/** * @param Definition $definition * @param Property $property * @throws InvalidArgumentException */ private function validateAssociation(Definition $definition, Property $property) { if ($property->isAssociated()) { $targetClass = (string) $property->getAssociation()->getTargetClassName(); if (!array_key_exists($targetClass, $this->entityDefinitions)) { throw new InvalidArgumentException(sprintf("Entity class \"%s\" used in association of \"%s\" entity does not have definition.", $targetClass, (string) $definition->getClassName())); } } }
/** * @param Property $property * @param $firstObject * @param $secondObject * @return bool * @throws InvalidArgumentException */ public function hasDifferentValue(Property $property, $firstObject, $secondObject) { $this->validaObjects($firstObject, $secondObject); $firstValue = $this->propertyAccessor->getValue($firstObject, $property->getName()); $secondValue = $this->propertyAccessor->getValue($secondObject, $property->getName()); $comparator = $this->comparatorFactory->getComparatorFor($firstValue, $secondValue); try { $comparator->assertEquals($firstValue, $secondValue); return false; } catch (ComparisonFailure $exception) { return true; } }
/** * @param $propertyName * @return bool */ public function isFor($propertyName) { return $this->property->getName() === $propertyName; }
/** * @param Property $property * @param $newElement * @throws RuntimeException */ private function validateAssociatedEntity(Property $property, $newElement) { if (!is_object($newElement) || !$property->getAssociation()->getTargetClassName()->isClassOf($newElement)) { throw new RuntimeException(sprintf("Property \"%s\" expects instanceof \"%s\" as a value.", $property->getName(), (string) $property->getAssociation()->getTargetClassName())); } }