Пример #1
0
 /**
  * @param Criteria $criteria
  * @param Paginator $paginator
  * @param Sorter $sorter
  * @return Configuration
  */
 public static function factory(Criteria $criteria = NULL, Paginator $paginator = NULL, Sorter $sorter = NULL)
 {
     $inst = new Configuration();
     if ($criteria) {
         $inst->setCriteria($criteria);
     }
     if ($sorter) {
         $inst->setSorter($sorter);
     }
     if ($paginator) {
         $inst->setPaginator($paginator);
     }
     return $inst;
 }
Пример #2
0
 /**
  * @param Configuration $configuration
  * @return Post
  */
 public function fetch(Configuration $configuration)
 {
     $criteria = $configuration->getCriteria();
     $collection = $this->repository->getAll();
     if ($criteria && $criteria->hasCriteria()) {
         $posts = $collection->filter(function ($post) use($criteria) {
             if ($id = $criteria->getCriterion('id')) {
                 return $id == $post->id;
             }
             if ($hash = $criteria->getCriterion('hash')) {
                 return $hash == $post->hash;
             }
         });
     } else {
         $posts = $collection->getAll();
     }
     if (!$posts || count($posts) <= 0) {
         return NULL;
     }
     return array_shift($posts);
 }