예제 #1
0
파일: Yaml.php 프로젝트: jgat2012/hp_oms
 /**
  * (non-PHPdoc)
  * @see Gedmo\Mapping.Driver::readExtendedMetadata()
  */
 public function readExtendedMetadata(ClassMetadataInfo $meta, array &$config)
 {
     $yaml = $this->_loadMappingFile($this->_findMappingFile($meta->name));
     $mapping = $yaml[$meta->name];
     if (isset($mapping['fields'])) {
         foreach ($mapping['fields'] as $field => $fieldMapping) {
             if (isset($fieldMapping['gedmo']['timestampable'])) {
                 $mappingProperty = $fieldMapping['gedmo']['timestampable'];
                 if (!$this->_isValidField($meta, $field)) {
                     throw MappingException::notValidFieldType($field, $meta->name);
                 }
                 if (!isset($mappingProperty['on']) || !in_array($mappingProperty['on'], array('update', 'create', 'change'))) {
                     throw MappingException::triggerTypeInvalid($field, $meta->name);
                 }
                 if ($mappingProperty['on'] == 'change') {
                     if (!isset($mappingProperty['field']) || !isset($mappingProperty['value'])) {
                         throw MappingException::parametersMissing($field, $meta->name);
                     }
                     $field = array('field' => $field, 'trackedField' => $mappingProperty['field'], 'value' => $mappingProperty['value']);
                 }
                 $config[$mappingProperty['on']][] = $field;
             }
         }
     }
 }
예제 #2
0
 /**
  * (non-PHPdoc)
  * @see Gedmo\Mapping.Driver::readExtendedMetadata()
  */
 public function readExtendedMetadata(ClassMetadataInfo $meta, array &$config)
 {
     require_once __DIR__ . '/../Annotations.php';
     $reader = new AnnotationReader();
     $reader->setAnnotationNamespaceAlias('Gedmo\\Timestampable\\Mapping\\', 'gedmo');
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || $meta->isInheritedAssociation($property->name)) {
             continue;
         }
         if ($timestampable = $reader->getPropertyAnnotation($property, self::ANNOTATION_TIMESTAMPABLE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw MappingException::fieldMustBeMapped($field, $meta->name);
             }
             if (!$this->_isValidField($meta, $field)) {
                 throw MappingException::notValidFieldType($field, $meta->name);
             }
             if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
                 throw MappingException::triggerTypeInvalid($field, $meta->name);
             }
             if ($timestampable->on == 'change') {
                 if (!isset($timestampable->field) || !isset($timestampable->value)) {
                     throw MappingException::parametersMissing($field, $meta->name);
                 }
                 $field = array('field' => $field, 'trackedField' => $timestampable->field, 'value' => $timestampable->value);
             }
             // properties are unique and mapper checks that, no risk here
             $config[$timestampable->on][] = $field;
         }
     }
 }