示例#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'])) {
                 if (in_array('sluggable', $fieldMapping['gedmo'])) {
                     if (!$this->_isValidField($meta, $field)) {
                         throw MappingException::notValidFieldType($field, $meta->name);
                     }
                     $config['fields'][] = $field;
                 } elseif (isset($fieldMapping['gedmo']['slug']) || in_array('slug', $fieldMapping['gedmo'])) {
                     $slug = $fieldMapping['gedmo']['slug'];
                     if (!$this->_isValidField($meta, $field)) {
                         throw MappingException::notValidFieldType($field, $meta->name);
                     }
                     if (isset($config['slug'])) {
                         throw MappingException::slugFieldIsDuplicate($field, $meta->name);
                     }
                     $config['slug'] = $field;
                     $config['style'] = isset($slug['style']) ? (string) $slug['style'] : 'default';
                     $config['updatable'] = isset($slug['updatable']) ? (bool) $slug['updatable'] : true;
                     $config['unique'] = isset($slug['unique']) ? (bool) $slug['unique'] : true;
                     $config['separator'] = isset($slug['separator']) ? (string) $slug['separator'] : '-';
                 }
             }
         }
     }
 }
示例#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\\Sluggable\\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;
         }
         // sluggable property
         if ($sluggable = $reader->getPropertyAnnotation($property, self::ANNOTATION_SLUGGABLE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw MappingException::fieldMustBeMapped($field, $meta->name);
             }
             if (!$this->_isValidField($meta, $field)) {
                 throw MappingException::notValidFieldType($field, $meta->name);
             }
             $config['fields'][] = $field;
         }
         // slug property
         if ($slug = $reader->getPropertyAnnotation($property, self::ANNOTATION_SLUG)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw MappingException::slugFieldMustBeMapped($field, $meta->name);
             }
             if (!$this->_isValidField($meta, $field)) {
                 throw MappingException::notValidFieldType($field, $meta->name);
             }
             if (isset($config['slug'])) {
                 throw MappingException::slugFieldIsDuplicate($field, $meta->name);
             }
             $config['slug'] = $field;
             $config['style'] = $slug->style;
             $config['updatable'] = $slug->updatable;
             $config['unique'] = $slug->unique;
             $config['separator'] = $slug->separator;
         }
     }
 }