当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassMetadataInfo::setChangeTrackingPolicy方法代码示例

本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadataInfo::setChangeTrackingPolicy方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataInfo::setChangeTrackingPolicy方法的具体用法?PHP ClassMetadataInfo::setChangeTrackingPolicy怎么用?PHP ClassMetadataInfo::setChangeTrackingPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\Mapping\ClassMetadataInfo的用法示例。


在下文中一共展示了ClassMetadataInfo::setChangeTrackingPolicy方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadMetadata

 public static function loadMetadata(ClassMetadataInfo $metadata)
 {
     $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
     $metadata->setPrimaryTable(array('name' => 'cms_users'));
     $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
     $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
     $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
     $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
     $metadata->mapField(array('id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id'));
     $metadata->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50, 'unique' => true, 'nullable' => true, 'columnName' => 'name'));
     $metadata->mapField(array('fieldName' => 'email', 'type' => 'string', 'columnName' => 'user_email', 'columnDefinition' => 'CHAR(32) NOT NULL'));
     $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     $metadata->mapOneToOne(array('fieldName' => 'address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address', 'cascade' => array(0 => 'remove'), 'mappedBy' => NULL, 'inversedBy' => 'user', 'joinColumns' => array(0 => array('name' => 'address_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')), 'orphanRemoval' => false));
     $metadata->mapOneToMany(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber', 'cascade' => array(1 => 'persist'), 'mappedBy' => 'user', 'orphanRemoval' => true, 'orderBy' => array('number' => 'ASC')));
     $metadata->mapManyToMany(array('fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group', 'cascade' => array(0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach'), 'mappedBy' => NULL, 'joinTable' => array('name' => 'cms_users_groups', 'joinColumns' => array(0 => array('name' => 'user_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false)), 'inverseJoinColumns' => array(0 => array('name' => 'group_id', 'referencedColumnName' => 'id', 'columnDefinition' => 'INT NULL'))), 'orderBy' => NULL));
     $metadata->table['uniqueConstraints'] = array('search_idx' => array('columns' => array('name', 'user_email')));
     $metadata->table['indexes'] = array('name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email')));
     $metadata->setSequenceGeneratorDefinition(array('sequenceName' => 'tablename_seq', 'allocationSize' => 100, 'initialValue' => 1));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:19,代码来源:AbstractMappingDriverTest.php

示例2: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
 {
     $xmlRoot = $this->getElement($className);
     if ($xmlRoot->getName() == 'entity') {
         if (isset($xmlRoot['repository-class'])) {
             $metadata->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
         }
         if (isset($xmlRoot['read-only']) && $xmlRoot['read-only'] == "true") {
             $metadata->markReadOnly();
         }
     } else {
         if ($xmlRoot->getName() == 'mapped-superclass') {
             $metadata->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
         }
     }
     // Evaluate <entity...> attributes
     $table = array();
     if (isset($xmlRoot['table'])) {
         $table['name'] = (string) $xmlRoot['table'];
     }
     $metadata->setPrimaryTable($table);
     // Evaluate named queries
     if (isset($xmlRoot['named-queries'])) {
         foreach ($xmlRoot->{'named-queries'}->{'named-query'} as $namedQueryElement) {
             $metadata->addNamedQuery(array('name' => (string) $namedQueryElement['name'], 'query' => (string) $namedQueryElement['query']));
         }
     }
     /* not implemented specially anyway. use table = schema.table
        if (isset($xmlRoot['schema'])) {
            $metadata->table['schema'] = (string)$xmlRoot['schema'];
        }*/
     if (isset($xmlRoot['inheritance-type'])) {
         $inheritanceType = (string) $xmlRoot['inheritance-type'];
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate <discriminator-column...>
             if (isset($xmlRoot->{'discriminator-column'})) {
                 $discrColumn = $xmlRoot->{'discriminator-column'};
                 $metadata->setDiscriminatorColumn(array('name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : null, 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : null, 'columnDefinition' => isset($discrColumn['column-definition']) ? (string) $discrColumn['column-definition'] : null));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate <discriminator-map...>
             if (isset($xmlRoot->{'discriminator-map'})) {
                 $map = array();
                 foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
                     $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
                 }
                 $metadata->setDiscriminatorMap($map);
             }
         }
     }
     // Evaluate <change-tracking-policy...>
     if (isset($xmlRoot['change-tracking-policy'])) {
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot['change-tracking-policy'])));
     }
     // Evaluate <indexes...>
     if (isset($xmlRoot->indexes)) {
         $metadata->table['indexes'] = array();
         foreach ($xmlRoot->indexes->index as $index) {
             $columns = explode(',', (string) $index['columns']);
             if (isset($index['name'])) {
                 $metadata->table['indexes'][(string) $index['name']] = array('columns' => $columns);
             } else {
                 $metadata->table['indexes'][] = array('columns' => $columns);
             }
         }
     }
     // Evaluate <unique-constraints..>
     if (isset($xmlRoot->{'unique-constraints'})) {
         $metadata->table['uniqueConstraints'] = array();
         foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) {
             $columns = explode(',', (string) $unique['columns']);
             if (isset($unique['name'])) {
                 $metadata->table['uniqueConstraints'][(string) $unique['name']] = array('columns' => $columns);
             } else {
                 $metadata->table['uniqueConstraints'][] = array('columns' => $columns);
             }
         }
     }
     if (isset($xmlRoot->options)) {
         $metadata->table['options'] = $this->_parseOptions($xmlRoot->options->children());
     }
     // Evaluate <field ...> mappings
     if (isset($xmlRoot->field)) {
         foreach ($xmlRoot->field as $fieldMapping) {
             $mapping = array('fieldName' => (string) $fieldMapping['name']);
             if (isset($fieldMapping['type'])) {
                 $mapping['type'] = (string) $fieldMapping['type'];
             }
             if (isset($fieldMapping['column'])) {
                 $mapping['columnName'] = (string) $fieldMapping['column'];
             }
             if (isset($fieldMapping['length'])) {
//.........这里部分代码省略.........
开发者ID:SerdarSanri,项目名称:doctrine-bundle,代码行数:101,代码来源:XmlDriver.php

示例3: setChangeTrackingPolicyNotify

 /**
  * Sets notify change tracking policy.
  *
  * @return ClassMetadataBuilder
  */
 public function setChangeTrackingPolicyNotify()
 {
     $this->cm->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_NOTIFY);
     return $this;
 }
开发者ID:nemekzg,项目名称:doctrine2,代码行数:10,代码来源:ClassMetadataBuilder.php

示例4: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
 {
     $class = $metadata->getReflectionClass();
     if (!$class) {
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($metadata->name);
     }
     $classAnnotations = $this->_reader->getClassAnnotations($class);
     // Compatibility with Doctrine Common 3.x
     if ($classAnnotations && is_int(key($classAnnotations))) {
         foreach ($classAnnotations as $annot) {
             $classAnnotations[get_class($annot)] = $annot;
         }
     }
     // Evaluate Entity annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Entity'];
         if ($entityAnnot->repositoryClass !== null) {
             $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
         }
         if ($entityAnnot->readOnly) {
             $metadata->markReadOnly();
         }
     } else {
         if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'])) {
             $mappedSuperclassAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'];
             $metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
         }
     }
     // Evaluate Table annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable = array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema);
         if ($tableAnnot->indexes !== null) {
             foreach ($tableAnnot->indexes as $indexAnnot) {
                 $primaryTable['indexes'][$indexAnnot->name] = array('columns' => $indexAnnot->columns);
             }
         }
         if ($tableAnnot->uniqueConstraints !== null) {
             foreach ($tableAnnot->uniqueConstraints as $uniqueConstraint) {
                 $primaryTable['uniqueConstraints'][$uniqueConstraint->name] = array('columns' => $uniqueConstraint->columns);
             }
         }
         if ($tableAnnot->options !== null) {
             $primaryTable['options'] = $tableAnnot->options;
         }
         $metadata->setPrimaryTable($primaryTable);
     }
     // Evaluate NamedQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'])) {
         $namedQueriesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'];
         if (!is_array($namedQueriesAnnot->value)) {
             throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
         }
         foreach ($namedQueriesAnnot->value as $namedQuery) {
             if (!$namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery) {
                 throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
             }
             $metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
         }
     }
     // Evaluate InheritanceType annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
         $inheritanceTypeAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate DiscriminatorColumn annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
                 $discrColumnAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type, 'length' => $discrColumnAnnot->length, 'columnDefinition' => $discrColumnAnnot->columnDefinition));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate DiscriminatorMap annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
                 $discrMapAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
                 $metadata->setDiscriminatorMap($discrMapAnnot->value);
             }
         }
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value));
     }
     // Evaluate annotations on properties/fields
     foreach ($class->getProperties() as $property) {
         if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) || $metadata->isInheritedAssociation($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Check for JoinColummn/JoinColumns annotations
//.........这里部分代码省略.........
开发者ID:SerdarSanri,项目名称:doctrine-bundle,代码行数:101,代码来源:AnnotationDriver.php

示例5: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
 {
     $element = $this->getElement($className);
     if ($element['type'] == 'entity') {
         if (isset($element['repositoryClass'])) {
             $metadata->setCustomRepositoryClass($element['repositoryClass']);
         }
         if (isset($element['readOnly']) && $element['readOnly'] == true) {
             $metadata->markReadOnly();
         }
     } else {
         if ($element['type'] == 'mappedSuperclass') {
             $metadata->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
         }
     }
     // Evaluate root level properties
     $table = array();
     if (isset($element['table'])) {
         $table['name'] = $element['table'];
     }
     $metadata->setPrimaryTable($table);
     // Evaluate named queries
     if (isset($element['namedQueries'])) {
         foreach ($element['namedQueries'] as $name => $queryMapping) {
             if (is_string($queryMapping)) {
                 $queryMapping = array('query' => $queryMapping);
             }
             if (!isset($queryMapping['name'])) {
                 $queryMapping['name'] = $name;
             }
             $metadata->addNamedQuery($queryMapping);
         }
     }
     /* not implemented specially anyway. use table = schema.table
        if (isset($element['schema'])) {
            $metadata->table['schema'] = $element['schema'];
        }*/
     if (isset($element['inheritanceType'])) {
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate discriminatorColumn
             if (isset($element['discriminatorColumn'])) {
                 $discrColumn = $element['discriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => $discrColumn['name'], 'type' => $discrColumn['type'], 'length' => $discrColumn['length']));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate discriminatorMap
             if (isset($element['discriminatorMap'])) {
                 $metadata->setDiscriminatorMap($element['discriminatorMap']);
             }
         }
     }
     // Evaluate changeTrackingPolicy
     if (isset($element['changeTrackingPolicy'])) {
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper($element['changeTrackingPolicy'])));
     }
     // Evaluate indexes
     if (isset($element['indexes'])) {
         foreach ($element['indexes'] as $name => $index) {
             if (!isset($index['name'])) {
                 $index['name'] = $name;
             }
             if (is_string($index['columns'])) {
                 $columns = explode(',', $index['columns']);
             } else {
                 $columns = $index['columns'];
             }
             $metadata->table['indexes'][$index['name']] = array('columns' => $columns);
         }
     }
     // Evaluate uniqueConstraints
     if (isset($element['uniqueConstraints'])) {
         foreach ($element['uniqueConstraints'] as $name => $unique) {
             if (!isset($unique['name'])) {
                 $unique['name'] = $name;
             }
             if (is_string($unique['columns'])) {
                 $columns = explode(',', $unique['columns']);
             } else {
                 $columns = $unique['columns'];
             }
             $metadata->table['uniqueConstraints'][$unique['name']] = array('columns' => $columns);
         }
     }
     $associationIds = array();
     if (isset($element['id'])) {
         // Evaluate identifier settings
         foreach ($element['id'] as $name => $idElement) {
             if (isset($idElement['associationKey']) && $idElement['associationKey'] == true) {
                 $associationIds[$name] = true;
                 continue;
             }
             $mapping = array('id' => true, 'fieldName' => $name);
//.........这里部分代码省略.........
开发者ID:williamamed,项目名称:Raptor2,代码行数:101,代码来源:YamlDriver.php

示例6: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
 {
     $xmlRoot = $this->getElement($className);
     if ($xmlRoot->getName() == 'entity') {
         $metadata->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
     } else {
         if ($xmlRoot->getName() == 'mapped-superclass') {
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMapperSuperClass($className);
         }
     }
     // Evaluate <entity...> attributes
     if (isset($xmlRoot['table'])) {
         $metadata->primaryTable['name'] = (string) $xmlRoot['table'];
     }
     if (isset($xmlRoot['schema'])) {
         $metadata->primaryTable['schema'] = (string) $xmlRoot['schema'];
     }
     if (isset($xmlRoot['inheritance-type'])) {
         $metadata->setInheritanceType((string) $xmlRoot['inheritance-type']);
     }
     // Evaluate <discriminator-column...>
     if (isset($xmlRoot->{'discriminator-column'})) {
         $discrColumn = $xmlRoot->{'discriminator-column'};
         $metadata->setDiscriminatorColumn(array('name' => (string) $discrColumn['name'], 'type' => (string) $discrColumn['type'], 'length' => (string) $discrColumn['length']));
     }
     // Evaluate <discriminator-map...>
     if (isset($xmlRoot->{'discriminator-map'})) {
         $metadata->setDiscriminatorMap((array) $xmlRoot->{'discriminator-map'});
     }
     // Evaluate <change-tracking-policy...>
     if (isset($xmlRoot->{'change-tracking-policy'})) {
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot->{'change-tracking-policy'})));
     }
     // Evaluate <indexes...>
     if (isset($xmlRoot->indexes)) {
         foreach ($xmlRoot->indexes->index as $index) {
             if (is_string($index['columns'])) {
                 $columns = explode(',', $index['columns']);
             } else {
                 $columns = $index['columns'];
             }
             $metadata->primaryTable['indexes'][$index['name']] = array('columns' => $columns);
         }
     }
     // Evaluate <unique-constraints..>
     if (isset($xmlRoot->{'unique-constraints'})) {
         foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) {
             if (is_string($unique['columns'])) {
                 $columns = explode(',', $unique['columns']);
             } else {
                 $columns = $unique['columns'];
             }
             $metadata->primaryTable['uniqueConstraints'][$unique['name']] = array('columns' => $columns);
         }
     }
     // Evaluate <field ...> mappings
     if (isset($xmlRoot->field)) {
         foreach ($xmlRoot->field as $fieldMapping) {
             $mapping = array('fieldName' => (string) $fieldMapping['name'], 'type' => (string) $fieldMapping['type']);
             if (isset($fieldMapping['column'])) {
                 $mapping['columnName'] = (string) $fieldMapping['column'];
             }
             if (isset($fieldMapping['length'])) {
                 $mapping['length'] = (int) $fieldMapping['length'];
             }
             if (isset($fieldMapping['precision'])) {
                 $mapping['precision'] = (int) $fieldMapping['precision'];
             }
             if (isset($fieldMapping['scale'])) {
                 $mapping['scale'] = (int) $fieldMapping['scale'];
             }
             if (isset($fieldMapping['unique'])) {
                 $mapping['unique'] = (string) $fieldMapping['unique'] == "false" ? false : true;
             }
             if (isset($fieldMapping['options'])) {
                 $mapping['options'] = (array) $fieldMapping['options'];
             }
             if (isset($fieldMapping['nullable'])) {
                 $mapping['nullable'] = (string) $fieldMapping['nullable'] == "false" ? false : true;
             }
             if (isset($fieldMapping['version']) && $fieldMapping['version']) {
                 $metadata->setVersionMapping($mapping);
             }
             if (isset($fieldMapping['column-definition'])) {
                 $mapping['columnDefinition'] = (string) $fieldMapping['column-definition'];
             }
             $metadata->mapField($mapping);
         }
     }
     // Evaluate <id ...> mappings
     foreach ($xmlRoot->id as $idElement) {
         $mapping = array('id' => true, 'fieldName' => (string) $idElement['name'], 'type' => (string) $idElement['type']);
         if (isset($idElement['column'])) {
             $mapping['columnName'] = (string) $idElement['column'];
         }
//.........这里部分代码省略.........
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:101,代码来源:XmlDriver.php

示例7: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
 {
     $class = $metadata->getReflectionClass();
     $classAnnotations = $this->_reader->getClassAnnotations($class);
     // Evaluate Entity annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Entity'];
         $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
     } else {
         if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'])) {
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
         }
     }
     // Evaluate DoctrineTable annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable = array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema);
         if ($tableAnnot->indexes !== null) {
             foreach ($tableAnnot->indexes as $indexAnnot) {
                 $primaryTable['indexes'][$indexAnnot->name] = array('columns' => $indexAnnot->columns);
             }
         }
         if ($tableAnnot->uniqueConstraints !== null) {
             foreach ($tableAnnot->uniqueConstraints as $uniqueConstraint) {
                 $primaryTable['uniqueConstraints'][$uniqueConstraint->name] = array('columns' => $uniqueConstraint->columns);
             }
         }
         $metadata->setPrimaryTable($primaryTable);
     }
     // Evaluate InheritanceType annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
         $inheritanceTypeAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
         $metadata->setInheritanceType(constant('\\Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
     }
     // Evaluate DiscriminatorColumn annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
         $discrColumnAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
         $metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type, 'length' => $discrColumnAnnot->length));
     }
     // Evaluate DiscriminatorMap annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
         $discrMapAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
         $metadata->setDiscriminatorMap($discrMapAnnot->value);
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
         $metadata->setChangeTrackingPolicy($changeTrackingAnnot->value);
     }
     // Evaluate annotations on properties/fields
     foreach ($class->getProperties() as $property) {
         if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) || $metadata->isInheritedAssociation($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Check for JoinColummn/JoinColumns annotations
         $joinColumns = array();
         if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumn')) {
             $joinColumns[] = array('name' => $joinColumnAnnot->name, 'referencedColumnName' => $joinColumnAnnot->referencedColumnName, 'unique' => $joinColumnAnnot->unique, 'nullable' => $joinColumnAnnot->nullable, 'onDelete' => $joinColumnAnnot->onDelete, 'onUpdate' => $joinColumnAnnot->onUpdate, 'columnDefinition' => $joinColumnAnnot->columnDefinition);
         } else {
             if ($joinColumnsAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumns')) {
                 foreach ($joinColumnsAnnot->value as $joinColumn) {
                     $joinColumns[] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'onUpdate' => $joinColumn->onUpdate, 'columnDefinition' => $joinColumn->columnDefinition);
                 }
             }
         }
         // Field can only be annotated with one of:
         // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
         if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
             if ($columnAnnot->type == null) {
                 throw MappingException::propertyTypeIsRequired($className, $property->getName());
             }
             $mapping['type'] = $columnAnnot->type;
             $mapping['length'] = $columnAnnot->length;
             $mapping['precision'] = $columnAnnot->precision;
             $mapping['scale'] = $columnAnnot->scale;
             $mapping['nullable'] = $columnAnnot->nullable;
             $mapping['unique'] = $columnAnnot->unique;
             if ($columnAnnot->options) {
                 $mapping['options'] = $columnAnnot->options;
             }
             if (isset($columnAnnot->name)) {
                 $mapping['columnName'] = $columnAnnot->name;
             }
             if (isset($columnAnnot->columnDefinition)) {
                 $mapping['columnDefinition'] = $columnAnnot->columnDefinition;
             }
             if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
             }
             if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Version')) {
//.........这里部分代码省略.........
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:101,代码来源:AnnotationDriver.php

示例8: loadMetadataForClass


//.........这里部分代码省略.........
         throw \Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
     }
     // Evaluate Table annotation
     $primaryTable = array();
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable['name'] = $tableAnnotation->name;
         $primaryTable['schema'] = $tableAnnotation->schema;
         if ($tableAnnotation->indexes !== NULL) {
             foreach ($tableAnnotation->indexes as $indexAnnotation) {
                 $index = array('columns' => $indexAnnotation->columns);
                 if (!empty($indexAnnotation->name)) {
                     $primaryTable['indexes'][$indexAnnotation->name] = $index;
                 } else {
                     $primaryTable['indexes'][] = $index;
                 }
             }
         }
         if ($tableAnnotation->uniqueConstraints !== NULL) {
             foreach ($tableAnnotation->uniqueConstraints as $uniqueConstraint) {
                 $uniqueConstraint = array('columns' => $uniqueConstraint->columns);
                 if (!empty($uniqueConstraint->name)) {
                     $primaryTable['uniqueConstraints'][$uniqueConstraint->name] = $uniqueConstraint;
                 } else {
                     $primaryTable['uniqueConstraints'][] = $uniqueConstraint;
                 }
             }
         }
     }
     if (!isset($primaryTable['name'])) {
         $className = $classSchema->getClassName();
         $primaryTable['name'] = $this->inferTableNameFromClassName($className);
     }
     // Evaluate NamedQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'])) {
         $namedQueriesAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'];
         if (!is_array($namedQueriesAnnotation->value)) {
             throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
         }
         foreach ($namedQueriesAnnotation->value as $namedQuery) {
             if (!$namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery) {
                 throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
             }
             $metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
         }
     }
     // Evaluate InheritanceType annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
         $inheritanceTypeAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($inheritanceTypeAnnotation->value)));
         if ($metadata->inheritanceType !== \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate DiscriminatorColumn annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
                 $discriminatorColumnAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => $discriminatorColumnAnnotation->name, 'type' => $discriminatorColumnAnnotation->type, 'length' => $discriminatorColumnAnnotation->length));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate DiscriminatorMap annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
                 $discriminatorMapAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
                 $metadata->setDiscriminatorMap($discriminatorMapAnnotation->value);
             } else {
                 $discriminatorMap = array();
                 $subclassNames = $this->reflectionService->getAllSubClassNamesForClass($className);
                 if (!$this->reflectionService->isClassAbstract($className)) {
                     $mappedClassName = strtolower(str_replace('Domain_Model_', '', str_replace('\\', '_', $className)));
                     $discriminatorMap[$mappedClassName] = $className;
                 }
                 foreach ($subclassNames as $subclassName) {
                     $mappedSubclassName = strtolower(str_replace('Domain_Model_', '', str_replace('\\', '_', $subclassName)));
                     $discriminatorMap[$mappedSubclassName] = $subclassName;
                 }
                 $metadata->setDiscriminatorMap($discriminatorMap);
             }
         }
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper($changeTrackingAnnotation->value)));
     } else {
         $metadata->setChangeTrackingPolicy(\Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT);
     }
     // Evaluate annotations on properties/fields
     $this->evaluatePropertyAnnotations($metadata);
     // build unique index for table
     if (!isset($primaryTable['uniqueConstraints'])) {
         $idProperties = array_keys($classSchema->getIdentityProperties());
         if (array_diff($idProperties, $metadata->getIdentifierFieldNames()) !== array()) {
             $uniqueIndexName = $this->truncateIdentifier('flow3_identity_' . $primaryTable['name']);
             foreach ($idProperties as $idProperty) {
                 $primaryTable['uniqueConstraints'][$uniqueIndexName]['columns'][] = isset($metadata->columnNames[$idProperty]) ? $metadata->columnNames[$idProperty] : strtolower($idProperty);
             }
         }
     }
     $metadata->setPrimaryTable($primaryTable);
     // Evaluate @HasLifecycleCallbacks annotation
     $this->evaluateLifeCycleAnnotations($class, $metadata);
 }
开发者ID:nxpthx,项目名称:FLOW3,代码行数:101,代码来源:Flow3AnnotationDriver.php

示例9: array

    'joinColumns' => array(
        array('name' => 'author_id', 'referencedColumnName' => 'id')
    ),
));
$metadata->mapManyToMany(array(
    'fieldName' => 'comments',
    'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorComment',
    'joinTable' => array(
        'name' => 'book_comment',
        'joinColumns' => array(array('name' => 'book_id', 'referencedColumnName' => 'id')),
        'inverseJoinColumns' => array(array('name' => 'comment_id', 'referencedColumnName' => 'id')),
    ),
));
$metadata->addLifecycleCallback('loading', 'postLoad');
$metadata->addLifecycleCallback('willBeRemoved', 'preRemove');
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT);

$builder = new BaseActiveRecord($metadata);

$builder->setMappingDriver(BaseActiveRecord::MAPPING_STATIC_PHP | BaseActiveRecord::MAPPING_ANNOTATION);
$builder->setAnnotationPrefix('orm');

// using custom templates to tweak EntityManager
$builder->addTemplateDir(__DIR__ . '/templates');

// using extensions
$builder->addExtension(new Timestampable());
$builder->addExtension(new GenerationTimestamp());

echo $builder->getCode();
开发者ID:regisg27,项目名称:Propel2,代码行数:31,代码来源:demo.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadataInfo::setChangeTrackingPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。