Esempio n. 1
0
 /**
  * {@inheritdo}
  */
 public function visit(SpecificationInterface $specification) : MapInterface
 {
     switch (true) {
         case $specification instanceof ComparatorInterface:
             if ($specification->sign() !== '=') {
                 throw new SpecificationNotApplicableAsPropertyMatchException();
             }
             return $this->buildMapping($specification);
         case $specification instanceof CompositeInterface:
             if ((string) $specification->operator() !== Operator::AND) {
                 throw new SpecificationNotApplicableAsPropertyMatchException();
             }
             return $this->merge($this->visit($specification->left()), $this->visit($specification->right()));
     }
     throw new SpecificationNotApplicableAsPropertyMatchException();
 }
 public function translate(SpecificationInterface $specification) : string
 {
     switch (true) {
         case $specification instanceof ComparatorInterface:
             if ($specification->sign() !== '==') {
                 throw new OnlyEqualityCanBeTranslatedException();
             }
             return sprintf('%s=%s', $specification->property(), $specification->value());
         case $specification instanceof CompositeInterface:
             if ((string) $specification->operator() === Operator::OR) {
                 throw new OnlyAndCompositionCanBeTranslatedException();
             }
             return sprintf('%s&%s', $this->translate($specification->left()), $this->translate($specification->right()));
         default:
             throw new SpecificationCantBeTranslatedException();
     }
 }