b2pweb /
bdf-form
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bdf\Form\Util; |
||
| 4 | |||
| 5 | use Bdf\Form\Child\ChildInterface; |
||
| 6 | use Bdf\Form\ElementInterface; |
||
| 7 | use WeakReference; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Implements get and set container methods for an element |
||
| 11 | */ |
||
| 12 | trait ContainerTrait |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var WeakReference<ChildInterface>|null |
||
| 16 | */ |
||
| 17 | private $container; |
||
| 18 | |||
| 19 | |||
| 20 | /** |
||
| 21 | * @see ElementInterface::container() |
||
| 22 | */ |
||
| 23 | 351 | final public function container(): ?ChildInterface |
|
| 24 | { |
||
| 25 | 351 | return $this->container ? $this->container->get() : null; |
|
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | * |
||
| 31 | * @return static |
||
| 32 | * @see ElementInterface::setContainer() |
||
| 33 | */ |
||
| 34 | 335 | final public function setContainer(ChildInterface $container): ElementInterface |
|
| 35 | { |
||
| 36 | 335 | $element = clone $this; |
|
| 37 | 335 | $element->container = WeakReference::create($container); |
|
| 38 | |||
| 39 | 335 | return $element; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 40 | } |
||
| 41 | } |
||
| 42 |