1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
<?php
namespace Commercetools\Core\Model\CustomObject;
use Commercetools\Core\Model\Common\Collection;
class CustomObjectCollection extends Collection
{
const KEY = 'key';
const CONTAINER = 'container';
protected $type = CustomObject::class;
protected function indexRow($offset, $row)
{
if ($row instanceof CustomObject) {
$key = $row->getKey();
$container = $row->getContainer();
} else {
$key = $row[static::KEY];
$container = $row[static::CONTAINER];
}
$this->addToIndex(static::KEY, $offset, $key);
$this->addToIndex(static::CONTAINER . '-' . static::KEY, $offset, $container . '-' . $key);
}
public function getByKey($key)
{
return $this->getBy(static::KEY, $key);
}
public function getByContainerKey($container, $key)
{
return $this->getBy(static::CONTAINER . '-' . static::KEY, $container . '-' . $key);
}
}