-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_map.php
More file actions
37 lines (31 loc) · 937 Bytes
/
_map.php
File metadata and controls
37 lines (31 loc) · 937 Bytes
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
<?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\Main;
// _map
// trait that provides a method to recursively change the entries (map) by providing a callback
trait _map
{
// map
// permet d'utiliser une closure pour changer les valeurs de l'objet
// la nouvelle valeur est passé dans la méthode set
// la clé est envoyé en deuxième argument
final public function map(\Closure $closure):Main\Map
{
$this->checkAllowed('map');
$return = $this->onPrepareThis('map');
foreach ($this->arr() as $key => $value)
{
$new = $closure($value,$key);
if($new !== $value)
$return->set($key,$new);
}
return $return;
}
}
?>