Beispiel #1
0
 /**
  * @param Fetchable $fetchable
  * @param Fetcher   $fetcher
  * @throws \Exception
  */
 public function __construct(Fetchable $fetchable, Fetcher $fetcher)
 {
     if ($fetcher->getNbByPage() <= 0) {
         throw new \Exception('Fetcher should have a limit of results per page');
     }
     if ($fetcher->hasSort()) {
         throw new \Exception('Sorted fetcher is not supported');
     }
     $this->fetchable = $fetchable;
     $this->fetcher = $fetcher;
     $this->fetcher->setPage(1);
     $this->fetcher->sortById(Fetcher::SORT_ASC);
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function getUniqueByFetcher(Fetcher $fetcher)
 {
     $fetcher->setPage(1);
     $fetcher->setNbByPage(2);
     $ids = $this->getIdsByFetcher($fetcher);
     if (empty($ids)) {
         return null;
     }
     if (count($ids) === 2) {
         throw new NotUniqueResultException();
     }
     return $this->manager->getById(reset($ids));
 }