|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xoops\Core; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* XoopsArray - \ArrayObject with standard access to attributes |
|
16
|
|
|
* |
|
17
|
|
|
* @category Xoops\Core |
|
18
|
|
|
* @package XoopsArray |
|
19
|
|
|
* @author Richard Griffith <[email protected]> |
|
20
|
|
|
* @copyright 2015-2016 XOOPS Project (http://xoops.org) |
|
21
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
22
|
|
|
* @link http://xoops.org |
|
23
|
|
|
*/ |
|
24
|
|
|
class XoopsArray extends \ArrayObject implements AttributeInterface |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Retrieve an attribute |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $name Name of the attribute |
|
31
|
|
|
* @param mixed $default A default value returned if the requested attribute is not set. |
|
32
|
|
|
* |
|
33
|
|
|
* @return mixed The value of the attribute, or null if not set. |
|
34
|
|
|
*/ |
|
35
|
42 |
|
public function get($name, $default = null) |
|
36
|
|
|
{ |
|
37
|
42 |
|
if ($this->offsetExists($name)) { |
|
38
|
34 |
|
return $this->offsetGet($name); |
|
39
|
|
|
} else { |
|
40
|
8 |
|
return $default; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Set an item attribute |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $name Name of the attribute |
|
48
|
|
|
* @param mixed $value Value for the attribute |
|
49
|
|
|
* |
|
50
|
|
|
* @return $this |
|
51
|
|
|
*/ |
|
52
|
13 |
|
public function set($name, $value) |
|
53
|
|
|
{ |
|
54
|
13 |
|
$this->offsetSet($name, $value); |
|
55
|
13 |
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* has - test if an attribute with a given name is set |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $name Name of the attribute |
|
62
|
|
|
* |
|
63
|
|
|
* @return boolean true if named attribute is set |
|
64
|
|
|
*/ |
|
65
|
4 |
|
public function has($name) |
|
66
|
|
|
{ |
|
67
|
4 |
|
return $this->offsetExists($name); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Remove an attribute. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $name An attribute name. |
|
74
|
|
|
* |
|
75
|
|
|
* @return mixed An attribute value, if the named attribute existed and |
|
76
|
|
|
* has been removed, otherwise NULL. |
|
77
|
|
|
*/ |
|
78
|
5 |
View Code Duplication |
public function remove($name) |
|
79
|
|
|
{ |
|
80
|
5 |
|
$value = null; |
|
81
|
5 |
|
if ($this->offsetExists($name)) { |
|
82
|
3 |
|
$value = $this->offsetGet($name); |
|
83
|
3 |
|
$this->offsetUnset($name); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
5 |
|
return $value; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Remove all attributes. |
|
91
|
|
|
* |
|
92
|
|
|
* @return array old values |
|
93
|
|
|
*/ |
|
94
|
3 |
|
public function clear() |
|
95
|
|
|
{ |
|
96
|
3 |
|
return $this->exchangeArray(array()); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|