added initial support for service definition
This commit is contained in:
52
Util/Collection.php
Normal file
52
Util/Collection.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Bundle\WebServiceBundle\Util;
|
||||
|
||||
class Collection implements \IteratorAggregate, \Countable
|
||||
{
|
||||
private $elements = array();
|
||||
private $keyPropertyGetter;
|
||||
|
||||
public function __construct($keyPropertyGetter)
|
||||
{
|
||||
$this->keyPropertyGetter = $keyPropertyGetter;
|
||||
}
|
||||
|
||||
public function add($element)
|
||||
{
|
||||
$this->elements[call_user_func(array($element, $this->keyPropertyGetter))] = $element;
|
||||
}
|
||||
|
||||
public function addAll($elements)
|
||||
{
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
$this->add($element);
|
||||
}
|
||||
}
|
||||
|
||||
public function has($key)
|
||||
{
|
||||
return isset($this->elements[$key]);
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
return $this->has($key) ? $this->elements[$key] : null;
|
||||
}
|
||||
|
||||
public function clear()
|
||||
{
|
||||
$this->elements = array();
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->elements);
|
||||
}
|
||||
|
||||
public function getIterator ()
|
||||
{
|
||||
return new \ArrayIterator($this->elements);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user