Пример #1
0
 private function createQuery(Criteria $criteria, $sagaId)
 {
     $comparisons = $criteria->getComparisons();
     $wheres = array();
     foreach ($comparisons as $key => $value) {
         $wheres['values.' . $key] = $value;
     }
     $queryBuilder = $this->collection->createQueryBuilder()->addAnd($wheres)->addAnd(array('removed' => false, 'sagaId' => $sagaId));
     return $queryBuilder->getQuery();
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function findOneBy(Criteria $criteria, $sagaId)
 {
     if (!isset($this->states[$sagaId])) {
         return null;
     }
     $states = $this->states[$sagaId];
     foreach ($criteria->getComparisons() as $key => $value) {
         $states = array_filter($states, function ($elem) use($key, $value) {
             $stateValue = $elem->get($key);
             return is_array($stateValue) ? in_array($value, $stateValue) : $value === $stateValue;
         });
     }
     $amount = count($states);
     if (1 === $amount) {
         return current($states);
     }
     if ($amount > 1) {
         throw new RepositoryException('Multiple saga state instances found.');
     }
     return null;
 }
Пример #3
0
 /**
  * @test
  */
 public function it_exposes_the_comparisons()
 {
     $data = array('appId' => 42, 'companyId' => 21);
     $criteria = new Criteria($data);
     $this->assertEquals($data, $criteria->getComparisons());
 }