Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
item.php
1<?
9
11
17abstract class Item
18{
20 protected $data = [
21 'source' => null
22 ];
23
29 public function __construct(array $data)
30 {
31 $this->setData($data);
32 }
33
39 public function getData()
40 {
41 return $this->data;
42 }
43
50 public function setData(array $data)
51 {
52 foreach ($data as $key => $value)
53 {
54 $this->set($key, $value);
55 }
56
57 return $this;
58 }
59
66 public function get($key)
67 {
68 if (!array_key_exists($key, $this->data))
69 {
70 throw new ArgumentException("Unknown key `$key`.");
71 }
72
73 return $this->data[$key];
74 }
75
84 public function set($key, $value)
85 {
86 if (!array_key_exists($key, $this->data))
87 {
88 throw new ArgumentException("Unknown key `$key`.");
89 }
90
91 $this->data[$key] = $value;
92 return $this;
93 }
94
103 public function __call($name, $arguments)
104 {
105 $method = mb_substr($name, 0, 3);
106 if (in_array($method, ['set', 'get']))
107 {
108 $key = lcfirst(mb_substr($name, 3));
109 return call_user_func_array(array($this, $method), array_merge([$key], $arguments));
110 }
111
112 throw new ArgumentException("Method `$name` not found.");
113 }
114}
115
__call($name, $arguments)
Definition item.php:103