Example #1
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);
 }