コード例 #1
0
ファイル: Annotation.php プロジェクト: nahakiole/cloudrexx
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata($meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::LOGGABLE)) {
         $config['loggable'] = true;
         if ($annot->logEntryClass) {
             if (!class_exists($annot->logEntryClass)) {
                 throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist.");
             }
             $config['logEntryClass'] = $annot->logEntryClass;
         }
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // versioned property
         if ($versioned = $this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
             $field = $property->getName();
             if ($meta->isCollectionValuedAssociation($field)) {
                 throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
             }
             // fields cannot be overrided and throws mapping exception
             $config['versioned'][] = $field;
         }
     }
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata($meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // class annotations
     if ($class !== null && ($annot = $this->reader->getClassAnnotation($class, self::SOFT_DELETEABLE))) {
         $config['softDeleteable'] = true;
         Validator::validateField($meta, $annot->fieldName);
         $config['fieldName'] = $annot->fieldName;
     }
     $this->validateFullMetadata($meta, $config);
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata($meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     if (!$class) {
         // based on recent doctrine 2.3.0-DEV maybe will be fixed in some way
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($meta->name);
     }
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::ENTITY_CLASS)) {
         if (!class_exists($annot->class)) {
             throw new InvalidMappingException("Translation class: {$annot->class} does not exist.");
         }
         $config['translationClass'] = $annot->class;
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // translatable property
         if ($translatable = $this->reader->getPropertyAnnotation($property, self::TRANSLATABLE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find translatable [{$field}] as mapped property in entity - {$meta->name}");
             }
             // fields cannot be overrided and throws mapping exception
             $config['fields'][] = $field;
             if (isset($translatable->fallback)) {
                 $config['fallback'][$field] = $translatable->fallback;
             }
         }
         // locale property
         if ($locale = $this->reader->getPropertyAnnotation($property, self::LOCALE)) {
             $field = $property->getName();
             if ($meta->hasField($field)) {
                 throw new InvalidMappingException("Locale field [{$field}] should not be mapped as column property in entity - {$meta->name}, since it makes no sence");
             }
             $config['locale'] = $field;
         } elseif ($language = $this->reader->getPropertyAnnotation($property, self::LANGUAGE)) {
             $field = $property->getName();
             if ($meta->hasField($field)) {
                 throw new InvalidMappingException("Language field [{$field}] should not be mapped as column property in entity - {$meta->name}, since it makes no sence");
             }
             $config['locale'] = $field;
         }
     }
     if (!$meta->isMappedSuperclass && $config) {
         if (is_array($meta->identifier) && count($meta->identifier) > 1) {
             throw new InvalidMappingException("Translatable does not support composite identifiers in class - {$meta->name}");
         }
     }
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata($meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     if (!$class) {
         // based on recent doctrine 2.3.0-DEV maybe will be fixed in some way
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($meta->name);
     }
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::LOGGABLE)) {
         $config['loggable'] = true;
         if ($annot->logEntryClass) {
             if (!class_exists($annot->logEntryClass)) {
                 throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist.");
             }
             $config['logEntryClass'] = $annot->logEntryClass;
         }
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // versioned property
         if ($versioned = $this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
             $field = $property->getName();
             if ($meta->isCollectionValuedAssociation($field)) {
                 throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
             }
             // fields cannot be overrided and throws mapping exception
             $config['versioned'][] = $field;
         }
     }
     if (!$meta->isMappedSuperclass && $config) {
         if (is_array($meta->identifier) && count($meta->identifier) > 1) {
             throw new InvalidMappingException("Loggable does not support composite identifiers in class - {$meta->name}");
         }
         if (isset($config['versioned']) && !isset($config['loggable'])) {
             throw new InvalidMappingException("Class must be annoted with Loggable annotation in order to track versioned fields in class - {$meta->name}");
         }
     }
 }
コード例 #5
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::ENTITY_CLASS)) {
         if (!class_exists($annot->class)) {
             throw new InvalidMappingException("Translation class: {$annot->class} does not exist.");
         }
         $config['translationClass'] = $annot->class;
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // translatable property
         if ($translatable = $this->reader->getPropertyAnnotation($property, self::TRANSLATABLE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find translatable [{$field}] as mapped property in entity - {$meta->name}");
             }
             // fields cannot be overrided and throws mapping exception
             $config['fields'][] = $field;
         }
         // locale property
         if ($locale = $this->reader->getPropertyAnnotation($property, self::LOCALE)) {
             $field = $property->getName();
             if ($meta->hasField($field)) {
                 throw new InvalidMappingException("Locale field [{$field}] should not be mapped as column property in entity - {$meta->name}, since it makes no sence");
             }
             $config['locale'] = $field;
         } elseif ($language = $this->reader->getPropertyAnnotation($property, self::LANGUAGE)) {
             $field = $property->getName();
             if ($meta->hasField($field)) {
                 throw new InvalidMappingException("Language field [{$field}] should not be mapped as column property in entity - {$meta->name}, since it makes no sence");
             }
             $config['locale'] = $field;
         }
     }
 }
コード例 #6
0
ファイル: Annotation.php プロジェクト: nacmartin/Historyable
    /**
     * {@inheritDoc}
     */
    public function readExtendedMetadata(ClassMetadata $meta, array &$config)
    {
        $class = $meta->getReflectionClass();
        // class annotations
        if ($annot = $this->reader->getClassAnnotation($class, self::HISTORYABLE)) {
            $config['historyable'] = true;

        }

        // property annotations
        foreach ($class->getProperties() as $property) {
            if ($meta->isMappedSuperclass && !$property->isPrivate() ||
                $meta->isInheritedField($property->name) ||
                isset($meta->associationMappings[$property->name]['inherited'])
            ) {
                continue;
            }
            if ($status = $this->reader->getPropertyAnnotation($property, self::STATUS)) {
                $field = $property->getName();
                if (!$meta->hasField($field)) {
                    throw new InvalidMappingException("Unable to find status [{$field}] as mapped property in entity - {$meta->name}");
                }
                if (!$this->isValidField($meta, $field)) {
                    throw new InvalidMappingException("Cannot make status on field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
                }
                if (isset($config['status_field'])) {
                    throw new InvalidMappingException("There cannot be more than one status field: [{$field}] and [{$config['status_field']}], in class - {$meta->name}.");
                }
                $config['status_field'] = $field;
            }
            if ($refVersion = $this->reader->getPropertyAnnotation($property, self::REFVERSION)) {
                $field = $property->getName();
                if (isset($config['refversion_field'])) {
                    throw new InvalidMappingException("There cannot be more than one refVersion field: [{$field}] and [{$config['status_refVersion']}], in class - {$meta->name}.");
                }
                $config['refVersion_field'] = $field;
            }
        }
    }
コード例 #7
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::TREE)) {
         if (!in_array($annot->type, $this->strategies)) {
             throw new InvalidMappingException("Tree type: {$annot->type} is not available.");
         }
         $config['strategy'] = $annot->type;
     }
     if ($annot = $this->reader->getClassAnnotation($class, self::CLOSURE)) {
         if (!class_exists($annot->class)) {
             throw new InvalidMappingException("Tree closure class: {$annot->class} does not exist.");
         }
         $config['closure'] = $annot->class;
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // left
         if ($left = $this->reader->getPropertyAnnotation($property, self::LEFT)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'left' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Tree left field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
             }
             $config['left'] = $field;
         }
         // right
         if ($right = $this->reader->getPropertyAnnotation($property, self::RIGHT)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'right' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Tree right field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
             }
             $config['right'] = $field;
         }
         // ancestor/parent
         if ($parent = $this->reader->getPropertyAnnotation($property, self::PARENT)) {
             $field = $property->getName();
             if (!$meta->isSingleValuedAssociation($field)) {
                 throw new InvalidMappingException("Unable to find ancestor/parent child relation through ancestor field - [{$field}] in class - {$meta->name}");
             }
             $config['parent'] = $field;
         }
         // root
         if ($root = $this->reader->getPropertyAnnotation($property, self::ROOT)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'root' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Tree root field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
             }
             $config['root'] = $field;
         }
         // level
         if ($parent = $this->reader->getPropertyAnnotation($property, self::LEVEL)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'level' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Tree level field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
             }
             $config['level'] = $field;
         }
     }
 }
コード例 #8
0
ファイル: Annotation.php プロジェクト: pabloasc/test_social
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata($meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     $validator = new Validator();
     if (!$class) {
         // based on recent doctrine 2.3.0-DEV maybe will be fixed in some way
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($meta->name);
     }
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::TREE)) {
         if (!in_array($annot->type, $this->strategies)) {
             throw new InvalidMappingException("Tree type: {$annot->type} is not available.");
         }
         $config['strategy'] = $annot->type;
         $config['activate_locking'] = $annot->activateLocking;
         $config['locking_timeout'] = (int) $annot->lockingTimeout;
         if ($config['locking_timeout'] < 1) {
             throw new InvalidMappingException("Tree Locking Timeout must be at least of 1 second.");
         }
     }
     if ($annot = $this->reader->getClassAnnotation($class, self::CLOSURE)) {
         if (!class_exists($annot->class)) {
             throw new InvalidMappingException("Tree closure class: {$annot->class} does not exist.");
         }
         $config['closure'] = $annot->class;
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // left
         if ($this->reader->getPropertyAnnotation($property, self::LEFT)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'left' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$validator->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Tree left field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
             }
             $config['left'] = $field;
         }
         // right
         if ($this->reader->getPropertyAnnotation($property, self::RIGHT)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'right' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$validator->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Tree right field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
             }
             $config['right'] = $field;
         }
         // ancestor/parent
         if ($this->reader->getPropertyAnnotation($property, self::PARENT)) {
             $field = $property->getName();
             if (!$meta->isSingleValuedAssociation($field)) {
                 throw new InvalidMappingException("Unable to find ancestor/parent child relation through ancestor field - [{$field}] in class - {$meta->name}");
             }
             $config['parent'] = $field;
         }
         // root
         if ($this->reader->getPropertyAnnotation($property, self::ROOT)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'root' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$validator->isValidFieldForRoot($meta, $field)) {
                 throw new InvalidMappingException("Tree root field - [{$field}] type is not valid and must be any of the 'integer' types or 'string' in class - {$meta->name}");
             }
             $config['root'] = $field;
         }
         // level
         if ($this->reader->getPropertyAnnotation($property, self::LEVEL)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'level' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$validator->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Tree level field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
             }
             $config['level'] = $field;
         }
         // path
         if ($pathAnnotation = $this->reader->getPropertyAnnotation($property, self::PATH)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'path' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$validator->isValidFieldForPath($meta, $field)) {
                 throw new InvalidMappingException("Tree Path field - [{$field}] type is not valid. It must be string or text in class - {$meta->name}");
             }
             if (strlen($pathAnnotation->separator) > 1) {
                 throw new InvalidMappingException("Tree Path field - [{$field}] Separator {$pathAnnotation->separator} is invalid. It must be only one character long.");
             }
             $config['path'] = $field;
             $config['path_separator'] = $pathAnnotation->separator;
         }
         // path source
         if ($this->reader->getPropertyAnnotation($property, self::PATH_SOURCE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'path_source' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$validator->isValidFieldForPathSource($meta, $field)) {
                 throw new InvalidMappingException("Tree PathSource field - [{$field}] type is not valid. It can be any of the integer variants, double, float or string in class - {$meta->name}");
             }
             $config['path_source'] = $field;
         }
         // lock time
         if ($this->reader->getPropertyAnnotation($property, self::LOCK_TIME)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'lock_time' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$validator->isValidFieldForLockTime($meta, $field)) {
                 throw new InvalidMappingException("Tree PathSource field - [{$field}] type is not valid. It must be \"date\" in class - {$meta->name}");
             }
             $config['lock_time'] = $field;
         }
     }
     if (isset($config['activate_locking']) && $config['activate_locking'] && !isset($config['lock_time'])) {
         throw new InvalidMappingException("You need to map a date field as the tree lock time field to activate locking support.");
     }
     if (!$meta->isMappedSuperclass && $config) {
         if (isset($config['strategy'])) {
             if (is_array($meta->identifier) && count($meta->identifier) > 1) {
                 throw new InvalidMappingException("Tree does not support composite identifiers in class - {$meta->name}");
             }
             $method = 'validate' . ucfirst($config['strategy']) . 'TreeMetadata';
             $validator->{$method}($meta, $config);
         } else {
             throw new InvalidMappingException("Cannot find Tree type for class: {$meta->name}");
         }
     }
 }
コード例 #9
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata($meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     if (!$class) {
         // based on recent doctrine 2.3.0-DEV maybe will be fixed in some way
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($meta->name);
     }
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::UPLOADABLE)) {
         $config['uploadable'] = true;
         $config['allowOverwrite'] = $annot->allowOverwrite;
         $config['appendNumber'] = $annot->appendNumber;
         $config['path'] = $annot->path;
         $config['pathMethod'] = $annot->pathMethod;
         $config['fileMimeTypeField'] = false;
         $config['filePathField'] = false;
         $config['fileSizeField'] = false;
         $config['callback'] = $annot->callback;
         $config['filenameGenerator'] = $annot->filenameGenerator;
         $config['maxSize'] = (double) $annot->maxSize;
         $config['allowedTypes'] = $annot->allowedTypes;
         $config['disallowedTypes'] = $annot->disallowedTypes;
         foreach ($class->getProperties() as $prop) {
             if ($this->reader->getPropertyAnnotation($prop, self::UPLOADABLE_FILE_MIME_TYPE)) {
                 $config['fileMimeTypeField'] = $prop->getName();
             }
             if ($this->reader->getPropertyAnnotation($prop, self::UPLOADABLE_FILE_PATH)) {
                 $config['filePathField'] = $prop->getName();
             }
             if ($this->reader->getPropertyAnnotation($prop, self::UPLOADABLE_FILE_SIZE)) {
                 $config['fileSizeField'] = $prop->getName();
             }
         }
         Validator::validateConfiguration($meta, $config);
     }
     /*
             // Code in case we need to identify entities which are not Uploadables, but have associations
             // with other Uploadable entities
     
             } else {
                 // We need to check if this class has a relation with Uploadable entities
                 $associations = $meta->getAssociationMappings();
     
                 foreach ($associations as $field => $association) {
                     $refl = new \ReflectionClass($association['targetEntity']);
     
                     if ($annot = $this->reader->getClassAnnotation($refl, self::UPLOADABLE)) {
                         $config['hasUploadables'] = true;
     
                         if (!isset($config['uploadables'])) {
                             $config['uploadables'] = array();
                         }
     
                         $config['uploadables'][] = array(
                             'class'         => $association['targetEntity'],
                             'property'      => $association['fieldName']
                         );
                     }
                 }
             }*/
     $this->validateFullMetadata($meta, $config);
 }