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


PHP ClassMetadata::setAssociationOverride方法代码示例

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


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

示例1: loadMetadataForClass


//.........这里部分代码省略.........
                             $mapping['joinTable'] = $joinTable;
                             $mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
                             $mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
                             $mapping['inversedBy'] = $manyToManyAnnot->inversedBy;
                             $mapping['cascade'] = $manyToManyAnnot->cascade;
                             $mapping['indexBy'] = $manyToManyAnnot->indexBy;
                             $mapping['orphanRemoval'] = $manyToManyAnnot->orphanRemoval;
                             $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnot->fetch);
                             if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                                 $mapping['orderBy'] = $orderByAnnot->value;
                             }
                             $metadata->mapManyToMany($mapping);
                         } else {
                             if ($embeddedAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Embedded')) {
                                 $mapping['class'] = $embeddedAnnot->class;
                                 $mapping['columnPrefix'] = $embeddedAnnot->columnPrefix;
                                 $metadata->mapEmbedded($mapping);
                             }
                         }
                     }
                 }
             }
         }
     }
     // Evaluate AssociationOverrides annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\AssociationOverrides'])) {
         $associationOverridesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\AssociationOverrides'];
         foreach ($associationOverridesAnnot->value as $associationOverride) {
             $override = array();
             $fieldName = $associationOverride->name;
             // Check for JoinColumn/JoinColumns annotations
             if ($associationOverride->joinColumns) {
                 $joinColumns = array();
                 foreach ($associationOverride->joinColumns as $joinColumn) {
                     $joinColumns[] = $this->joinColumnToArray($joinColumn);
                 }
                 $override['joinColumns'] = $joinColumns;
             }
             // Check for JoinTable annotations
             if ($associationOverride->joinTable) {
                 $joinTableAnnot = $associationOverride->joinTable;
                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema);
                 foreach ($joinTableAnnot->joinColumns as $joinColumn) {
                     $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);
                 }
                 foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
                     $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumn);
                 }
                 $override['joinTable'] = $joinTable;
             }
             // Check for inversedBy
             if ($associationOverride->inversedBy) {
                 $override['inversedBy'] = $associationOverride->inversedBy;
             }
             $metadata->setAssociationOverride($fieldName, $override);
         }
     }
     // Evaluate AttributeOverrides annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\AttributeOverrides'])) {
         $attributeOverridesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\AttributeOverrides'];
         foreach ($attributeOverridesAnnot->value as $attributeOverrideAnnot) {
             $attributeOverride = $this->columnToArray($attributeOverrideAnnot->name, $attributeOverrideAnnot->column);
             $metadata->setAttributeOverride($attributeOverrideAnnot->name, $attributeOverride);
         }
     }
     // Evaluate EntityListeners annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\EntityListeners'])) {
         $entityListenersAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\EntityListeners'];
         foreach ($entityListenersAnnot->value as $item) {
             $listenerClassName = $metadata->fullyQualifiedClassName($item);
             if (!class_exists($listenerClassName)) {
                 throw MappingException::entityListenerClassNotFound($listenerClassName, $className);
             }
             $hasMapping = false;
             $listenerClass = new \ReflectionClass($listenerClassName);
             /* @var $method \ReflectionMethod */
             foreach ($listenerClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                 // find method callbacks.
                 $callbacks = $this->getMethodCallbacks($method);
                 $hasMapping = $hasMapping ?: !empty($callbacks);
                 foreach ($callbacks as $value) {
                     $metadata->addEntityListener($value[1], $listenerClassName, $value[0]);
                 }
             }
             // Evaluate the listener using naming convention.
             if (!$hasMapping) {
                 EntityListenerBuilder::bindEntityListener($metadata, $listenerClassName);
             }
         }
     }
     // Evaluate @HasLifecycleCallbacks annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\HasLifecycleCallbacks'])) {
         /* @var $method \ReflectionMethod */
         foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
             foreach ($this->getMethodCallbacks($method) as $value) {
                 $metadata->addLifecycleCallback($value[0], $value[1]);
             }
         }
     }
 }
开发者ID:aschempp,项目名称:doctrine2,代码行数:101,代码来源:AnnotationDriver.php

示例2: loadMetadataForClass


//.........这里部分代码省略.........
         foreach ($xmlRoot->{'many-to-many'} as $manyToManyElement) {
             $mapping = array('fieldName' => (string) $manyToManyElement['field'], 'targetEntity' => (string) $manyToManyElement['target-entity']);
             if (isset($manyToManyElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $manyToManyElement['fetch']);
             }
             if (isset($manyToManyElement['orphan-removal'])) {
                 $mapping['orphanRemoval'] = $this->evaluateBoolean($manyToManyElement['orphan-removal']);
             }
             if (isset($manyToManyElement['mapped-by'])) {
                 $mapping['mappedBy'] = (string) $manyToManyElement['mapped-by'];
             } else {
                 if (isset($manyToManyElement->{'join-table'})) {
                     if (isset($manyToManyElement['inversed-by'])) {
                         $mapping['inversedBy'] = (string) $manyToManyElement['inversed-by'];
                     }
                     $joinTableElement = $manyToManyElement->{'join-table'};
                     $joinTable = array('name' => (string) $joinTableElement['name']);
                     if (isset($joinTableElement['schema'])) {
                         $joinTable['schema'] = (string) $joinTableElement['schema'];
                     }
                     foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                     foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                     $mapping['joinTable'] = $joinTable;
                 }
             }
             if (isset($manyToManyElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($manyToManyElement->cascade);
             }
             if (isset($manyToManyElement->{'order-by'})) {
                 $orderBy = array();
                 foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) {
                     $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction'];
                 }
                 $mapping['orderBy'] = $orderBy;
             }
             if (isset($manyToManyElement['index-by'])) {
                 $mapping['indexBy'] = (string) $manyToManyElement['index-by'];
             } else {
                 if (isset($manyToManyElement->{'index-by'})) {
                     throw new \InvalidArgumentException("<index-by /> is not a valid tag");
                 }
             }
             $metadata->mapManyToMany($mapping);
         }
     }
     // Evaluate association-overrides
     if (isset($xmlRoot->{'attribute-overrides'})) {
         foreach ($xmlRoot->{'attribute-overrides'}->{'attribute-override'} as $overrideElement) {
             $fieldName = (string) $overrideElement['name'];
             foreach ($overrideElement->field as $field) {
                 $mapping = $this->columnToArray($field);
                 $mapping['fieldName'] = $fieldName;
                 $metadata->setAttributeOverride($fieldName, $mapping);
             }
         }
     }
     // Evaluate association-overrides
     if (isset($xmlRoot->{'association-overrides'})) {
         foreach ($xmlRoot->{'association-overrides'}->{'association-override'} as $overrideElement) {
             $fieldName = (string) $overrideElement['name'];
             $override = array();
             // Check for join-columns
             if (isset($overrideElement->{'join-columns'})) {
                 $joinColumns = array();
                 foreach ($overrideElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                     $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
                 }
                 $override['joinColumns'] = $joinColumns;
             }
             // Check for join-table
             if ($overrideElement->{'join-table'}) {
                 $joinTable = null;
                 $joinTableElement = $overrideElement->{'join-table'};
                 $joinTable = array('name' => (string) $joinTableElement['name'], 'schema' => (string) $joinTableElement['schema']);
                 if (isset($joinTableElement->{'join-columns'})) {
                     foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                 }
                 if (isset($joinTableElement->{'inverse-join-columns'})) {
                     foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                 }
                 $override['joinTable'] = $joinTable;
             }
             $metadata->setAssociationOverride($fieldName, $override);
         }
     }
     // Evaluate <lifecycle-callbacks...>
     if (isset($xmlRoot->{'lifecycle-callbacks'})) {
         foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
             $metadata->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ORM\\Events::' . (string) $lifecycleCallback['type']));
         }
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:101,代码来源:XmlDriver.php

示例3: loadMetadataForClass


//.........这里部分代码省略.........
                                 $joinColumnElement['name'] = $joinColumnName;
                             }
                         }
                         $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                     $mapping['joinTable'] = $joinTable;
                 }
             }
             if (isset($manyToManyElement['inversedBy'])) {
                 $mapping['inversedBy'] = $manyToManyElement['inversedBy'];
             }
             if (isset($manyToManyElement['cascade'])) {
                 $mapping['cascade'] = $manyToManyElement['cascade'];
             }
             if (isset($manyToManyElement['orderBy'])) {
                 $mapping['orderBy'] = $manyToManyElement['orderBy'];
             }
             if (isset($manyToManyElement['indexBy'])) {
                 $mapping['indexBy'] = $manyToManyElement['indexBy'];
             }
             if (isset($manyToManyElement['orphanRemoval'])) {
                 $mapping['orphanRemoval'] = (bool) $manyToManyElement['orphanRemoval'];
             }
             $metadata->mapManyToMany($mapping);
             // Evaluate second level cache
             if (isset($manyToManyElement['cache'])) {
                 $metadata->enableAssociationCache($mapping['fieldName'], $this->cacheToArray($manyToManyElement['cache']));
             }
         }
     }
     // Evaluate associationOverride
     if (isset($element['associationOverride']) && is_array($element['associationOverride'])) {
         foreach ($element['associationOverride'] as $fieldName => $associationOverrideElement) {
             $override = array();
             // Check for joinColumn
             if (isset($associationOverrideElement['joinColumn'])) {
                 $joinColumns = array();
                 foreach ($associationOverrideElement['joinColumn'] as $name => $joinColumnElement) {
                     if (!isset($joinColumnElement['name'])) {
                         $joinColumnElement['name'] = $name;
                     }
                     $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
                 }
                 $override['joinColumns'] = $joinColumns;
             }
             // Check for joinTable
             if (isset($associationOverrideElement['joinTable'])) {
                 $joinTableElement = $associationOverrideElement['joinTable'];
                 $joinTable = array('name' => $joinTableElement['name']);
                 if (isset($joinTableElement['schema'])) {
                     $joinTable['schema'] = $joinTableElement['schema'];
                 }
                 foreach ($joinTableElement['joinColumns'] as $name => $joinColumnElement) {
                     if (!isset($joinColumnElement['name'])) {
                         $joinColumnElement['name'] = $name;
                     }
                     $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                 }
                 foreach ($joinTableElement['inverseJoinColumns'] as $name => $joinColumnElement) {
                     if (!isset($joinColumnElement['name'])) {
                         $joinColumnElement['name'] = $name;
                     }
                     $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                 }
                 $override['joinTable'] = $joinTable;
             }
             $metadata->setAssociationOverride($fieldName, $override);
         }
     }
     // Evaluate associationOverride
     if (isset($element['attributeOverride']) && is_array($element['attributeOverride'])) {
         foreach ($element['attributeOverride'] as $fieldName => $attributeOverrideElement) {
             $mapping = $this->columnToArray($fieldName, $attributeOverrideElement);
             $metadata->setAttributeOverride($fieldName, $mapping);
         }
     }
     // Evaluate lifeCycleCallbacks
     if (isset($element['lifecycleCallbacks'])) {
         foreach ($element['lifecycleCallbacks'] as $type => $methods) {
             foreach ($methods as $method) {
                 $metadata->addLifecycleCallback($method, constant('Doctrine\\ORM\\Events::' . $type));
             }
         }
     }
     // Evaluate entityListeners
     if (isset($element['entityListeners'])) {
         foreach ($element['entityListeners'] as $className => $entityListener) {
             // Evaluate the listener using naming convention.
             if (empty($entityListener)) {
                 EntityListenerBuilder::bindEntityListener($metadata, $className);
                 continue;
             }
             foreach ($entityListener as $eventName => $callbackElement) {
                 foreach ($callbackElement as $methodName) {
                     $metadata->addEntityListener($eventName, $className, $methodName);
                 }
             }
         }
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:101,代码来源:YamlDriver.php


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