22
33namespace SQLBuilder ;
44
5- use ArrayIterator ;
6- use ArrayAccess ;
7- use IteratorAggregate ;
5+ use ArrayObject ;
86
9- class ArgumentArray implements ArrayAccess, IteratorAggregate
7+ class ArgumentArray extends ArrayObject
108{
11- /**
12- * @var array
13- *
14- * {
15- * :name => 'John',
16- * :phone => 'Phone',
17- * }
18- */
19- protected $ args = array ();
20-
219 /**
2210 * @var Bind[]
2311 */
2412 protected $ bindings = array ();
2513
26- public function __construct (array $ args = array ())
27- {
28- $ this ->args = $ args ;
29- }
30-
31- public function getIterator ()
32- {
33- return new ArrayIterator ($ this ->args );
34- }
35-
3614 public function push (Bind $ bind )
3715 {
3816 $ this ->bindings [] = $ bind ;
39- $ this -> args [$ bind ->getMarker ()] = $ bind ->getValue ();
17+ $ this [$ bind ->getMarker ()] = $ bind ->getValue ();
4018 }
4119
4220 // Deprecated
4321 public function add ($ bind )
4422 {
4523 // trigger_error("Bind::add is deprecated, please use Bind::bind instead.", E_USER_DEPRECATED);
4624 $ this ->bindings [] = $ bind ;
47- $ this -> args [$ bind ->getMarker ()] = $ bind ->getValue ();
25+ $ this [$ bind ->getMarker ()] = $ bind ->getValue ();
4826 }
4927
5028 public function bind ($ bind )
5129 {
5230 $ this ->bindings [] = $ bind ;
53- $ this -> args [$ bind ->getMarker ()] = $ bind ->getValue ();
31+ $ this [$ bind ->getMarker ()] = $ bind ->getValue ();
5432 }
5533
5634 public function getBindingByIndex ($ idx )
@@ -63,29 +41,9 @@ public function getBindings()
6341 return $ this ->bindings ;
6442 }
6543
66- public function offsetSet ($ name , $ value )
67- {
68- $ this ->args [$ name ] = $ value ;
69- }
70-
71- public function offsetExists ($ name )
72- {
73- return isset ($ this ->args [ $ name ]);
74- }
75-
76- public function offsetGet ($ name )
77- {
78- return $ this ->args [ $ name ];
79- }
80-
81- public function offsetUnset ($ name )
82- {
83- unset($ this ->args [$ name ]);
84- }
85-
8644 public function getArgs ()
8745 {
88- return $ this ->args ;
46+ return $ this ->getArrayCopy () ;
8947 }
9048
9149 /**
@@ -99,13 +57,13 @@ public function toArray($removeBinds = false)
9957 {
10058 if ($ removeBinds ) {
10159 $ args = array ();
102- foreach ($ this -> args as $ key => $ val ) {
60+ foreach ($ this as $ key => $ val ) {
10361 $ args [$ key ] = $ val instanceof Bind ? $ val ->getValue () : $ val ;
10462 }
10563
10664 return $ args ;
10765 }
10866
109- return $ this ->args ;
67+ return $ this ->getArrayCopy () ;
11068 }
11169}
0 commit comments