/** * Добавляет вложенную спецификацию * * @param SpecificationInterface $specification * @return void */ private function addSpecification(SpecificationInterface $specification) { if ($specification instanceof AggregateSpecification) { $this->addSpecifications($specification->getSpecifications()); return; } $this->specifications[] = $specification; }
/** * {@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(); }
/** * {@inheritdoc} */ public function validate(SpecificationInterface $specification, EntityInterface $meta) : bool { if (!$meta instanceof Aggregate) { throw new InvalidArgumentException(); } switch (true) { case $specification instanceof ComparatorInterface: return $this->isValidProperty($specification->property(), $meta); case $specification instanceof CompositeInterface: if (!$this->validate($specification->left(), $meta)) { return false; } return $this->validate($specification->right(), $meta); case $specification instanceof NotInterface: return $this->validate($specification->specification(), $meta); } return false; }
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(); } }
private function extract(SpecificationInterface $specification) : array { $data = []; switch (true) { case $specification instanceof ComparatorInterface: $data[$specification->property()] = $specification->value(); break; case $specification instanceof CompositeInterface: if ((string) $specification->operator() === Operator::OR) { throw new SpecificationNotUsableAsQueryException(); } $data = array_merge($data, $this->extract($specification->left()), $this->extract($specification->right())); break; default: throw new SpecificationNotUsableAsQueryException(); } return $data; }
/** * Check if specification satisfied by given value * @param mixed $value * @return bool */ public function isSatisfiedBy($value) { return $this->left->isSatisfiedBy($value) && $this->right->isSatisfiedBy($value); }
/** * Determines whether or not the * passed in value is satisfied by * the specification or not * @param $value * @return bool */ public function isSatisfiedBy($value) { return $this->specOne->isSatisfiedBy($value) && $this->specTwo->isSatisfiedBy($value); }
/** * {@inheritDoc} */ public function isSatisfiedBy($value) { return !$this->wrapped->isSatisfiedBy($value); }
/** * Checks if the current transition satisfies the specifiation on the given context. * * @param ContextInterface $context * * @return bool */ public function isOpen(ContextInterface $context) { return $this->spec->isSatisfiedBy($context); }
/** * {@inheritDoc} */ public function isSatisfiedBy($value) { return $this->x->isSatisfiedBy($value) && $this->y->isSatisfiedBy($value); }
public function isSatisfiedBy(Item $item) : bool { return !$this->specification->isSatisfiedBy($item); }
/** * isSatisfied * * Return true if the composed specification returns false. * * @return boolean */ public function isSatisfied() { return false === $this->spec->isSatisfied(); }