Ejemplo n.º 1
0
 /**
  * @param string            $type
  * @param string            $name
  * @param Entity\Reflection $entityReflection
  * @param bool              $readonly
  * @param string            $options
  */
 public function __construct($type, $name, Entity\Reflection $entityReflection, $readonly = false, $options = null)
 {
     $this->entityReflection = $entityReflection;
     $this->name = $name;
     $this->options = Annotation::parseOptions($options);
     $this->readonly = (bool) $readonly;
     $this->_initType($type);
     $this->_initComputed();
     $this->_initMapping();
     $this->_initEnumeration();
     $this->_initAssociation();
 }
Ejemplo n.º 2
0
 /**
  * Parse properties from annotations
  *
  * @param string $docComment
  *
  * @throws Exception\EntityException
  */
 private function _parseProperties($docComment)
 {
     $properties = [];
     foreach (Reflection\Annotation::parseProperties($docComment) as $definition) {
         try {
             $property = new Reflection\Property($definition[2], $definition[3], $this, !$definition[1], $definition[4]);
         } catch (Exception\PropertyException $e) {
             throw new Exception\EntityException($e->getMessage(), $this->className, $definition[0]);
         }
         // Prevent duplications
         if (isset($properties[$property->getName()])) {
             throw new Exception\EntityException("Duplicate property with name '" . $property->getName() . "'!", $this->className, $definition[0]);
         }
         if (in_array($property->getName(), $this->publicProperties)) {
             throw new Exception\EntityException("Property '" . $property->getName() . "' already defined as public property!", $this->className, $definition[0]);
         }
         // Primary property
         if ($property->hasOption(Reflection\Property::OPTION_PRIMARY)) {
             if ($this->hasPrimary()) {
                 throw new Exception\EntityException("Primary already defined!", $this->className, $definition[0]);
             }
             $this->primaryName = $property->getName();
         }
         if ($property->hasOption(Reflection\Property::OPTION_ASSOC) && $this->primaryName === null) {
             throw new Exception\EntityException("You must define primary property before the association!", $this->className, $definition[0]);
         }
         $this->properties[$property->getName()] = $property;
     }
 }