Esempio n. 1
0
 /**
  * @param  string $class
  * @return void
  */
 private static function loadAnnotationProperties($class)
 {
     if (!isset(self::$annProps[$class])) {
         self::$annProps[$class] = [];
         $ref = $class::getReflection();
         foreach ($ref->getAnnotations() as $ann => $values) {
             if ($ann === 'property' || $ann === 'property-read') {
                 foreach ($values as $tmp) {
                     $matches = NStrings::match($tmp, '#^[ \\t]*(?P<type>\\\\?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?:\\\\[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*(?:\\|\\\\?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?:\\\\[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*)?)[ \\t]+(?P<property>\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)(?:[ \\t]+->[ \\t]+(?P<column>[a-zA-Z0-9_-]+))?[ \\t]*(?P<description>.*)\\z#');
                     if ($matches === NULL) {
                         throw new YetORM\Exception\InvalidStateException('Invalid property definition - "@' . $ann . ' ' . $tmp . '" does not match "@property[-read] <type> $<property> [-> <column>][ <description>]" pattern.');
                     }
                     $nullable = FALSE;
                     $type = $matches['type'];
                     $types = explode('|', $type, 2);
                     if (count($types) === 2) {
                         if (strcasecmp($types[0], 'NULL') === 0) {
                             $nullable = TRUE;
                             $type = $types[1];
                         }
                         if (strcasecmp($types[1], 'NULL') === 0) {
                             if ($nullable) {
                                 throw new YetORM\Exception\InvalidStateException('Invalid property type (double NULL).');
                             }
                             $nullable = TRUE;
                             $type = $types[0];
                         }
                         if (!$nullable) {
                             throw new YetORM\Exception\InvalidStateException('Invalid property type (multiple non-NULL types detected).');
                         }
                     }
                     if ($type === 'bool') {
                         $type = 'boolean';
                     } elseif ($type === 'int') {
                         $type = 'integer';
                     }
                     if (!EntityProperty::isNativeType($type)) {
                         $type = AnnotationsParser::expandClassName($type, $ref);
                     }
                     $readonly = $ann === 'property-read';
                     $name = substr($matches['property'], 1);
                     $column = strlen($matches['column']) ? $matches['column'] : $name;
                     $description = strlen($matches['description']) ? $matches['description'] : NULL;
                     self::$annProps[$class][$name] = new AnnotationProperty($ref, $name, $readonly, $type, $column, $nullable, $description);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * @param  EntityType $reflection
  * @param  string $name
  * @param  bool $readonly
  * @param  string $type
  * @param  string $column
  * @param  bool $nullable
  * @param  string $description
  */
 public function __construct($reflection, $name, $readonly, $type, $column, $nullable, $description = NULL)
 {
     parent::__construct($reflection, $name, $readonly, $type, $description);
     $this->column = (string) $column;
     $this->nullable = (bool) $nullable;
 }