/** * {@inheritdoc} */ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) { if (null === $this->mappingData) { $this->loadMappingData(); } $shortName = $this->getShortName($className); if (!isset($this->mappingData[$shortName])) { throw new MappingException(sprintf('No mapping found for class "%s".', $className)); } $mapping = array_merge(array('type' => 'entity', 'table' => $this->tableize($shortName), 'readOnly' => false, 'repositoryClass' => null), $this->mappingData[$shortName]); switch ($mapping['type']) { case 'entity': $metadata->setCustomRepositoryClass($mapping['repositoryClass']); if ($mapping['readOnly']) { $metadata->markReadOnly(); } break; case 'mappedSuperclass': $metadata->isMappedSuperclass = true; break; default: throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); } $metadata->setTableName($mapping['table']); // map fields foreach ($mapping['fields'] as $field => $fieldMapping) { $this->mapField($field, $fieldMapping, $metadata); } if (0 === count($metadata->getIdentifier())) { $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); } }
function it_checks_a_non_existent_mapping_relationship($classMetadata, ConfigurationInterface $configuration) { $configuration->getName()->willReturn('foo'); $classMetadata->getAssociationMapping('foo')->willThrow(MappingException::mappingNotFound('spec\\Pim\\Bundle\\ReferenceDataBundle\\RequirementChecker\\CustomValidProductValue', 'foo')); $this->check($configuration)->shouldReturn(false); $this->getFailure()->shouldReturn("No mapping found for field 'foo' on class " . "'spec\\Pim\\Bundle\\ReferenceDataBundle\\RequirementChecker\\CustomValidProductValue'."); }
/** * {@inheritDoc} * @todo Same code exists in AnnotationDriver, should we re-use it somehow or not worry about it? */ public function getAllClassNames() { if ($this->_classNames !== null) { return $this->_classNames; } if (!$this->_paths) { throw MappingException::pathRequired(); } $classes = array(); $includedFiles = array(); foreach ($this->_paths as $path) { if (!is_dir($path)) { throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::LEAVES_ONLY); foreach ($iterator as $file) { if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) { continue; } $sourceFile = realpath($file->getPathName()); require_once $sourceFile; $includedFiles[] = $sourceFile; } } $declared = get_declared_classes(); foreach ($declared as $className) { $rc = new \ReflectionClass($className); $sourceFile = $rc->getFileName(); if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) { $classes[] = $className; } } $this->_classNames = $classes; return $classes; }
/** * Get all class names. * * @return string[] */ public function getAllClassNames() { if (!$this->paths) { throw MappingException::pathRequired(); } $classes = []; $includedFiles = []; foreach ($this->paths as $path) { if (!is_dir($path)) { throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); } $iterator = new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY), '/^.+\\/Entity\\/.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH); foreach ($iterator as $file) { $sourceFile = realpath($file[0]); require_once $sourceFile; $includedFiles[] = $sourceFile; } } $declared = get_declared_classes(); foreach ($declared as $className) { $rc = new \ReflectionClass($className); $sourceFile = $rc->getFileName(); if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) { $classes[] = $className; } } return $classes; }
/** * Gets the metadata of a class. * * @param string $class A class name * @param string $path The path where the class is stored (if known) * * @return ClassMetadataCollection A ClassMetadataCollection instance */ public function getClassMetadata($class, $path = null) { $metadata = $this->getMetadataForClass($class); if (!$metadata->getMetadata()) { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($class); } $this->findNamespaceAndPathForMetadata($metadata); return $metadata; }
/** * Loads the metadata for the specified class into the provided container. * * @param string $className * @param ClassMetadataInfo $metadata */ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) { foreach ($this->_drivers as $namespace => $driver) { if (strpos($className, $namespace) === 0) { $driver->loadMetadataForClass($className, $metadata); return; } } throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); }
/** * {@inheritDoc} */ public function findMappingFile($className) { if (!$this->fileExists($className)) { throw MappingException::mappingFileNotFound($className, $this->paths[0]); } if (isset(self::$pathsMap[$className])) { $this->paths = self::$pathsMap[$className]; } return $this->paths[0]; }
/** * Lookup the entity class to find methods that match to event lifecycle names * * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata The entity metadata. * @param string $className The listener class name. * * @throws \Doctrine\ORM\Mapping\MappingException When the listener class not found. */ public static function bindEntityListener(ClassMetadata $metadata, $className) { $class = $metadata->fullyQualifiedClassName($className); if (!class_exists($class)) { throw MappingException::entityListenerClassNotFound($class, $className); } foreach (get_class_methods($class) as $method) { if (!isset(self::$events[$method])) { continue; } $metadata->addEntityListener($method, $class, $method); } }
protected function _findMappingFile($className) { foreach ($this->_paths as $prefix => $path) { if (0 !== strpos($className, $prefix . '\\')) { continue; } $filename = $path . '/' . strtr(substr($className, strlen($prefix) + 1), '\\', '.') . $this->_fileExtension; if (file_exists($filename)) { return $filename; } throw MappingException::mappingFileNotFound($className, $filename); } throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\') + 1) . $this->_fileExtension); }
/** * Gets the metadata of a class. * * @param string $class A class name * @param string $path The path where the class is stored (if known) * * @return ClassMetadataCollection A ClassMetadataCollection instance */ public function getClassMetadata($class, $path = null) { $metadata = $this->getMetadataForClass($class); if (!$metadata->getMetadata()) { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($class); } $all = $metadata->getMetadata(); if (class_exists($class)) { $r = $all[0]->getReflectionClass(); $path = $this->getBasePathForClass($class, $r->getNamespacename(), dirname($r->getFilename())); } elseif (!$path) { throw new \RuntimeException(sprintf('Unable to determine where to save the "%s" class (use the --path option).', $class)); } $metadata->setPath($path); $metadata->setNamespace($r->getNamespacename()); return $metadata; }
/** * Sets the version field mapping used for versioning. Sets the default * value to use depending on the column type. * * @param array $mapping The version field mapping array * @throws MappingException * @return void */ public function setVersionMapping(array &$mapping) { $this->isVersioned = true; $this->versionField = $mapping['fieldName']; if (!isset($mapping['default'])) { if (in_array($mapping['type'], array('integer', 'bigint', 'smallint'))) { $mapping['default'] = 1; } else { if ($mapping['type'] == 'datetime') { $mapping['default'] = 'CURRENT_TIMESTAMP'; } else { throw MappingException::unsupportedOptimisticLockingType($this->name, $mapping['fieldName'], $mapping['type']); } } } }
/** * @param array $assoc * @param object $sourceEntity * @param int|null $offset * @param int|null $limit * * @return \Doctrine\DBAL\Driver\Statement * * @throws \Doctrine\ORM\Mapping\MappingException */ private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); $class = $sourceClass; $association = $assoc; $criteria = array(); if ( ! $assoc['isOwningSide']) { $class = $this->em->getClassMetadata($assoc['targetEntity']); $association = $class->associationMappings[$assoc['mappedBy']]; } $joinColumns = $assoc['isOwningSide'] ? $association['joinTable']['joinColumns'] : $association['joinTable']['inverseJoinColumns']; $quotedJoinTable = $this->quoteStrategy->getJoinTableName($association, $class, $this->platform); foreach ($joinColumns as $joinColumn) { $sourceKeyColumn = $joinColumn['referencedColumnName']; $quotedKeyColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); switch (true) { case $sourceClass->containsForeignIdentifier: $field = $sourceClass->getFieldForColumn($sourceKeyColumn); $value = $sourceClass->reflFields[$field]->getValue($sourceEntity); if (isset($sourceClass->associationMappings[$field])) { $value = $this->em->getUnitOfWork()->getEntityIdentifier($value); $value = $value[$this->em->getClassMetadata($sourceClass->associationMappings[$field]['targetEntity'])->identifier[0]]; } break; case isset($sourceClass->fieldNames[$sourceKeyColumn]): $field = $sourceClass->fieldNames[$sourceKeyColumn]; $value = $sourceClass->reflFields[$field]->getValue($sourceEntity); break; default: throw MappingException::joinColumnMustPointToMappedField( $sourceClass->name, $sourceKeyColumn ); } $criteria[$quotedJoinTable . '.' . $quotedKeyColumn] = $value; } $sql = $this->getSelectSQL($criteria, $assoc, 0, $limit, $offset); list($params, $types) = $this->expandParameters($criteria); return $this->conn->executeQuery($sql, $params, $types); }
/** * {@inheritDoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */ /* @var $xmlRoot SimpleXMLElement */ $xmlRoot = $this->getElement($className); if ($xmlRoot->getName() == 'entity') { if (isset($xmlRoot['repository-class'])) { $metadata->setCustomRepositoryClass((string) $xmlRoot['repository-class']); } if (isset($xmlRoot['read-only']) && $this->evaluateBoolean($xmlRoot['read-only'])) { $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'])); } } // Evaluate native named queries if (isset($xmlRoot->{'named-native-queries'})) { foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} as $nativeQueryElement) { $metadata->addNamedNativeQuery(array('name' => isset($nativeQueryElement['name']) ? (string) $nativeQueryElement['name'] : null, 'query' => isset($nativeQueryElement->query) ? (string) $nativeQueryElement->query : null, 'resultClass' => isset($nativeQueryElement['result-class']) ? (string) $nativeQueryElement['result-class'] : null, 'resultSetMapping' => isset($nativeQueryElement['result-set-mapping']) ? (string) $nativeQueryElement['result-set-mapping'] : null)); } } // Evaluate sql result set mapping if (isset($xmlRoot->{'sql-result-set-mappings'})) { foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} as $rsmElement) { $entities = array(); $columns = array(); foreach ($rsmElement as $entityElement) { //<entity-result/> if (isset($entityElement['entity-class'])) { $entityResult = array('fields' => array(), 'entityClass' => (string) $entityElement['entity-class'], 'discriminatorColumn' => isset($entityElement['discriminator-column']) ? (string) $entityElement['discriminator-column'] : null); foreach ($entityElement as $fieldElement) { $entityResult['fields'][] = array('name' => isset($fieldElement['name']) ? (string) $fieldElement['name'] : null, 'column' => isset($fieldElement['column']) ? (string) $fieldElement['column'] : null); } $entities[] = $entityResult; } //<column-result/> if (isset($entityElement['name'])) { $columns[] = array('name' => (string) $entityElement['name']); } } $metadata->addSqlResultSetMapping(array('name' => (string) $rsmElement['name'], 'entities' => $entities, 'columns' => $columns)); } } /* 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()); } // The mapping assignement is done in 2 times as a bug might occurs on some php/xml lib versions // The internal SimpleXmlIterator get resetted, to this generate a duplicate field exception $mappings = array(); // Evaluate <field ...> mappings if (isset($xmlRoot->field)) { foreach ($xmlRoot->field as $fieldMapping) { $mapping = $this->columnToArray($fieldMapping); if (isset($mapping['version'])) { $metadata->setVersionMapping($mapping); unset($mapping['version']); } $metadata->mapField($mapping); } } foreach ($mappings as $mapping) { if (isset($mapping['version'])) { $metadata->setVersionMapping($mapping); } $metadata->mapField($mapping); } // Evaluate <id ...> mappings $associationIds = array(); foreach ($xmlRoot->id as $idElement) { if (isset($idElement['association-key']) && $this->evaluateBoolean($idElement['association-key'])) { $associationIds[(string) $idElement['name']] = true; continue; } $mapping = array('id' => true, 'fieldName' => (string) $idElement['name']); if (isset($idElement['type'])) { $mapping['type'] = (string) $idElement['type']; } if (isset($idElement['length'])) { $mapping['length'] = (string) $idElement['length']; } if (isset($idElement['column'])) { $mapping['columnName'] = (string) $idElement['column']; } if (isset($idElement['column-definition'])) { $mapping['columnDefinition'] = (string) $idElement['column-definition']; } $metadata->mapField($mapping); if (isset($idElement->generator)) { $strategy = isset($idElement->generator['strategy']) ? (string) $idElement->generator['strategy'] : 'AUTO'; $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $strategy)); } // Check for SequenceGenerator/TableGenerator definition if (isset($idElement->{'sequence-generator'})) { $seqGenerator = $idElement->{'sequence-generator'}; $metadata->setSequenceGeneratorDefinition(array('sequenceName' => (string) $seqGenerator['sequence-name'], 'allocationSize' => (string) $seqGenerator['allocation-size'], 'initialValue' => (string) $seqGenerator['initial-value'])); } else { if (isset($idElement->{'custom-id-generator'})) { $customGenerator = $idElement->{'custom-id-generator'}; $metadata->setCustomGeneratorDefinition(array('class' => (string) $customGenerator['class'])); } else { if (isset($idElement->{'table-generator'})) { throw MappingException::tableIdGeneratorNotImplemented($className); } } } } // Evaluate <one-to-one ...> mappings if (isset($xmlRoot->{'one-to-one'})) { foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) { $mapping = array('fieldName' => (string) $oneToOneElement['field'], 'targetEntity' => (string) $oneToOneElement['target-entity']); if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; } if (isset($oneToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $oneToOneElement['fetch']); } if (isset($oneToOneElement['mapped-by'])) { $mapping['mappedBy'] = (string) $oneToOneElement['mapped-by']; } else { if (isset($oneToOneElement['inversed-by'])) { $mapping['inversedBy'] = (string) $oneToOneElement['inversed-by']; } $joinColumns = array(); if (isset($oneToOneElement->{'join-column'})) { $joinColumns[] = $this->joinColumnToArray($oneToOneElement->{'join-column'}); } else { if (isset($oneToOneElement->{'join-columns'})) { foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { $joinColumns[] = $this->joinColumnToArray($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; } if (isset($oneToOneElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade); } if (isset($oneToOneElement['orphan-removal'])) { $mapping['orphanRemoval'] = $this->evaluateBoolean($oneToOneElement['orphan-removal']); } $metadata->mapOneToOne($mapping); } } // Evaluate <one-to-many ...> mappings if (isset($xmlRoot->{'one-to-many'})) { foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) { $mapping = array('fieldName' => (string) $oneToManyElement['field'], 'targetEntity' => (string) $oneToManyElement['target-entity'], 'mappedBy' => (string) $oneToManyElement['mapped-by']); if (isset($oneToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $oneToManyElement['fetch']); } if (isset($oneToManyElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade); } if (isset($oneToManyElement['orphan-removal'])) { $mapping['orphanRemoval'] = $this->evaluateBoolean($oneToManyElement['orphan-removal']); } if (isset($oneToManyElement->{'order-by'})) { $orderBy = array(); foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction']; } $mapping['orderBy'] = $orderBy; } if (isset($oneToManyElement['index-by'])) { $mapping['indexBy'] = (string) $oneToManyElement['index-by']; } else { if (isset($oneToManyElement->{'index-by'})) { throw new \InvalidArgumentException("<index-by /> is not a valid tag"); } } $metadata->mapOneToMany($mapping); } } // Evaluate <many-to-one ...> mappings if (isset($xmlRoot->{'many-to-one'})) { foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) { $mapping = array('fieldName' => (string) $manyToOneElement['field'], 'targetEntity' => (string) $manyToOneElement['target-entity']); if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; } if (isset($manyToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $manyToOneElement['fetch']); } if (isset($manyToOneElement['inversed-by'])) { $mapping['inversedBy'] = (string) $manyToOneElement['inversed-by']; } $joinColumns = array(); if (isset($manyToOneElement->{'join-column'})) { $joinColumns[] = $this->joinColumnToArray($manyToOneElement->{'join-column'}); } else { if (isset($manyToOneElement->{'join-columns'})) { foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { $joinColumns[] = $this->joinColumnToArray($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; if (isset($manyToOneElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade); } $metadata->mapManyToOne($mapping); } } // Evaluate <many-to-many ...> mappings if (isset($xmlRoot->{'many-to-many'})) { 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'])); } } }
/** * {@inheritDoc} */ public function getAllClassNames() { $classes = array(); if ($this->_paths) { $declared = get_declared_classes(); foreach ((array) $this->_paths as $path) { if (!is_dir($path)) { throw MappingException::annotationDriverRequiresConfiguredDirectoryPath(); } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::LEAVES_ONLY); foreach ($iterator as $file) { if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) { continue; } require_once $file->getPathName(); } } $declared = array_diff(get_declared_classes(), $declared); foreach ($declared as $className) { if (!$this->isTransient($className)) { $classes[] = $className; } } } return $classes; }
/** * @param string $callback * @param string $event */ public function addLifecycleCallback($callback, $event) { if (!$this->reflClass->hasMethod($callback) || ($this->reflClass->getMethod($callback)->getModifiers() & \ReflectionMethod::IS_PUBLIC) == 0) { throw MappingException::lifecycleCallbackMethodNotFound($this->name, $callback); } return parent::addLifecycleCallback($callback, $event); }
/** * Adds inherited association mappings to the subclass mapping. * * @param \Doctrine\ORM\Mapping\ClassMetadata $subClass * @param \Doctrine\ORM\Mapping\ClassMetadata $parentClass * * @return void * * @throws MappingException */ private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass) { foreach ($parentClass->associationMappings as $field => $mapping) { if ($parentClass->isMappedSuperclass) { if ($mapping['type'] & ClassMetadata::TO_MANY && !$mapping['isOwningSide']) { throw MappingException::illegalToManyAssociationOnMappedSuperclass($parentClass->name, $field); } $mapping['sourceEntity'] = $subClass->name; } //$subclassMapping = $mapping; if (!isset($mapping['inherited']) && !$parentClass->isMappedSuperclass) { $mapping['inherited'] = $parentClass->name; } if (!isset($mapping['declared'])) { $mapping['declared'] = $parentClass->name; } $subClass->addInheritedAssociationMapping($mapping); } }
/** * {@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']; } $metadata->mapField($mapping); if (isset($idElement->generator)) { $strategy = isset($idElement->generator['strategy']) ? (string) $idElement->generator['strategy'] : 'AUTO'; $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $strategy)); } // Check for SequenceGenerator/TableGenerator definition if (isset($idElement->{'sequence-generator'})) { $seqGenerator = $idElement->{'sequence-generator'}; $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGenerator->{'sequence-name'}, 'allocationSize' => $seqGenerator->{'allocation-size'}, 'initialValue' => $seqGeneratorAnnot->{'initial-value'})); } else { if (isset($idElement->{'table-generator'})) { throw MappingException::tableIdGeneratorNotImplemented($className); } } } // Evaluate <one-to-one ...> mappings if (isset($xmlRoot->{'one-to-one'})) { foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) { $mapping = array('fieldName' => (string) $oneToOneElement['field'], 'targetEntity' => (string) $oneToOneElement['target-entity']); if (isset($oneToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . (string) $oneToOneElement['fetch']); } if (isset($oneToOneElement['mapped-by'])) { $mapping['mappedBy'] = (string) $oneToOneElement['mapped-by']; } else { $joinColumns = array(); if (isset($oneToOneElement->{'join-column'})) { $joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement->{'join-column'}); } else { if (isset($oneToOneElement->{'join-columns'})) { foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; } if (isset($oneToOneElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade); } if (isset($oneToOneElement->{'orphan-removal'})) { $mapping['orphanRemoval'] = (bool) $oneToOneElement->{'orphan-removal'}; } $metadata->mapOneToOne($mapping); } } // Evaluate <one-to-many ...> mappings if (isset($xmlRoot->{'one-to-many'})) { foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) { $mapping = array('fieldName' => (string) $oneToManyElement['field'], 'targetEntity' => (string) $oneToManyElement['target-entity'], 'mappedBy' => (string) $oneToManyElement['mapped-by']); if (isset($oneToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . (string) $oneToManyElement['fetch']); } if (isset($oneToManyElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade); } if (isset($oneToManyElement->{'orphan-removal'})) { $mapping['orphanRemoval'] = (bool) $oneToManyElement->{'orphan-removal'}; } $metadata->mapOneToMany($mapping); } } // Evaluate <many-to-one ...> mappings if (isset($xmlRoot->{'many-to-one'})) { foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) { $mapping = array('fieldName' => (string) $manyToOneElement['field'], 'targetEntity' => (string) $manyToOneElement['target-entity']); if (isset($manyToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . (string) $manyToOneElement['fetch']); } $joinColumns = array(); if (isset($manyToOneElement->{'join-column'})) { $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'}); } else { if (isset($manyToOneElement->{'join-columns'})) { foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { if (!isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $name; } $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; if (isset($manyToOneElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade); } if (isset($manyToOneElement->{'orphan-removal'})) { $mapping['orphanRemoval'] = (bool) $manyToOneElement->{'orphan-removal'}; } $metadata->mapManyToOne($mapping); } } // Evaluate <many-to-many ...> mappings if (isset($xmlRoot->{'many-to-many'})) { 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\\AssociationMapping::FETCH_' . (string) $manyToManyElement['fetch']); } if (isset($manyToManyElement['mapped-by'])) { $mapping['mappedBy'] = (string) $manyToManyElement['mapped-by']; } else { if (isset($manyToManyElement->{'join-table'})) { $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->_getJoinColumnMapping($joinColumnElement); } foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) { $joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement); } $mapping['joinTable'] = $joinTable; } } if (isset($manyToManyElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($manyToManyElement->cascade); } if (isset($manyToManyElement->{'orphan-removal'})) { $mapping['orphanRemoval'] = (bool) $manyToManyElement->{'orphan-removal'}; } $metadata->mapManyToMany($mapping); } } // 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'])); } } }
/** * Loads the metadata of the class in question and all it's ancestors whose metadata * is still not loaded. * * @param string $name The name of the class for which the metadata should get loaded. * @param array $tables The metadata collection to which the loaded metadata is added. */ protected function loadMetadata($name) { if (!$this->initialized) { $this->initialize(); } $loaded = array(); $parentClasses = $this->getParentClasses($name); $parentClasses[] = $name; // Move down the hierarchy of parent classes, starting from the topmost class $parent = null; $visited = array(); foreach ($parentClasses as $className) { if (isset($this->loadedMetadata[$className])) { $parent = $this->loadedMetadata[$className]; if (!$parent->isMappedSuperclass) { array_unshift($visited, $className); } continue; } $class = $this->newClassMetadataInstance($className); if ($parent) { $class->setInheritanceType($parent->inheritanceType); $class->setDiscriminatorColumn($parent->discriminatorColumn); $class->setIdGeneratorType($parent->generatorType); $this->addInheritedFields($class, $parent); $this->addInheritedRelations($class, $parent); $class->setIdentifier($parent->identifier); $class->setVersioned($parent->isVersioned); $class->setVersionField($parent->versionField); $class->setDiscriminatorMap($parent->discriminatorMap); $class->setLifecycleCallbacks($parent->lifecycleCallbacks); $class->setChangeTrackingPolicy($parent->changeTrackingPolicy); } // Invoke driver try { $this->driver->loadMetadataForClass($className, $class); } catch (ReflectionException $e) { throw MappingException::reflectionFailure($className, $e); } // Verify & complete identifier mapping if (!$class->identifier && !$class->isMappedSuperclass) { throw MappingException::identifierRequired($className); } if ($parent && !$parent->isMappedSuperclass) { if ($parent->isIdGeneratorSequence()) { $class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition); } else { if ($parent->isIdGeneratorTable()) { $class->getTableGeneratorDefinition($parent->tableGeneratorDefinition); } } if ($parent->generatorType) { $class->setIdGeneratorType($parent->generatorType); } if ($parent->idGenerator) { $class->setIdGenerator($parent->idGenerator); } } else { $this->completeIdGeneratorMapping($class); } if ($parent && $parent->isInheritanceTypeSingleTable()) { $class->setPrimaryTable($parent->table); } $class->setParentClasses($visited); if ($this->evm->hasListeners(Events::loadClassMetadata)) { $eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($class); $this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs); } // verify inheritance if (!$parent && !$class->isMappedSuperclass && !$class->isInheritanceTypeNone()) { if (count($class->discriminatorMap) == 0) { throw MappingException::missingDiscriminatorMap($class->name); } if (!$class->discriminatorColumn) { throw MappingException::missingDiscriminatorColumn($class->name); } } $this->loadedMetadata[$className] = $class; $parent = $class; if (!$class->isMappedSuperclass) { array_unshift($visited, $className); } $loaded[] = $className; } return $loaded; }
/** * Whether the class with the specified name should have its metadata loaded. * This is only the case if it is either mapped as an Entity or a * MappedSuperclass. * * @param string $className * @return boolean */ public function isTransient($className) { foreach ($this->_drivers as $namespace => $driver) { if (strpos($className, $namespace) === 0) { return $driver->isTransient($className); } } throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); }
protected function _findMappingFile($className) { $defaultFileName = str_replace('\\', '.', $className) . $this->_fileExtension; foreach ($this->_paths as $path) { if (!isset($this->_prefixes[$path])) { if (file_exists($path . DIRECTORY_SEPARATOR . $defaultFileName)) { return $path . DIRECTORY_SEPARATOR . $defaultFileName; } continue; } $prefix = $this->_prefixes[$path]; if (0 !== strpos($className, $prefix.'\\')) { continue; } $filename = $path.'/'.strtr(substr($className, strlen($prefix)+1), '\\', '.').$this->_fileExtension; if (file_exists($filename)) { return $filename; } throw MappingException::mappingFileNotFound($className, $filename); } throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\') + 1).$this->_fileExtension); }
/** * Attempts to resolve the fetch mode. * * @param string $className The class name * @param string $fetchMode The fetch mode * @return integer The fetch mode as defined in ClassMetadata * @throws MappingException If the fetch mode is not valid */ private function getFetchMode($className, $fetchMode) { if (!defined('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $fetchMode)) { throw MappingException::invalidFetchMode($className, $fetchMode); } return constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $fetchMode); }
/** * Stores the association mapping. * * @param AssociationMapping $assocMapping */ private function _storeAssociationMapping(AssociationMapping $assocMapping) { $sourceFieldName = $assocMapping->getSourceFieldName(); if (isset($this->associationMappings[$sourceFieldName])) { throw MappingException::duplicateFieldMapping(); } $this->associationMappings[$sourceFieldName] = $assocMapping; $this->_registerMappingIfInverse($assocMapping); // Store ReflectionProperty of mapped field $refProp = $this->reflClass->getProperty($sourceFieldName); $refProp->setAccessible(true); $this->reflFields[$sourceFieldName] = $refProp; }
/** * Loads a collection of entities of a many-to-many association. * * @param ManyToManyMapping $assoc The association mapping of the association being loaded. * @param object $sourceEntity The entity that owns the collection. * @param PersistentCollection $coll The collection to fill. */ public function loadManyToManyCollection(array $assoc, $sourceEntity, PersistentCollection $coll) { $criteria = array(); $sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']); $joinTableConditions = array(); if ($assoc['isOwningSide']) { foreach ($assoc['relationToSourceKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) { if (isset($sourceClass->fieldNames[$sourceKeyColumn])) { $criteria[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); } else { throw MappingException::joinColumnMustPointToMappedField($sourceClass->name, $sourceKeyColumn); } } } else { $owningAssoc = $this->_em->getClassMetadata($assoc['targetEntity'])->associationMappings[$assoc['mappedBy']]; // TRICKY: since the association is inverted source and target are flipped foreach ($owningAssoc['relationToTargetKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) { if (isset($sourceClass->fieldNames[$sourceKeyColumn])) { $criteria[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); } else { throw MappingException::joinColumnMustPointToMappedField($sourceClass->name, $sourceKeyColumn); } } } $sql = $this->_getSelectEntitiesSQL($criteria, $assoc); $stmt = $this->_conn->executeQuery($sql, array_values($criteria)); while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { $coll->hydrateAdd($this->_createEntity($result)); } $stmt->closeCursor(); }
/** * Finds the mapping file for the class with the given name by searching * through the configured paths. * * @param $className * @return string The (absolute) file name. * @throws MappingException */ protected function _findMappingFile($className) { $fileName = str_replace('\\', '.', $className) . $this->_fileExtension; // Check whether file exists foreach ((array) $this->_paths as $path) { if (file_exists($path . DIRECTORY_SEPARATOR . $fileName)) { return $path . DIRECTORY_SEPARATOR . $fileName; } } throw MappingException::mappingFileNotFound($className, $fileName); }
/** * {@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); if (isset($idElement['type'])) { $mapping['type'] = $idElement['type']; } if (isset($idElement['column'])) { $mapping['columnName'] = $idElement['column']; } if (isset($idElement['length'])) { $mapping['length'] = $idElement['length']; } if (isset($idElement['columnDefinition'])) { $mapping['columnDefinition'] = $idElement['columnDefinition']; } $metadata->mapField($mapping); if (isset($idElement['generator'])) { $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($idElement['generator']['strategy']))); } // Check for SequenceGenerator/TableGenerator definition if (isset($idElement['sequenceGenerator'])) { $metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']); } else { if (isset($idElement['tableGenerator'])) { throw MappingException::tableIdGeneratorNotImplemented($className); } } } } // Evaluate fields if (isset($element['fields'])) { foreach ($element['fields'] as $name => $fieldMapping) { $mapping = array('fieldName' => $name); if (isset($fieldMapping['type'])) { $e = explode('(', $fieldMapping['type']); $fieldMapping['type'] = $e[0]; $mapping['type'] = $fieldMapping['type']; if (isset($e[1])) { $fieldMapping['length'] = substr($e[1], 0, strlen($e[1]) - 1); } } if (isset($fieldMapping['id'])) { $mapping['id'] = true; if (isset($fieldMapping['generator']['strategy'])) { $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($fieldMapping['generator']['strategy']))); } } if (isset($fieldMapping['column'])) { $mapping['columnName'] = $fieldMapping['column']; } if (isset($fieldMapping['length'])) { $mapping['length'] = $fieldMapping['length']; } if (isset($fieldMapping['precision'])) { $mapping['precision'] = $fieldMapping['precision']; } if (isset($fieldMapping['scale'])) { $mapping['scale'] = $fieldMapping['scale']; } if (isset($fieldMapping['unique'])) { $mapping['unique'] = (bool) $fieldMapping['unique']; } if (isset($fieldMapping['options'])) { $mapping['options'] = $fieldMapping['options']; } if (isset($fieldMapping['nullable'])) { $mapping['nullable'] = $fieldMapping['nullable']; } if (isset($fieldMapping['version']) && $fieldMapping['version']) { $metadata->setVersionMapping($mapping); } if (isset($fieldMapping['columnDefinition'])) { $mapping['columnDefinition'] = $fieldMapping['columnDefinition']; } $metadata->mapField($mapping); } } // Evaluate oneToOne relationships if (isset($element['oneToOne'])) { foreach ($element['oneToOne'] as $name => $oneToOneElement) { $mapping = array('fieldName' => $name, 'targetEntity' => $oneToOneElement['targetEntity']); if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; } if (isset($oneToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToOneElement['fetch']); } if (isset($oneToOneElement['mappedBy'])) { $mapping['mappedBy'] = $oneToOneElement['mappedBy']; } else { if (isset($oneToOneElement['inversedBy'])) { $mapping['inversedBy'] = $oneToOneElement['inversedBy']; } $joinColumns = array(); if (isset($oneToOneElement['joinColumn'])) { $joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement['joinColumn']); } else { if (isset($oneToOneElement['joinColumns'])) { foreach ($oneToOneElement['joinColumns'] as $name => $joinColumnElement) { if (!isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $name; } $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; } if (isset($oneToOneElement['cascade'])) { $mapping['cascade'] = $oneToOneElement['cascade']; } if (isset($oneToOneElement['orphanRemoval'])) { $mapping['orphanRemoval'] = (bool) $oneToOneElement['orphanRemoval']; } $metadata->mapOneToOne($mapping); } } // Evaluate oneToMany relationships if (isset($element['oneToMany'])) { foreach ($element['oneToMany'] as $name => $oneToManyElement) { $mapping = array('fieldName' => $name, 'targetEntity' => $oneToManyElement['targetEntity'], 'mappedBy' => $oneToManyElement['mappedBy']); if (isset($oneToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToManyElement['fetch']); } if (isset($oneToManyElement['cascade'])) { $mapping['cascade'] = $oneToManyElement['cascade']; } if (isset($oneToManyElement['orphanRemoval'])) { $mapping['orphanRemoval'] = (bool) $oneToManyElement['orphanRemoval']; } if (isset($oneToManyElement['orderBy'])) { $mapping['orderBy'] = $oneToManyElement['orderBy']; } if (isset($oneToManyElement['indexBy'])) { $mapping['indexBy'] = $oneToManyElement['indexBy']; } $metadata->mapOneToMany($mapping); } } // Evaluate manyToOne relationships if (isset($element['manyToOne'])) { foreach ($element['manyToOne'] as $name => $manyToOneElement) { $mapping = array('fieldName' => $name, 'targetEntity' => $manyToOneElement['targetEntity']); if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; } if (isset($manyToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $manyToOneElement['fetch']); } if (isset($manyToOneElement['inversedBy'])) { $mapping['inversedBy'] = $manyToOneElement['inversedBy']; } $joinColumns = array(); if (isset($manyToOneElement['joinColumn'])) { $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement['joinColumn']); } else { if (isset($manyToOneElement['joinColumns'])) { foreach ($manyToOneElement['joinColumns'] as $name => $joinColumnElement) { if (!isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $name; } $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; if (isset($manyToOneElement['cascade'])) { $mapping['cascade'] = $manyToOneElement['cascade']; } $metadata->mapManyToOne($mapping); } } // Evaluate manyToMany relationships if (isset($element['manyToMany'])) { foreach ($element['manyToMany'] as $name => $manyToManyElement) { $mapping = array('fieldName' => $name, 'targetEntity' => $manyToManyElement['targetEntity']); if (isset($manyToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $manyToManyElement['fetch']); } if (isset($manyToManyElement['mappedBy'])) { $mapping['mappedBy'] = $manyToManyElement['mappedBy']; } else { if (isset($manyToManyElement['joinTable'])) { if (isset($manyToManyElement['inversedBy'])) { $mapping['inversedBy'] = $manyToManyElement['inversedBy']; } $joinTableElement = $manyToManyElement['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->_getJoinColumnMapping($joinColumnElement); } foreach ($joinTableElement['inverseJoinColumns'] as $name => $joinColumnElement) { if (!isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $name; } $joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement); } $mapping['joinTable'] = $joinTable; } } if (isset($manyToManyElement['cascade'])) { $mapping['cascade'] = $manyToManyElement['cascade']; } if (isset($manyToManyElement['orderBy'])) { $mapping['orderBy'] = $manyToManyElement['orderBy']; } if (isset($manyToManyElement['indexBy'])) { $mapping['indexBy'] = $manyToManyElement['indexBy']; } $metadata->mapManyToMany($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)); } } } }
/** * @param string $fieldName * @throws MappingException */ private function assertFieldNotMapped($fieldName) { if (isset($this->fieldMappings[$fieldName]) || isset($this->associationMappings[$fieldName]) || isset($this->embeddedClasses[$fieldName])) { throw MappingException::duplicateFieldMapping($this->name, $fieldName); } }
private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { $criteria = array(); $sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']); if ($assoc['isOwningSide']) { $quotedJoinTable = $sourceClass->getQuotedJoinTableName($assoc, $this->_platform); foreach ($assoc['relationToSourceKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) { if ($sourceClass->containsForeignIdentifier) { $field = $sourceClass->getFieldForColumn($sourceKeyColumn); $value = $sourceClass->reflFields[$field]->getValue($sourceEntity); if (isset($sourceClass->associationMappings[$field])) { $value = $this->_em->getUnitOfWork()->getEntityIdentifier($value); $value = $value[$this->_em->getClassMetadata($sourceClass->associationMappings[$field]['targetEntity'])->identifier[0]]; } $criteria[$quotedJoinTable . "." . $relationKeyColumn] = $value; } else { if (isset($sourceClass->fieldNames[$sourceKeyColumn])) { $criteria[$quotedJoinTable . "." . $relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); } else { throw MappingException::joinColumnMustPointToMappedField($sourceClass->name, $sourceKeyColumn); } } } } else { $owningAssoc = $this->_em->getClassMetadata($assoc['targetEntity'])->associationMappings[$assoc['mappedBy']]; $quotedJoinTable = $sourceClass->getQuotedJoinTableName($owningAssoc, $this->_platform); // TRICKY: since the association is inverted source and target are flipped foreach ($owningAssoc['relationToTargetKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) { if ($sourceClass->containsForeignIdentifier) { $field = $sourceClass->getFieldForColumn($sourceKeyColumn); $value = $sourceClass->reflFields[$field]->getValue($sourceEntity); if (isset($sourceClass->associationMappings[$field])) { $value = $this->_em->getUnitOfWork()->getEntityIdentifier($value); $value = $value[$this->_em->getClassMetadata($sourceClass->associationMappings[$field]['targetEntity'])->identifier[0]]; } $criteria[$quotedJoinTable . "." . $relationKeyColumn] = $value; } else { if (isset($sourceClass->fieldNames[$sourceKeyColumn])) { $criteria[$quotedJoinTable . "." . $relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); } else { throw MappingException::joinColumnMustPointToMappedField($sourceClass->name, $sourceKeyColumn); } } } } $sql = $this->_getSelectEntitiesSQL($criteria, $assoc, 0, $limit, $offset); list($params, $types) = $this->expandParameters($criteria); return $this->_conn->executeQuery($sql, $params, $types); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function initialize($metadata) { $dict1GrpCfg = $this->createEntityConfig('grouping', 'Acme\\TestBundle\\Entity\\Dictionary1', ['groups' => [GroupingScope::GROUP_DICTIONARY]]); $dict1Cfg = $this->createEntityConfig('dictionary', 'Acme\\TestBundle\\Entity\\Dictionary1', ['virtual_fields' => ['name']]); $dict2GrpCfg = $this->createEntityConfig('grouping', 'Acme\\TestBundle\\Entity\\Dictionary2', ['groups' => [GroupingScope::GROUP_DICTIONARY]]); $dict2Cfg = $this->createEntityConfig('dictionary', 'Acme\\TestBundle\\Entity\\Dictionary2', ['virtual_fields' => ['id', 'name']]); $dict3GrpCfg = $this->createEntityConfig('grouping', 'Acme\\TestBundle\\Entity\\Dictionary3', ['groups' => [GroupingScope::GROUP_DICTIONARY]]); $dict3Cfg = $this->createEntityConfig('dictionary', 'Acme\\TestBundle\\Entity\\Dictionary3'); $dict4GrpCfg = $this->createEntityConfig('grouping', 'Acme\\TestBundle\\Entity\\Dictionary4', ['groups' => [GroupingScope::GROUP_DICTIONARY]]); $dict4Cfg = $this->createEntityConfig('dictionary', 'Acme\\TestBundle\\Entity\\Dictionary4'); $this->groupingConfigProvider->expects($this->any())->method('getConfigs')->will($this->returnValue([$dict1GrpCfg, $dict2GrpCfg, $dict3GrpCfg, $dict4GrpCfg])); $this->dictionaryConfigProvider->expects($this->any())->method('hasConfig')->will($this->returnCallback(function ($className, $fieldName) { return in_array($className, ['Acme\\TestBundle\\Entity\\Dictionary1', 'Acme\\TestBundle\\Entity\\Dictionary2', 'Acme\\TestBundle\\Entity\\Dictionary3', 'Acme\\TestBundle\\Entity\\Dictionary4']); })); $this->dictionaryConfigProvider->expects($this->any())->method('getConfig')->will($this->returnCallback(function ($className, $fieldName) use(&$dict1Cfg, &$dict2Cfg, &$dict3Cfg, &$dict4Cfg) { switch ($className) { case 'Acme\\TestBundle\\Entity\\Dictionary1': return $dict1Cfg; case 'Acme\\TestBundle\\Entity\\Dictionary2': return $dict2Cfg; case 'Acme\\TestBundle\\Entity\\Dictionary3': return $dict3Cfg; case 'Acme\\TestBundle\\Entity\\Dictionary4': return $dict4Cfg; default: throw new RuntimeException(sprintf('Entity "%s" is not configurable', $className)); } })); $mDataDict1 = $this->createDictionaryMetadata(); $mDataDict2 = $this->createDictionaryMetadata(); $mDataDict3 = $this->createDictionaryMetadata(); $mDataDict4 = $this->createDictionaryMetadata(['name' => 'string', 'code' => 'string', 'label' => 'string'], 'name'); $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnCallback(function ($className) use(&$metadata, &$mDataDict1, &$mDataDict2, &$mDataDict3, &$mDataDict4) { switch ($className) { case 'Acme\\TestBundle\\Entity\\Dictionary1': return $mDataDict1; case 'Acme\\TestBundle\\Entity\\Dictionary2': return $mDataDict2; case 'Acme\\TestBundle\\Entity\\Dictionary3': return $mDataDict3; case 'Acme\\TestBundle\\Entity\\Dictionary4': return $mDataDict4; default: if (isset($metadata[$className])) { return $metadata[$className]; } throw MappingException::reflectionFailure($className, new \ReflectionException()); } })); }
/** * {@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'])) { $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['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']; } if (isset($fieldMapping->options)) { $mapping['options'] = $this->_parseOptions($fieldMapping->options->children()); } $metadata->mapField($mapping); } } // Evaluate <id ...> mappings $associationIds = array(); foreach ($xmlRoot->id as $idElement) { if ((bool) $idElement['association-key'] == true) { $associationIds[(string) $idElement['name']] = true; continue; } $mapping = array('id' => true, 'fieldName' => (string) $idElement['name']); if (isset($idElement['type'])) { $mapping['type'] = (string) $idElement['type']; } if (isset($idElement['column'])) { $mapping['columnName'] = (string) $idElement['column']; } if (isset($idElement['column-definition'])) { $mapping['columnDefinition'] = (string) $idElement['column-definition']; } $metadata->mapField($mapping); if (isset($idElement->generator)) { $strategy = isset($idElement->generator['strategy']) ? (string) $idElement->generator['strategy'] : 'AUTO'; $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $strategy)); } // Check for SequenceGenerator/TableGenerator definition if (isset($idElement->{'sequence-generator'})) { $seqGenerator = $idElement->{'sequence-generator'}; $metadata->setSequenceGeneratorDefinition(array('sequenceName' => (string) $seqGenerator['sequence-name'], 'allocationSize' => (string) $seqGenerator['allocation-size'], 'initialValue' => (string) $seqGenerator['initial-value'])); } else { if (isset($idElement->{'table-generator'})) { throw MappingException::tableIdGeneratorNotImplemented($className); } } } // Evaluate <one-to-one ...> mappings if (isset($xmlRoot->{'one-to-one'})) { foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) { $mapping = array('fieldName' => (string) $oneToOneElement['field'], 'targetEntity' => (string) $oneToOneElement['target-entity']); if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; } if (isset($oneToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $oneToOneElement['fetch']); } if (isset($oneToOneElement['mapped-by'])) { $mapping['mappedBy'] = (string) $oneToOneElement['mapped-by']; } else { if (isset($oneToOneElement['inversed-by'])) { $mapping['inversedBy'] = (string) $oneToOneElement['inversed-by']; } $joinColumns = array(); if (isset($oneToOneElement->{'join-column'})) { $joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement->{'join-column'}); } else { if (isset($oneToOneElement->{'join-columns'})) { foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; } if (isset($oneToOneElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade); } if (isset($oneToOneElement['orphan-removal'])) { $mapping['orphanRemoval'] = (bool) $oneToOneElement['orphan-removal']; } $metadata->mapOneToOne($mapping); } } // Evaluate <one-to-many ...> mappings if (isset($xmlRoot->{'one-to-many'})) { foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) { $mapping = array('fieldName' => (string) $oneToManyElement['field'], 'targetEntity' => (string) $oneToManyElement['target-entity'], 'mappedBy' => (string) $oneToManyElement['mapped-by']); if (isset($oneToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $oneToManyElement['fetch']); } if (isset($oneToManyElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade); } if (isset($oneToManyElement['orphan-removal'])) { $mapping['orphanRemoval'] = (bool) $oneToManyElement['orphan-removal']; } if (isset($oneToManyElement->{'order-by'})) { $orderBy = array(); foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction']; } $mapping['orderBy'] = $orderBy; } if (isset($oneToManyElement['index-by'])) { $mapping['indexBy'] = (string) $oneToManyElement['index-by']; } else { if (isset($oneToManyElement->{'index-by'})) { throw new \InvalidArgumentException("<index-by /> is not a valid tag"); } } $metadata->mapOneToMany($mapping); } } // Evaluate <many-to-one ...> mappings if (isset($xmlRoot->{'many-to-one'})) { foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) { $mapping = array('fieldName' => (string) $manyToOneElement['field'], 'targetEntity' => (string) $manyToOneElement['target-entity']); if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; } if (isset($manyToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $manyToOneElement['fetch']); } if (isset($manyToOneElement['inversed-by'])) { $mapping['inversedBy'] = (string) $manyToOneElement['inversed-by']; } $joinColumns = array(); if (isset($manyToOneElement->{'join-column'})) { $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'}); } else { if (isset($manyToOneElement->{'join-columns'})) { foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; if (isset($manyToOneElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade); } $metadata->mapManyToOne($mapping); } } // Evaluate <many-to-many ...> mappings if (isset($xmlRoot->{'many-to-many'})) { 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'] = (bool) $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->_getJoinColumnMapping($joinColumnElement); } foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) { $joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($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 <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'])); } } }
/** * {@inheritDoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */ $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 { if ($element['type'] == 'embeddable') { $metadata->isEmbeddedClass = true; } else { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); } } } // Evaluate root level properties $table = array(); if (isset($element['table'])) { $table['name'] = $element['table']; } // Evaluate second level cache if (isset($element['cache'])) { $metadata->enableCache($this->cacheToArray($element['cache'])); } $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); } } // Evaluate named native queries if (isset($element['namedNativeQueries'])) { foreach ($element['namedNativeQueries'] as $name => $mappingElement) { if (!isset($mappingElement['name'])) { $mappingElement['name'] = $name; } $metadata->addNamedNativeQuery(array('name' => $mappingElement['name'], 'query' => isset($mappingElement['query']) ? $mappingElement['query'] : null, 'resultClass' => isset($mappingElement['resultClass']) ? $mappingElement['resultClass'] : null, 'resultSetMapping' => isset($mappingElement['resultSetMapping']) ? $mappingElement['resultSetMapping'] : null)); } } // Evaluate sql result set mappings if (isset($element['sqlResultSetMappings'])) { foreach ($element['sqlResultSetMappings'] as $name => $resultSetMapping) { if (!isset($resultSetMapping['name'])) { $resultSetMapping['name'] = $name; } $entities = array(); $columns = array(); if (isset($resultSetMapping['entityResult'])) { foreach ($resultSetMapping['entityResult'] as $entityResultElement) { $entityResult = array('fields' => array(), 'entityClass' => isset($entityResultElement['entityClass']) ? $entityResultElement['entityClass'] : null, 'discriminatorColumn' => isset($entityResultElement['discriminatorColumn']) ? $entityResultElement['discriminatorColumn'] : null); if (isset($entityResultElement['fieldResult'])) { foreach ($entityResultElement['fieldResult'] as $fieldResultElement) { $entityResult['fields'][] = array('name' => isset($fieldResultElement['name']) ? $fieldResultElement['name'] : null, 'column' => isset($fieldResultElement['column']) ? $fieldResultElement['column'] : null); } } $entities[] = $entityResult; } } if (isset($resultSetMapping['columnResult'])) { foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) { $columns[] = array('name' => isset($columnResultAnnot['name']) ? $columnResultAnnot['name'] : null); } } $metadata->addSqlResultSetMapping(array('name' => $resultSetMapping['name'], 'entities' => $entities, 'columns' => $columns)); } } /* 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' => 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['columnDefinition']) ? (string) $discrColumn['columnDefinition'] : null)); } 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 => $indexYml) { if (!isset($indexYml['name'])) { $indexYml['name'] = $name; } if (is_string($indexYml['columns'])) { $index = array('columns' => array_map('trim', explode(',', $indexYml['columns']))); } else { $index = array('columns' => $indexYml['columns']); } if (isset($indexYml['flags'])) { if (is_string($indexYml['flags'])) { $index['flags'] = array_map('trim', explode(',', $indexYml['flags'])); } else { $index['flags'] = $indexYml['flags']; } } if (isset($indexYml['options'])) { $index['options'] = $indexYml['options']; } $metadata->table['indexes'][$indexYml['name']] = $index; } } // Evaluate uniqueConstraints if (isset($element['uniqueConstraints'])) { foreach ($element['uniqueConstraints'] as $name => $uniqueYml) { if (!isset($uniqueYml['name'])) { $uniqueYml['name'] = $name; } if (is_string($uniqueYml['columns'])) { $unique = array('columns' => array_map('trim', explode(',', $uniqueYml['columns']))); } else { $unique = array('columns' => $uniqueYml['columns']); } if (isset($uniqueYml['options'])) { $unique['options'] = $uniqueYml['options']; } $metadata->table['uniqueConstraints'][$uniqueYml['name']] = $unique; } } if (isset($element['options'])) { $metadata->table['options'] = $element['options']; } $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); if (isset($idElement['type'])) { $mapping['type'] = $idElement['type']; } if (isset($idElement['column'])) { $mapping['columnName'] = $idElement['column']; } if (isset($idElement['length'])) { $mapping['length'] = $idElement['length']; } if (isset($idElement['columnDefinition'])) { $mapping['columnDefinition'] = $idElement['columnDefinition']; } if (isset($idElement['options'])) { $mapping['options'] = $idElement['options']; } $metadata->mapField($mapping); if (isset($idElement['generator'])) { $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($idElement['generator']['strategy']))); } // Check for SequenceGenerator/TableGenerator definition if (isset($idElement['sequenceGenerator'])) { $metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']); } else { if (isset($idElement['customIdGenerator'])) { $customGenerator = $idElement['customIdGenerator']; $metadata->setCustomGeneratorDefinition(array('class' => (string) $customGenerator['class'])); } else { if (isset($idElement['tableGenerator'])) { throw MappingException::tableIdGeneratorNotImplemented($className); } } } } } // Evaluate fields if (isset($element['fields'])) { foreach ($element['fields'] as $name => $fieldMapping) { $mapping = $this->columnToArray($name, $fieldMapping); if (isset($fieldMapping['id'])) { $mapping['id'] = true; if (isset($fieldMapping['generator']['strategy'])) { $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($fieldMapping['generator']['strategy']))); } } if (isset($mapping['version'])) { $metadata->setVersionMapping($mapping); unset($mapping['version']); } $metadata->mapField($mapping); } } if (isset($element['embedded'])) { foreach ($element['embedded'] as $name => $embeddedMapping) { $mapping = array('fieldName' => $name, 'class' => $embeddedMapping['class'], 'columnPrefix' => isset($embeddedMapping['columnPrefix']) ? $embeddedMapping['columnPrefix'] : null); $metadata->mapEmbedded($mapping); } } // Evaluate oneToOne relationships if (isset($element['oneToOne'])) { foreach ($element['oneToOne'] as $name => $oneToOneElement) { $mapping = array('fieldName' => $name, 'targetEntity' => $oneToOneElement['targetEntity']); if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; } if (isset($oneToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToOneElement['fetch']); } if (isset($oneToOneElement['mappedBy'])) { $mapping['mappedBy'] = $oneToOneElement['mappedBy']; } else { if (isset($oneToOneElement['inversedBy'])) { $mapping['inversedBy'] = $oneToOneElement['inversedBy']; } $joinColumns = array(); if (isset($oneToOneElement['joinColumn'])) { $joinColumns[] = $this->joinColumnToArray($oneToOneElement['joinColumn']); } else { if (isset($oneToOneElement['joinColumns'])) { foreach ($oneToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) { if (!isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $joinColumnName; } $joinColumns[] = $this->joinColumnToArray($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; } if (isset($oneToOneElement['cascade'])) { $mapping['cascade'] = $oneToOneElement['cascade']; } if (isset($oneToOneElement['orphanRemoval'])) { $mapping['orphanRemoval'] = (bool) $oneToOneElement['orphanRemoval']; } $metadata->mapOneToOne($mapping); // Evaluate second level cache if (isset($oneToOneElement['cache'])) { $metadata->enableAssociationCache($mapping['fieldName'], $this->cacheToArray($oneToOneElement['cache'])); } } } // Evaluate oneToMany relationships if (isset($element['oneToMany'])) { foreach ($element['oneToMany'] as $name => $oneToManyElement) { $mapping = array('fieldName' => $name, 'targetEntity' => $oneToManyElement['targetEntity'], 'mappedBy' => $oneToManyElement['mappedBy']); if (isset($oneToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToManyElement['fetch']); } if (isset($oneToManyElement['cascade'])) { $mapping['cascade'] = $oneToManyElement['cascade']; } if (isset($oneToManyElement['orphanRemoval'])) { $mapping['orphanRemoval'] = (bool) $oneToManyElement['orphanRemoval']; } if (isset($oneToManyElement['orderBy'])) { $mapping['orderBy'] = $oneToManyElement['orderBy']; } if (isset($oneToManyElement['indexBy'])) { $mapping['indexBy'] = $oneToManyElement['indexBy']; } $metadata->mapOneToMany($mapping); // Evaluate second level cache if (isset($oneToManyElement['cache'])) { $metadata->enableAssociationCache($mapping['fieldName'], $this->cacheToArray($oneToManyElement['cache'])); } } } // Evaluate manyToOne relationships if (isset($element['manyToOne'])) { foreach ($element['manyToOne'] as $name => $manyToOneElement) { $mapping = array('fieldName' => $name, 'targetEntity' => $manyToOneElement['targetEntity']); if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; } if (isset($manyToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $manyToOneElement['fetch']); } if (isset($manyToOneElement['inversedBy'])) { $mapping['inversedBy'] = $manyToOneElement['inversedBy']; } $joinColumns = array(); if (isset($manyToOneElement['joinColumn'])) { $joinColumns[] = $this->joinColumnToArray($manyToOneElement['joinColumn']); } else { if (isset($manyToOneElement['joinColumns'])) { foreach ($manyToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) { if (!isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $joinColumnName; } $joinColumns[] = $this->joinColumnToArray($joinColumnElement); } } } $mapping['joinColumns'] = $joinColumns; if (isset($manyToOneElement['cascade'])) { $mapping['cascade'] = $manyToOneElement['cascade']; } $metadata->mapManyToOne($mapping); // Evaluate second level cache if (isset($manyToOneElement['cache'])) { $metadata->enableAssociationCache($mapping['fieldName'], $this->cacheToArray($manyToOneElement['cache'])); } } } // Evaluate manyToMany relationships if (isset($element['manyToMany'])) { foreach ($element['manyToMany'] as $name => $manyToManyElement) { $mapping = array('fieldName' => $name, 'targetEntity' => $manyToManyElement['targetEntity']); if (isset($manyToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $manyToManyElement['fetch']); } if (isset($manyToManyElement['mappedBy'])) { $mapping['mappedBy'] = $manyToManyElement['mappedBy']; } else { if (isset($manyToManyElement['joinTable'])) { $joinTableElement = $manyToManyElement['joinTable']; $joinTable = array('name' => $joinTableElement['name']); if (isset($joinTableElement['schema'])) { $joinTable['schema'] = $joinTableElement['schema']; } if (isset($joinTableElement['joinColumns'])) { foreach ($joinTableElement['joinColumns'] as $joinColumnName => $joinColumnElement) { if (!isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $joinColumnName; } } $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement); } if (isset($joinTableElement['inverseJoinColumns'])) { foreach ($joinTableElement['inverseJoinColumns'] as $joinColumnName => $joinColumnElement) { if (!isset($joinColumnElement['name'])) { $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); } } } } }