// Collections can be used as arrays
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10971 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
1 parent
6be1ed9428
commit
6d792ee52b
1 file changed
+37
-1
+37
-1
@@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
class CollectionCore implements Iterator, Countable
|
class CollectionCore implements Iterator, ArrayAccess, Countable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string Object class name
|
* @var string Object class name
|
||||||
@@ -202,4 +202,40 @@ class CollectionCore implements Iterator, Countable
|
|||||||
$this->getAll();
|
$this->getAll();
|
||||||
return count($this->results);
|
return count($this->results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a result exist
|
||||||
|
*
|
||||||
|
* @param $offset
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function offsetExists($offset)
|
||||||
|
{
|
||||||
|
$this->getAll();
|
||||||
|
return isset($this->results[$offset]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a result by offset
|
||||||
|
*
|
||||||
|
* @param $offset
|
||||||
|
* @return ObjectModel
|
||||||
|
*/
|
||||||
|
public function offsetGet($offset)
|
||||||
|
{
|
||||||
|
$this->getAll();
|
||||||
|
if (!isset($this->results[$offset]))
|
||||||
|
throw new PrestashopException('Unknown offset '.$offset.' for collection '.$this->classname);
|
||||||
|
return $this->results[$offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetSet($offset, $value)
|
||||||
|
{
|
||||||
|
throw new PrestashopException('It is forbidden to override a result in a collection');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetUnset($offset)
|
||||||
|
{
|
||||||
|
throw new PrestashopException('It is forbidden to unset a result in a collection');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user