| 1 |
Derived Collections |
| 2 |
=================== |
| 3 |
|
| 4 |
You can create custom collection classes by extending the |
| 5 |
``Doctrine\Common\Collections\ArrayCollection`` class. If the |
| 6 |
``__construct`` semantics are different from the default ``ArrayCollection`` |
| 7 |
you can override the ``createFrom`` method: |
| 8 |
|
| 9 |
.. code-block:: php |
| 10 |
final class DerivedArrayCollection extends ArrayCollection |
| 11 |
{ |
| 12 |
/** @var \stdClass */ |
| 13 |
private $foo; |
| 14 |
|
| 15 |
public function __construct(\stdClass $foo, array $elements = []) |
| 16 |
{ |
| 17 |
$this->foo = $foo; |
| 18 |
|
| 19 |
parent::__construct($elements); |
| 20 |
} |
| 21 |
|
| 22 |
protected function createFrom(array $elements) : self |
| 23 |
{ |
| 24 |
return new static($this->foo, $elements); |
| 25 |
} |
| 26 |
} |