Source of file DocumentFetchCreatorRegistry.php
Size: 1,802 Bytes - Last Modified: 2021-12-23T10:34:25+00:00
/var/www/docs.ssmods.com/process/src/src/Service/DocumentFetchCreatorRegistry.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | <?php namespace SilverStripe\SearchService\Service; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\InjectorNotFoundException; use SilverStripe\SearchService\Interfaces\DocumentFetchCreatorInterface; use SilverStripe\SearchService\Interfaces\DocumentFetcherInterface; class DocumentFetchCreatorRegistry { use Injectable; /** * @var DocumentFetchCreatorInterface[] */ private $fetchCreators = []; /** * DocumentFetchCreatorRegistry constructor. * @param array $fetchCreators */ public function __construct(...$fetchCreators) { foreach ($fetchCreators as $creator) { $this->addFetchCreator($creator); } } /** * @param DocumentFetchCreatorInterface $creator * @return $this */ public function addFetchCreator(DocumentFetchCreatorInterface $creator): self { $this->fetchCreators[] = $creator; return $this; } /** * @param DocumentFetchCreatorInterface $creator * @return $this */ public function removeFetchCreator(DocumentFetchCreatorInterface $creator): self { $class = get_class($creator); $this->fetchCreators = array_filter($this->fetchCreators, function ($creator) use ($class) { return !$creator instanceof $class; }); return $this; } /** * @param string $class * @return DocumentFetchCreatorInterface|null */ public function getFetcher(string $class): ?DocumentFetcherInterface { foreach ($this->fetchCreators as $creator) { if ($creator->appliesTo($class)) { return $creator->createFetcher($class); } } return null; } } |