Exemple #1
0
 /**
  * @param \Hynage\ORM\Entity $entity
  * @return \Hynage\ORM\EntityManager
  */
 private function addProxies(Entity $entity)
 {
     $reflectionClass = new ReflectionClass($entity::getClassNameOfEntityDefinition());
     foreach ($reflectionClass->getProperties(\ReflectionMethod::IS_PROTECTED) as $property) {
         $definition = $property->getAnnotation('HynageRelation');
         if (!is_array($definition)) {
             continue;
         }
         $proxy = new Proxy($this, $entity, $definition['class'], $definition['local'], $definition['foreign'], $definition['type']);
         $entity->setProxy($property->name, $proxy);
     }
     return $this;
 }
Exemple #2
0
 /**
  * @return array
  */
 public static function getFieldDefinitions()
 {
     $fields = array();
     $reflectionClass = new ReflectionClass(static::getClassNameOfEntityDefinition());
     foreach ($reflectionClass->getProperties(\ReflectionMethod::IS_PROTECTED) as $property) {
         $definition = $property->getAnnotation('HynageColumn');
         if (!is_array($definition)) {
             continue;
         }
         $propertyName = $property->name;
         $name = isset($definition['name']) ? $definition['name'] : ltrim($property->name, '_');
         $type = isset($definition['type']) ? strtoupper($definition['type']) : 'VARCHAR';
         $length = isset($definition['length']) ? (int) $definition['length'] : null;
         $attributes = array();
         $attributes['unsigned'] = $property->hasAnnotation('HynageColumnUnsigned');
         $attributes['notNull'] = $property->hasAnnotation('HynageColumnNotNull');
         $attributes['autoIncrement'] = $property->hasAnnotation('HynageColumnAutoIncrement');
         $attributes['primary'] = $property->hasAnnotation('HynageColumnPrimary');
         if ($property->hasAnnotation('HynageColumnDefault')) {
             $attributes['default'] = $property->getAnnotation('HynageColumnDefault');
         }
         $fields[] = new Field($name, $propertyName, $type, $length, $attributes);
     }
     return $fields;
 }