-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_prepend.php
More file actions
56 lines (45 loc) · 1.36 KB
/
_prepend.php
File metadata and controls
56 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/main/blob/master/LICENSE
*/
namespace Quid\Main\Map;
use Quid\Base;
use Quid\Main;
// _prepend
// trait that replaces methods to make the collection prepend per default (add at the beginning)
trait _prepend
{
// set
// ajoute ou change une clé valeur dans la map, accepte une clé null
// si la clé n'existe pas elle est prepend
final public function set($key,$value):Main\Map
{
$this->checkAllowed('set');
$return = $this->onPrepareThis('set');
$key = $this->onPrepareKey($key);
$value = $this->onPrepareValueSet($value);
if($key === null)
$return->unshift($value);
elseif($return->exists($key) && $return->checkBefore(false,$value))
Base\Arr::setRef($key,$value,$return->arr());
elseif(Base\Arr::isKey($key))
$return->prepend([$key=>$value]);
return $return->checkAfter();
}
// add
// raccourci pour unshift
final public function add(...$values):Main\Map
{
return $this->unshift(...$values);
}
// pend
// raccourci pour prepend
final public function pend(...$values):Main\Map
{
return $this->prepend(...$values);
}
}
?>