Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
map.php
1<?php
2
4
6
10abstract class Map extends Collection
11{
20 public function add($item, $key = null): self
21 {
22 if ($key === null)
23 {
24 throw new ArgumentException('you must transfer the key');
25 }
26
27 $this->collection[$key] = $item;
28
29 if ($this->generator)
30 {
31 $this->generator->send($item);
32 }
33
34 return $this;
35 }
36
42 public function addItems(array $items): Collection
43 {
44 // $this->collection = array_replace($this->collection, $items);
45
46 $this->collection = $this->collection + $items;
47 return $this;
48 }
49
55 public function getItem($key)
56 {
57 return $this->collection[$key] ?? null;
58 }
59
64 public function has($key): bool
65 {
66 return isset($this->collection[$key]);
67 }
68
75 public function updateItem($item, $key): Map
76 {
77 $this->collection[$key] = $item;
78
79 return $this;
80 }
81
86 public function getItemsByKeys(array $keys): Map
87 {
88 return new static(array_intersect_key($this->collection, array_flip($keys)));
89 }
90}
getItemsByKeys(array $keys)
Definition map.php:86
updateItem($item, $key)
Definition map.php:75
add($item, $key=null)
Definition map.php:20
addItems(array $items)
Definition map.php:42