本文整理汇总了PHP中Doctrine\ORM\Mapping\MappingException类的典型用法代码示例。如果您正苦于以下问题:PHP MappingException类的具体用法?PHP MappingException怎么用?PHP MappingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MappingException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: loadMetadataForClass
/**
* {@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));
}
}
开发者ID:ruian,项目名称:KnpRadBundle,代码行数:35,代码来源:YamlDriver.php
示例2:
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'.");
}
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:7,代码来源:ProductValueRelationshipCheckerSpec.php
示例3: getAllClassNames
/**
* {@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;
}
开发者ID:michaelnavarro,项目名称:zc,代码行数:39,代码来源:StaticPHPDriver.php
示例4: getAllClassNames
/**
* 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;
}
开发者ID:victoire,项目名称:victoire,代码行数:33,代码来源:AnnotationDriver.php
示例5: getClassMetadata
/**
* 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;
}
开发者ID:laubosslink,项目名称:lab,代码行数:17,代码来源:MetadataFactory.php
示例6: loadMetadataForClass
/**
* 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);
}
开发者ID:pabloasc,项目名称:test_social,代码行数:16,代码来源:DriverChain.php
示例7: findMappingFile
/**
* {@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];
}
开发者ID:nacmartin,项目名称:SimpleDoctrineMapping,代码行数:13,代码来源:SimpleDoctrineMappingLocator.php
示例8: bindEntityListener
/**
* 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);
}
}
开发者ID:Dren-x,项目名称:mobit,代码行数:21,代码来源:EntityListenerBuilder.php
示例9: _findMappingFile
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);
}
开发者ID:rfc1483,项目名称:blog,代码行数:14,代码来源:XmlDriver.php
示例10: getClassMetadata
/**
* 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;
}
开发者ID:laiello,项目名称:mediathequescrum,代码行数:25,代码来源:MetadataFactory.php
示例11: setVersionMapping
/**
* 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']);
}
}
}
}
开发者ID:alexanderwsp-git,项目名称:columbus,代码行数:24,代码来源:ClassMetadataInfo.php
示例12: getManyToManyStatement
/**
* @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);
}
开发者ID:nattaphat,项目名称:hgis,代码行数:66,代码来源:BasicEntityPersister.php
示例13: loadMetadataForClass
/**
* {@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 {
//.........这里部分代码省略.........
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:101,代码来源:XmlDriver.php
示例14: getAllClassNames
/**
* {@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;
}
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:29,代码来源:AnnotationDriver.php
示例15: addLifecycleCallback
/**
* @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);
}
开发者ID:ramonornela,项目名称:doctrine2,代码行数:11,代码来源:ClassMetadata.php
示例16: addInheritedRelations
/**
* 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);
}
}
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:29,代码来源:ClassMetadataFactory.php
示例17: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{
$xmlRoot = $this->getElement($className);
if ($xmlRoot->getName() == 'entity') {
$metadata->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
} else {
if ($xmlRoot->getName() == 'mapped-superclass') {
$metadata->isMappedSuperclass = true;
} else {
throw MappingException::classIsNotAValidEntityOrMapperSuperClass($className);
}
}
// Evaluate <entity...> attributes
if (isset($xmlRoot['table'])) {
$metadata->primaryTable['name'] = (string) $xmlRoot['table'];
}
if (isset($xmlRoot['schema'])) {
$metadata->primaryTable['schema'] = (string) $xmlRoot['schema'];
}
if (isset($xmlRoot['inheritance-type'])) {
$metadata->setInheritanceType((string) $xmlRoot['inheritance-type']);
}
// Evaluate <discriminator-column...>
if (isset($xmlRoot->{'discriminator-column'})) {
$discrColumn = $xmlRoot->{'discriminator-column'};
$metadata->setDiscriminatorColumn(array('name' => (string) $discrColumn['name'], 'type' => (string) $discrColumn['type'], 'length' => (string) $discrColumn['length']));
}
// Evaluate <discriminator-map...>
if (isset($xmlRoot->{'discriminator-map'})) {
$metadata->setDiscriminatorMap((array) $xmlRoot->{'discriminator-map'});
}
// Evaluate <change-tracking-policy...>
if (isset($xmlRoot->{'change-tracking-policy'})) {
$metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot->{'change-tracking-policy'})));
}
// Evaluate <indexes...>
if (isset($xmlRoot->indexes)) {
foreach ($xmlRoot->indexes->index as $index) {
if (is_string($index['columns'])) {
$columns = explode(',', $index['columns']);
} else {
$columns = $index['columns'];
}
$metadata->primaryTable['indexes'][$index['name']] = array('columns' => $columns);
}
}
// Evaluate <unique-constraints..>
if (isset($xmlRoot->{'unique-constraints'})) {
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) {
if (is_string($unique['columns'])) {
$columns = explode(',', $unique['columns']);
} else {
$columns = $unique['columns'];
}
$metadata->primaryTable['uniqueConstraints'][$unique['name']] = array('columns' => $columns);
}
}
// Evaluate <field ...> mappings
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $fieldMapping) {
$mapping = array('fieldName' => (string) $fieldMapping['name'], 'type' => (string) $fieldMapping['type']);
if (isset($fieldMapping['column'])) {
$mapping['columnName'] = (string) $fieldMapping['column'];
}
if (isset($fieldMapping['length'])) {
$mapping['length'] = (int) $fieldMapping['length'];
}
if (isset($fieldMapping['precision'])) {
$mapping['precision'] = (int) $fieldMapping['precision'];
}
if (isset($fieldMapping['scale'])) {
$mapping['scale'] = (int) $fieldMapping['scale'];
}
if (isset($fieldMapping['unique'])) {
$mapping['unique'] = (string) $fieldMapping['unique'] == "false" ? false : true;
}
if (isset($fieldMapping['options'])) {
$mapping['options'] = (array) $fieldMapping['options'];
}
if (isset($fieldMapping['nullable'])) {
$mapping['nullable'] = (string) $fieldMapping['nullable'] == "false" ? false : true;
}
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
$metadata->setVersionMapping($mapping);
}
if (isset($fieldMapping['column-definition'])) {
$mapping['columnDefinition'] = (string) $fieldMapping['column-definition'];
}
$metadata->mapField($mapping);
}
}
// Evaluate <id ...> mappings
foreach ($xmlRoot->id as $idElement) {
$mapping = array('id' => true, 'fieldName' => (string) $idElement['name'], 'type' => (string) $idElement['type']);
if (isset($idElement['column'])) {
$mapping['columnName'] = (string) $idElement['column'];
}
//.........这里部分代码省略.........
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:101,代码来源:XmlDriver.php
示例18: loadMetadata
/**
* 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;
}
开发者ID:jeffreiffers,项目名称:doctrine2,代码行数:93,代码来源:ClassMetadataFactory.php
示例19: isTransient
/**
* 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);
}
开发者ID:poulikov,项目名称:readlater,代码行数:17,代码来源:DriverChain.php
示例20: getFetchMode
/**
* 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);
}
开发者ID:SerdarSanri,项目名称:doctrine-bundle,代码行数:15,代码来源:AnnotationDriver.php
注:本文中的Doctrine\ORM\Mapping\MappingException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论