1 | <?php |
||
9 | trait AccessMethodsTrait |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @param array $items |
||
14 | */ |
||
15 | public function setItems($items) |
||
16 | { |
||
17 | $this->items = $items; |
||
|
|||
18 | } |
||
19 | |||
20 | /** |
||
21 | * {@inheritDoc} |
||
22 | * @param \Nip\Records\AbstractModels\Record $element |
||
23 | */ |
||
24 | 2 | public function add($element, $key = null) |
|
25 | { |
||
26 | 2 | if ($key == null) { |
|
27 | 2 | $this->items[] = $element; |
|
28 | |||
29 | 2 | return; |
|
30 | } |
||
31 | $this->set($key, $element); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param string $id |
||
36 | * @param mixed $value |
||
37 | */ |
||
38 | 4 | public function set($id, $value) |
|
42 | |||
43 | |||
44 | /** |
||
45 | * Returns a parameter by name. |
||
46 | * |
||
47 | * @param string $key The key |
||
48 | * @param mixed $default The default value if the parameter key does not exist |
||
49 | * |
||
50 | * @return mixed |
||
51 | */ |
||
52 | 2 | public function get($key, $default = null) |
|
56 | |||
57 | /** |
||
58 | * @return boolean |
||
59 | * @param string $key |
||
60 | */ |
||
61 | public function has($key) |
||
65 | |||
66 | /** |
||
67 | * @param $key |
||
68 | * @return bool |
||
69 | * @deprecated Use ->has($key) instead |
||
70 | */ |
||
71 | public function exists($key) |
||
75 | |||
76 | |||
77 | /** |
||
78 | * Returns the parameters. |
||
79 | * |
||
80 | * @return array An array of parameters |
||
81 | */ |
||
82 | public function all() |
||
86 | |||
87 | /** |
||
88 | * Returns the parameter keys. |
||
89 | * |
||
90 | * @return array An array of parameter keys |
||
91 | */ |
||
92 | 1 | public function keys() |
|
93 | { |
||
94 | 1 | return array_keys($this->items); |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * Returns the parameter values. |
||
99 | * |
||
100 | * @return array An array of parameter values |
||
101 | */ |
||
102 | public function values() |
||
106 | |||
107 | |||
108 | /** |
||
109 | * @param string $key |
||
110 | * @return null |
||
111 | */ |
||
112 | 1 | public function unset($key) |
|
122 | |||
123 | /** |
||
124 | * Alias of unshift |
||
125 | * |
||
126 | * @param mixed $value |
||
127 | * @param mixed $key |
||
128 | * @return $this |
||
129 | */ |
||
130 | public function prepend($value, $key = null) |
||
134 | |||
135 | /** |
||
136 | * Push an item onto the beginning of the collection. |
||
137 | * |
||
138 | * @param $value |
||
139 | * @param null $key |
||
140 | * @return $this |
||
141 | */ |
||
142 | public function unshift($value, $key = null) |
||
152 | } |
||
153 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: