Пример #1
0
 /**
  * @param $entity
  * @return mixed
  * @throws RuntimeException
  */
 public function getIdentity($entity)
 {
     $identity = $this->propertyAccessor->getValue($entity, $this->identity->getPropertyName());
     if (empty($identity) && $identity !== 0) {
         throw new RuntimeException("Can't get identity from not identified entity.");
     }
     return $identity;
 }
Пример #2
0
 /**
  * @param $className
  * @param Identity $idDefinition
  * @param array $observedProperties
  * @throws InvalidArgumentException
  * @throws NotExistingPropertyException
  */
 private function validatePropertyPaths($className, Identity $idDefinition, array $observedProperties)
 {
     $reflection = new \ReflectionClass($className);
     foreach ($observedProperties as $property) {
         $propertyName = $property->getName();
         if ($idDefinition->isEqual($propertyName)) {
             throw new InvalidArgumentException("Id definition property path can't be between observer properties.");
         }
         if (!$reflection->hasProperty($propertyName)) {
             throw new NotExistingPropertyException(sprintf("Property \"%s\" does not exists in \"%s\" class.", $propertyName, $className));
         }
     }
 }