- adding __set magic method.
This commit is contained in:
52
src/Ary.php
52
src/Ary.php
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Created Reza Salarmehr.
|
* Created by Reza Salarmehr.
|
||||||
*
|
*
|
||||||
* Some methods are from Laravel source code.
|
* Some methods are from Laravel source code.
|
||||||
*
|
*
|
||||||
@ -82,6 +82,11 @@ class Ary implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
|
|||||||
return $this->get($item);
|
return $this->get($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __set($name, $value)
|
||||||
|
{
|
||||||
|
$this->offsetSet($name, $value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an item from the collection by key.
|
* Get an item from the collection by key.
|
||||||
*
|
*
|
||||||
@ -109,6 +114,23 @@ class Ary implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
|
|||||||
return array_key_exists($key, $this->items);
|
return array_key_exists($key, $this->items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the item at a given offset.
|
||||||
|
*
|
||||||
|
* @param mixed $key
|
||||||
|
* @param mixed $value
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function offsetSet($key, $value)
|
||||||
|
{
|
||||||
|
if (is_null($key)) {
|
||||||
|
$this->items[] = $value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->items[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the object into something JSON serializable.
|
* Convert the object into something JSON serializable.
|
||||||
*
|
*
|
||||||
@ -182,23 +204,6 @@ class Ary implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
|
|||||||
return $this->get($key);
|
return $this->get($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the item at a given offset.
|
|
||||||
*
|
|
||||||
* @param mixed $key
|
|
||||||
* @param mixed $value
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function offsetSet($key, $value)
|
|
||||||
{
|
|
||||||
if (is_null($key)) {
|
|
||||||
$this->items[] = $value;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this->items[$key] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unset the item at a given offset.
|
* Unset the item at a given offset.
|
||||||
*
|
*
|
||||||
@ -267,4 +272,15 @@ class Ary implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
|
|||||||
{
|
{
|
||||||
return (object)$this->all();
|
return (object)$this->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * sets a nested ary.
|
||||||
|
// * @param $key
|
||||||
|
// * @param $items
|
||||||
|
// */
|
||||||
|
// public function setAry($key, $items)
|
||||||
|
// {
|
||||||
|
// $this->items[$key] = new self($items);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user