*/ protected function getCollectionByProperty($type, $property) { $directory = $this->getRelatedDirectory($type); $collection = $directory->getCollection(); $list = $this->getNestedProperty($property) ?: []; /** @var FlexCollectionInterface $collection */ $collection = $collection->filter(static function ($object) use ($list) { return in_array($object->getKey(), $list, true); }); return $collection; } /** * @param string $type * @return FlexDirectory * @throws RuntimeException */ protected function getRelatedDirectory($type): FlexDirectory { $directory = $this->getFlexContainer()->getDirectory($type); if (!$directory) { throw new RuntimeException(ucfirst($type). ' directory does not exist!'); } return $directory; } }