for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Cycle DataMapper ORM
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/
declare(strict_types=1);
namespace Cycle\ORM\Relation\Pivoted;
use Doctrine\Common\Collections\ArrayCollection;
* Collection with associated relation context. Attention, pivot context is lost when collection is partitioned or
* filtered.
final class PivotedCollection extends ArrayCollection implements PivotedCollectionInterface
{
/** @var \SplObjectStorage */
protected $pivotContext;
* @param array $elements
* @param \SplObjectStorage|null $pivotData
public function __construct(array $elements = [], \SplObjectStorage $pivotData = null)
parent::__construct($elements);
$this->pivotContext = $pivotData ?? new \SplObjectStorage();
}
* @inheritdoc
public function hasPivot($element): bool
return $this->pivotContext->offsetExists($element);
public function getPivot($element)
return $this->pivotContext[$element] ?? null;
public function setPivot($element, $pivot): void
$this->pivotContext[$element] = $pivot;
public function getPivotContext(): \SplObjectStorage
return $this->pivotContext;
* @return PivotedCollection
protected function createFrom(array $elements)
$new = parent::createFrom($elements);
$new->pivotContext = $this->pivotContext;
return $new;