- removing method that were implemented in the collection class

This commit is contained in:
Reza
2016-03-18 17:25:08 +03:30
parent 6528c266ce
commit 23c4c936b9

View File

@ -11,8 +11,6 @@
namespace Salarmehr; namespace Salarmehr;
use ArrayAccess; use ArrayAccess;
use ArrayIterator;
use CachingIterator;
use Countable; use Countable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use IteratorAggregate; use IteratorAggregate;
@ -20,18 +18,10 @@ use JsonSerializable;
class Ary extends Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable class Ary extends Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
{ {
/**
* The items contained in the collection.
*
* @var array
*/
protected $items = [];
/** /**
* Create a new collection. * Create a new collection.
* *
* @param mixed $items * @param mixed $items
*/ */
public function __construct() public function __construct()
@ -46,36 +36,6 @@ class Ary extends Collection implements ArrayAccess, Countable, IteratorAggregat
$this->items = $items; $this->items = $items;
} }
/**
* Results array of items from Collection or Arrayable.
*
* @param mixed $items
* @return array
*/
protected function getArrayableItems($items)
{
if ($items instanceof self) {
return $items->all();
}
if (method_exists($items, 'toArray')) {
return $items->toArray();
}
if ($items instanceof \JsonSerializable) {
return json_decode(json_encode($items), true);
}
return (array)$items;
}
/**
* Get all of the items in the collection.
*
* @return array
*/
public function all()
{
return $this->items;
}
public function &__get($item) public function &__get($item)
{ {
return $this->get($item); return $this->get($item);
@ -110,17 +70,6 @@ class Ary extends Collection implements ArrayAccess, Countable, IteratorAggregat
return $array; return $array;
} }
/**
* Determine if an item exists at an offset.
*
* @param mixed $key
* @return bool
*/
public function offsetExists($key)
{
return array_key_exists($key, $this->items);
}
/** /**
* Set the item at a given offset. * Set the item at a given offset.
* *
@ -167,117 +116,11 @@ class Ary extends Collection implements ArrayAccess, Countable, IteratorAggregat
return $this->get($key); return $this->get($key);
} }
/**
* Convert the object into something JSON serializable.
*
* @return array
*/
public function jsonSerialize()
{
return $this->all();
}
/**
* Get the collection of items as a plain array.
*
* @return array
*/
public function toArray()
{
return $this->all();
}
/**
* Merge the collection with the given items.
*
* @param mixed $items
* @return static
*/
public function merge($items)
{
return new static(array_merge($this->items, $this->getArrayableItems($items)));
}
/**
* Get a CachingIterator instance.
*
* @param int $flags
* @return \CachingIterator
*/
public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING)
{
return new \CachingIterator($this->getIterator(), $flags);
}
/**
* Get an iterator for the items.
*
* @return \ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->items);
}
/**
* Count the number of items in the collection.
*
* @return int
*/
public function count()
{
return count($this->items);
}
/**
* Convert the collection to its string representation.
*
* @return string
*/
public function __toString()
{
return $this->toJson();
}
/**
* Get the collection of items as JSON.
*
* @param int $options
* @return string
*/
public function toJson($options = 0)
{
return json_encode($this->all(), $options);
}
/**
* Get a subset of the items from the given array.
*
* @param array|string $keys
* @return array
*/
public function only($keys)
{
return array_intersect_key($this->all(), array_flip((array)$keys));
}
public function __isset($name) public function __isset($name)
{ {
return $this->has($name); return $this->has($name);
} }
/**
* Determine if an item exists in the collection by key.
*
* @param mixed $key
* @return bool
*/
public function has($key)
{
return $this->offsetExists($key);
}
/** /**
* Get the collection of items as a plain object. * Get the collection of items as a plain object.
* *
@ -289,17 +132,10 @@ class Ary extends Collection implements ArrayAccess, Countable, IteratorAggregat
} }
/** /**
* Search the ary for a given value and return the corresponding key if successful. * Return a subset of current ary as a new ary
* * @param $item
* @param mixed $value * @return Ary
* @param bool $strict
* @return mixed
*/ */
public function search($value, $strict = false)
{
return array_search($value, $this->items, $strict);
}
public function ary($item) public function ary($item)
{ {
return new ary($this->get($item)); return new ary($this->get($item));
@ -309,15 +145,4 @@ class Ary extends Collection implements ArrayAccess, Countable, IteratorAggregat
{ {
$this->offsetUnset($key); $this->offsetUnset($key);
} }
/**
* Unset the item at a given offset.
*
* @param string $key
* @return void
*/
public function offsetUnset($key)
{
unset($this->items[$key]);
}
} }