本文整理汇总了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadata::setCustomRepositoryClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::setCustomRepositoryClass方法的具体用法?PHP ClassMetadata::setCustomRepositoryClass怎么用?PHP ClassMetadata::setCustomRepositoryClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::setCustomRepositoryClass方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setCustomRepositoryClass
/**
* @param ClassMetadata $metadata
*/
private function setCustomRepositoryClass(ClassMetadata $metadata)
{
try {
$resourceMetadata = $this->resourceRegistry->getByClass($metadata->getName());
} catch (\InvalidArgumentException $exception) {
return;
}
if ($resourceMetadata->hasClass('repository')) {
$metadata->setCustomRepositoryClass($resourceMetadata->getClass('repository'));
}
}
示例2: testClassMetadataInstanceSerialization
public function testClassMetadataInstanceSerialization()
{
$cm = new ClassMetadata('Documents\\CmsUser');
// Test initial state
$this->assertTrue(count($cm->getReflectionProperties()) == 0);
$this->assertTrue($cm->reflClass instanceof \ReflectionClass);
$this->assertEquals('Documents\\CmsUser', $cm->name);
$this->assertEquals('Documents\\CmsUser', $cm->rootDocumentName);
$this->assertEquals(array(), $cm->subClasses);
$this->assertEquals(array(), $cm->parentClasses);
$this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm->inheritanceType);
// Customize state
$cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION);
$cm->setSubclasses(array("One", "Two", "Three"));
$cm->setParentClasses(array("UserParent"));
$cm->setCustomRepositoryClass("UserRepository");
$cm->setDiscriminatorField('disc');
$cm->mapOneEmbedded(array('fieldName' => 'phonenumbers', 'targetDocument' => 'Bar'));
$cm->setFile('customFileProperty');
$cm->setDistance('customDistanceProperty');
$cm->setSlaveOkay(true);
$cm->setShardKey(array('_id' => '1'));
$cm->setCollectionCapped(true);
$cm->setCollectionMax(1000);
$cm->setCollectionSize(500);
$this->assertTrue(is_array($cm->getFieldMapping('phonenumbers')));
$this->assertEquals(1, count($cm->fieldMappings));
$this->assertEquals(1, count($cm->associationMappings));
$serialized = serialize($cm);
$cm = unserialize($serialized);
// Check state
$this->assertTrue(count($cm->getReflectionProperties()) > 0);
$this->assertEquals('Documents', $cm->namespace);
$this->assertTrue($cm->reflClass instanceof \ReflectionClass);
$this->assertEquals('Documents\\CmsUser', $cm->name);
$this->assertEquals('UserParent', $cm->rootDocumentName);
$this->assertEquals(array('Documents\\One', 'Documents\\Two', 'Documents\\Three'), $cm->subClasses);
$this->assertEquals(array('UserParent'), $cm->parentClasses);
$this->assertEquals('Documents\\UserRepository', $cm->customRepositoryClassName);
$this->assertEquals('disc', $cm->discriminatorField);
$this->assertTrue(is_array($cm->getFieldMapping('phonenumbers')));
$this->assertEquals(1, count($cm->fieldMappings));
$this->assertEquals(1, count($cm->associationMappings));
$this->assertEquals('customFileProperty', $cm->file);
$this->assertEquals('customDistanceProperty', $cm->distance);
$this->assertTrue($cm->slaveOkay);
$this->assertEquals(array('keys' => array('_id' => 1), 'options' => array()), $cm->getShardKey());
$mapping = $cm->getFieldMapping('phonenumbers');
$this->assertEquals('Documents\\Bar', $mapping['targetDocument']);
$this->assertTrue($cm->getCollectionCapped());
$this->assertEquals(1000, $cm->getCollectionMax());
$this->assertEquals(500, $cm->getCollectionSize());
}
示例3: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$reflClass = $class->getReflectionClass();
$classAnnotations = $this->reader->getClassAnnotations($reflClass);
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'])) {
$documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'];
} elseif (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\MappedSuperclass'])) {
$documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\MappedSuperclass'];
$class->isMappedSuperclass = true;
} elseif (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\EmbeddedDocument'])) {
$documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\EmbeddedDocument'];
$class->isEmbeddedDocument = true;
} else {
throw MongoDBException::classIsNotAValidDocument($className);
}
if (isset($documentAnnot->db)) {
$class->setDatabase($documentAnnot->db);
}
if (isset($documentAnnot->collection)) {
$class->setCollection($documentAnnot->collection);
}
if (isset($documentAnnot->repositoryClass)) {
$class->setCustomRepositoryClass($documentAnnot->repositoryClass);
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Indexes'])) {
$indexes = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Indexes']->value;
$indexes = is_array($indexes) ? $indexes : array($indexes);
foreach ($indexes as $index) {
$this->addIndex($class, $index);
}
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Index'])) {
$index = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Index'];
$this->addIndex($class, $index);
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\UniqueIndex'])) {
$index = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\UniqueIndex'];
$this->addIndex($class, $index);
}
if (isset($documentAnnot->indexes)) {
foreach ($documentAnnot->indexes as $index) {
$this->addIndex($class, $index);
}
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'])) {
$inheritanceTypeAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'];
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'])) {
$discrFieldAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'];
$class->setDiscriminatorField(array('fieldName' => $discrFieldAnnot->fieldName));
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'])) {
$discrMapAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'];
$class->setDiscriminatorMap($discrMapAnnot->value);
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorValue'])) {
$discrValueAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorValue'];
$class->setDiscriminatorValue($discrValueAnnot->value);
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\ChangeTrackingPolicy'])) {
$changeTrackingAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\ChangeTrackingPolicy'];
$class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value));
}
$methods = $reflClass->getMethods();
foreach ($reflClass->getProperties() as $property) {
if ($class->isMappedSuperclass && !$property->isPrivate() || $class->isInheritedField($property->name)) {
continue;
}
$mapping = array();
$mapping['fieldName'] = $property->getName();
if ($alsoLoad = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\AlsoLoad')) {
$mapping['alsoLoadFields'] = (array) $alsoLoad->value;
}
if ($notSaved = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\NotSaved')) {
$mapping['notSaved'] = true;
}
if ($versionAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Version')) {
$mapping['version'] = true;
}
if ($versionAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Lock')) {
$mapping['lock'] = true;
}
$indexes = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Indexes');
$indexes = $indexes ? $indexes : array();
if ($index = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Index')) {
$indexes[] = $index;
}
if ($index = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\UniqueIndex')) {
$indexes[] = $index;
}
foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
if ($fieldAnnot instanceof \Doctrine\ODM\MongoDB\Mapping\Field) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$class->mapField($mapping);
}
}
//.........这里部分代码省略.........
示例4:
function it_does_not_set_custom_repository_class_if_registry_does_not_have_class(LoadClassMetadataEventArgs $event, RegistryInterface $registry, ClassMetadata $classMetadata)
{
$registry->getByClass('Foo')->willThrow(\InvalidArgumentException::class);
$classMetadata->setCustomRepositoryClass(Argument::any())->shouldNotBeCalled();
$this->loadClassMetadata($event);
}
示例5: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$xmlRoot = $this->getElement($className);
if (!$xmlRoot) {
return;
}
if ($xmlRoot->getName() == 'document') {
if (isset($xmlRoot['repository-class'])) {
$class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
}
} elseif ($xmlRoot->getName() == 'mapped-superclass') {
$class->isMappedSuperclass = true;
} elseif ($xmlRoot->getName() == 'embedded-document') {
$class->isEmbeddedDocument = true;
}
if (isset($xmlRoot['db'])) {
$class->setDatabase((string) $xmlRoot['db']);
}
if (isset($xmlRoot['collection'])) {
$class->setCollection((string) $xmlRoot['collection']);
}
if (isset($xmlRoot['inheritance-type'])) {
$inheritanceType = (string) $xmlRoot['inheritance-type'];
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
}
if (isset($xmlRoot->{'discriminator-field'})) {
$discrField = $xmlRoot->{'discriminator-field'};
$class->setDiscriminatorField(array('name' => (string) $discrField['name'], 'fieldName' => (string) $discrField['fieldName']));
}
if (isset($xmlRoot->{'discriminator-map'})) {
$map = array();
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
$map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
}
$class->setDiscriminatorMap($map);
}
if (isset($xmlRoot->{'change-tracking-policy'})) {
$class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot->{'change-tracking-policy'})));
}
if (isset($xmlRoot->{'indexes'})) {
foreach ($xmlRoot->{'indexes'}->{'index'} as $index) {
$this->addIndex($class, $index);
}
}
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $field) {
$mapping = array();
$attributes = $field->attributes();
foreach ($attributes as $key => $value) {
$mapping[$key] = (string) $value;
$booleanAttributes = array('id', 'reference', 'embed', 'unique');
if (in_array($key, $booleanAttributes)) {
$mapping[$key] = 'true' === $mapping[$key] ? true : false;
}
}
$this->addFieldMapping($class, $mapping);
}
}
if (isset($xmlRoot->{'embed-one'})) {
foreach ($xmlRoot->{'embed-one'} as $embed) {
$this->addEmbedMapping($class, $embed, 'one');
}
}
if (isset($xmlRoot->{'embed-many'})) {
foreach ($xmlRoot->{'embed-many'} as $embed) {
$this->addEmbedMapping($class, $embed, 'many');
}
}
if (isset($xmlRoot->{'reference-many'})) {
foreach ($xmlRoot->{'reference-many'} as $reference) {
$this->addReferenceMapping($class, $reference, 'many');
}
}
if (isset($xmlRoot->{'reference-one'})) {
foreach ($xmlRoot->{'reference-one'} as $reference) {
$this->addReferenceMapping($class, $reference, 'one');
}
}
if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ODM\\MongoDB\\Events::' . (string) $lifecycleCallback['type']));
}
}
}
示例6: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$xmlRoot = $this->getElement($className);
if (!$xmlRoot) {
return;
}
if (isset($xmlRoot['db'])) {
$class->setDB((string) $xmlRoot['db']);
}
if (isset($xmlRoot['collection'])) {
$class->setCollection((string) $xmlRoot['collection']);
}
if (isset($xmlRoot['repository-class'])) {
$class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
}
if (isset($xmlRoot['indexes'])) {
foreach ($xmlRoot['indexes'] as $index) {
$class->addIndex((array) $index['keys'], (array) $index['options']);
}
}
if (isset($xmlRoot['inheritance-type'])) {
$inheritanceType = (string) $xmlRoot['inheritance-type'];
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
}
if (isset($xmlRoot->{'discriminator-field'})) {
$discrField = $xmlRoot->{'discriminator-field'};
$class->setDiscriminatorField(array('name' => (string) $discrField['name'], 'fieldName' => (string) $discrField['fieldName']));
}
if (isset($xmlRoot->{'discriminator-map'})) {
$map = array();
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
$map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
}
$class->setDiscriminatorMap($map);
}
if (isset($xmlRoot->inheritance['type'])) {
$class->discriminatorMap = $xmlRoot['inheritance'];
}
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $field) {
$mapping = array();
$attributes = $field->attributes();
foreach ($attributes as $key => $value) {
$mapping[$key] = (string) $value;
$booleanAttributes = array('id', 'reference', 'embed');
if (in_array($key, $booleanAttributes)) {
$mapping[$key] = 'true' === $mapping[$key] ? true : false;
}
}
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'embed-one'})) {
foreach ($xmlRoot->{'embed-one'} as $embed) {
$mapping = $this->_getMappingFromEmbed($embed, 'one');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'embed-many'})) {
foreach ($xmlRoot->{'embed-many'} as $embed) {
$mapping = $this->_getMappingFromEmbed($embed, 'many');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'reference-many'})) {
foreach ($xmlRoot->{'reference-many'} as $reference) {
$mapping = $this->_getMappingFromReference($reference, 'many');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'reference-one'})) {
foreach ($xmlRoot->{'reference-one'} as $reference) {
$mapping = $this->_getMappingFromReference($reference, 'one');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ORM\\Events::' . (string) $lifecycleCallback['type']));
}
}
}
示例7: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$element = $this->getElement($className);
if ( ! $element) {
return;
}
$element['type'] = isset($element['type']) ? $element['type'] : 'document';
if (isset($element['db'])) {
$class->setDB($element['db']);
}
if (isset($element['collection'])) {
$class->setCollection($element['collection']);
}
if ($element['type'] == 'document') {
if (isset($element['repositoryClass'])) {
$class->setCustomRepositoryClass($element['repositoryClass']);
}
} elseif ($element['type'] === 'mappedSuperclass') {
$class->isMappedSuperclass = true;
} elseif ($element['type'] === 'embeddedDocument') {
$class->isEmbeddedDocument = true;
}
if (isset($element['indexes'])) {
foreach($element['indexes'] as $index) {
$class->addIndex($index['keys'], isset($index['options']) ? $index['options'] : array());
}
}
if (isset($element['inheritanceType'])) {
$class->setInheritanceType(constant('Doctrine\ODM\MongoDB\Mapping\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
}
if (isset($element['discriminatorField'])) {
$discrField = $element['discriminatorField'];
$class->setDiscriminatorField(array(
'name' => $discrField['name'],
'fieldName' => $discrField['fieldName']
));
}
if (isset($element['discriminatorMap'])) {
$class->setDiscriminatorMap($element['discriminatorMap']);
}
if (isset($element['changeTrackingPolicy'])) {
$class->setChangeTrackingPolicy(constant('Doctrine\ODM\MongoDB\Mapping\ClassMetadata::CHANGETRACKING_'
. strtoupper($element['changeTrackingPolicy'])));
}
if (isset($element['fields'])) {
foreach ($element['fields'] as $fieldName => $mapping) {
if (is_string($mapping)) {
$type = $mapping;
$mapping = array();
$mapping['type'] = $type;
}
if ( ! isset($mapping['fieldName'])) {
$mapping['fieldName'] = $fieldName;
}
if (isset($mapping['type']) && $mapping['type'] === 'collection') {
$mapping['strategy'] = isset($mapping['strategy']) ? $mapping['strategy'] : 'pushAll';
}
$this->addFieldMapping($class, $mapping);
}
}
if (isset($element['embedOne'])) {
foreach ($element['embedOne'] as $fieldName => $embed) {
$this->addMappingFromEmbed($class, $fieldName, $embed, 'one');
}
}
if (isset($element['embedMany'])) {
foreach ($element['embedMany'] as $fieldName => $embed) {
$this->addMappingFromEmbed($class, $fieldName, $embed, 'many');
}
}
if (isset($element['referenceOne'])) {
foreach ($element['referenceOne'] as $fieldName => $reference) {
$this->addMappingFromReference($class, $fieldName, $reference, 'one');
}
}
if (isset($element['referenceMany'])) {
foreach ($element['referenceMany'] as $fieldName => $reference) {
$this->addMappingFromReference($class, $fieldName, $reference, 'many');
}
}
if (isset($element['lifecycleCallbacks'])) {
foreach ($element['lifecycleCallbacks'] as $type => $methods) {
foreach ($methods as $method) {
$class->addLifecycleCallback($method, constant('Doctrine\ODM\MongoDB\Events::' . $type));
}
}
}
}
示例8: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$reflClass = $class->getReflectionClass();
$classAnnotations = $this->_reader->getClassAnnotations($reflClass);
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'])) {
$documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'];
if ($documentAnnot->db) {
$class->setDB($documentAnnot->db);
}
if ($documentAnnot->collection) {
$class->setCollection($documentAnnot->collection);
}
if ($documentAnnot->repositoryClass) {
$class->setCustomRepositoryClass($documentAnnot->repositoryClass);
}
if ($documentAnnot->indexes) {
foreach ($documentAnnot->indexes as $index) {
$class->addIndex($index->keys, $index->options);
}
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'])) {
$inheritanceTypeAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'];
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'])) {
$discrFieldAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'];
$class->setDiscriminatorField(array('fieldName' => $discrFieldAnnot->fieldName));
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'])) {
$discrMapAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'];
$class->setDiscriminatorMap($discrMapAnnot->value);
}
} else {
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\MappedSuperclass'])) {
$class->isMappedSuperclass = true;
} else {
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\EmbeddedDocument'])) {
$class->isEmbeddedDocument = true;
}
}
}
foreach ($reflClass->getProperties() as $property) {
$mapping = array();
$mapping['fieldName'] = $property->getName();
$types = array('Id', 'Increment', 'File', 'Field', 'String', 'Boolean', 'Int', 'Float', 'Date', 'Key', 'Bin', 'BinFunc', 'BinUUID', 'BinMD5', 'BinCustom', 'EmbedOne', 'EmbedMany', 'ReferenceOne', 'ReferenceMany', 'Timestamp', 'Hash', 'Collection');
foreach ($types as $type) {
if ($fieldAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\' . $type)) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$class->mapField($mapping);
break;
}
}
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\HasLifecycleCallbacks'])) {
foreach ($reflClass->getMethods() as $method) {
if ($method->isPublic()) {
$annotations = $this->_reader->getMethodAnnotations($method);
if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PrePersist'])) {
$class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::prePersist);
}
if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostPersist'])) {
$class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::postPersist);
}
if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PreUpdate'])) {
$class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::preUpdate);
}
if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostUpdate'])) {
$class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::postUpdate);
}
if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PreRemove'])) {
$class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::preRemove);
}
if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostRemove'])) {
$class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::postRemove);
}
if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostLoad'])) {
$class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::postLoad);
}
}
}
}
}
示例9: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$reflClass = $class->getReflectionClass();
$classAnnotations = $this->_reader->getClassAnnotations($reflClass);
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'])) {
$documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'];
if ($documentAnnot->db) {
$class->setDB($documentAnnot->db);
}
if ($documentAnnot->collection) {
$class->setCollection($documentAnnot->collection);
}
if ($documentAnnot->repositoryClass) {
$class->setCustomRepositoryClass($documentAnnot->repositoryClass);
}
if ($documentAnnot->indexes) {
foreach ($documentAnnot->indexes as $index) {
$class->addIndex($index->keys, $index->options);
}
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'])) {
$inheritanceTypeAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'];
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'])) {
$discrFieldAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'];
$class->setDiscriminatorField(array('fieldName' => $discrFieldAnnot->fieldName));
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'])) {
$discrMapAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'];
$class->setDiscriminatorMap($discrMapAnnot->value);
}
} else {
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\MappedSuperclass'])) {
$class->isMappedSuperclass = true;
} else {
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\EmbeddedDocument'])) {
$class->isEmbeddedDocument = true;
}
}
}
$methods = $reflClass->getMethods();
foreach ($reflClass->getProperties() as $property) {
$mapping = array();
$mapping['fieldName'] = $property->getName();
if ($alsoLoad = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\AlsoLoad')) {
$mapping['alsoLoadFields'] = (array) $alsoLoad->value;
}
if ($notSaved = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\NotSaved')) {
$mapping['notSaved'] = true;
}
foreach ($this->_reader->getPropertyAnnotations($property) as $fieldAnnot) {
if ($fieldAnnot instanceof \Doctrine\ODM\MongoDB\Mapping\Field) {
if ($fieldAnnot instanceof \Doctrine\ODM\MongoDB\Mapping\Id && $fieldAnnot->custom) {
$fieldAnnot->type = 'custom_id';
$class->setAllowCustomId(true);
}
$mapping = array_merge($mapping, (array) $fieldAnnot);
$class->mapField($mapping);
}
}
$types = array('Embed', 'Reference');
foreach ($types as $type) {
if ($fieldAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\' . $type)) {
// This is a blatant hack to see if the defined default
// value is an array so we can make the embed/reference many
// instead of one. This won't be necessary once the ReflectionProperty
// class has a getDefaultValue() method: http://bugs.php.net/bug.php?id=41670
$property->setAccessible(true);
$default = $property->getValue(new $class->name());
$mapping = array_merge($mapping, (array) $fieldAnnot);
if (is_array($default)) {
$mapping['type'] = 'many';
} else {
$mapping['type'] = 'one';
}
$class->mapField($mapping);
}
}
}
foreach ($methods as $method) {
if ($method->isPublic()) {
if ($alsoLoad = $this->_reader->getMethodAnnotation($method, 'Doctrine\\ODM\\MongoDB\\Mapping\\AlsoLoad')) {
$class->fieldMappings[$mapping['fieldName']]['alsoLoadMethods'][] = array('name' => (array) $alsoLoad->value, 'method' => $method->getName());
}
}
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\HasLifecycleCallbacks'])) {
foreach ($methods as $method) {
if ($method->isPublic()) {
$annotations = $this->_reader->getMethodAnnotations($method);
if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PrePersist'])) {
$class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\ODMEvents::prePersist);
}
if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostPersist'])) {
$class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\ODMEvents::postPersist);
}
//.........这里部分代码省略.........
示例10: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$element = $this->getElement($className);
if (!$element) {
return;
}
$element['type'] = isset($element['type']) ? $element['type'] : 'document';
if (isset($element['db'])) {
$class->setDB($element['db']);
}
if (isset($element['collection'])) {
$class->setCollection($element['collection']);
}
if ($element['type'] == 'document') {
if (isset($element['repositoryClass'])) {
$class->setCustomRepositoryClass($element['repositoryClass']);
}
} elseif ($element['type'] === 'mappedSuperclass') {
$class->isMappedSuperclass = true;
} elseif ($element['type'] === 'embeddedDocument') {
$class->isEmbeddedDocument = true;
}
if (isset($element['indexes'])) {
foreach ($element['indexes'] as $index) {
$class->addIndex($index['keys'], $index['options']);
}
}
if (isset($element['inheritanceType'])) {
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
}
if (isset($element['discriminatorColumn'])) {
$discrColumn = $element['discriminatorColumn'];
$class->setDiscriminatorColumn(array('name' => $discrColumn['name'], 'fieldName' => $discrColumn['fieldName']));
}
if (isset($element['discriminatorMap'])) {
$class->setDiscriminatorMap($element['discriminatorMap']);
}
if (isset($element['fields'])) {
foreach ($element['fields'] as $fieldName => $mapping) {
if (!isset($mapping['fieldName'])) {
$mapping['fieldName'] = $fieldName;
}
$class->mapField($mapping);
}
}
if (isset($element['embedOne'])) {
foreach ($element['embedOne'] as $fieldName => $embed) {
$mapping = $this->_getMappingFromEmbed($fieldName, $embed, 'one');
$class->mapField($mapping);
}
}
if (isset($element['embedMany'])) {
foreach ($element['embedMany'] as $fieldName => $embed) {
$mapping = $this->_getMappingFromEmbed($fieldName, $embed, 'many');
$class->mapField($mapping);
}
}
if (isset($element['referenceOne'])) {
foreach ($element['referenceOne'] as $fieldName => $reference) {
$mapping = $this->_getMappingFromReference($fieldName, $reference, 'one');
$class->mapField($mapping);
}
}
if (isset($element['referenceMany'])) {
foreach ($element['referenceMany'] as $fieldName => $reference) {
$mapping = $this->_getMappingFromReference($fieldName, $reference, 'many');
$class->mapField($mapping);
}
}
if (isset($element['lifecycleCallbacks'])) {
foreach ($element['lifecycleCallbacks'] as $type => $methods) {
foreach ($methods as $method) {
$class->addLifecycleCallback($method, constant('Doctrine\\ORM\\Events::' . $type));
}
}
}
}
示例11: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$xmlRoot = $this->getElement($className);
if (!$xmlRoot) {
return;
}
if ($xmlRoot->getName() == 'document') {
if (isset($xmlRoot['repository-class'])) {
$class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
}
} elseif ($xmlRoot->getName() == 'mapped-superclass') {
$class->isMappedSuperclass = true;
} elseif ($xmlRoot->getName() == 'embedded-document') {
$class->isEmbeddedDocument = true;
}
if (isset($xmlRoot['db'])) {
$class->setDB((string) $xmlRoot['db']);
}
if (isset($xmlRoot['collection'])) {
$class->setCollection((string) $xmlRoot['collection']);
}
if (isset($xmlRoot['indexes'])) {
foreach ($xmlRoot['indexes'] as $index) {
$class->addIndex((array) $index['keys'], (array) $index['options']);
}
}
if (isset($xmlRoot['customId']) && (string) $xmlRoot['customId'] === true) {
$class->setAllowCustomId(true);
}
if (isset($xmlRoot['inheritance-type'])) {
$inheritanceType = (string) $xmlRoot['inheritance-type'];
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
}
if (isset($xmlRoot->{'discriminator-field'})) {
$discrField = $xmlRoot->{'discriminator-field'};
$class->setDiscriminatorField(array('name' => (string) $discrField['name'], 'fieldName' => (string) $discrField['fieldName']));
}
if (isset($xmlRoot->{'discriminator-map'})) {
$map = array();
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
$map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
}
$class->setDiscriminatorMap($map);
}
if (isset($xmlRoot->{'change-tracking-policy'})) {
$class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot->{'change-tracking-policy'})));
}
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $field) {
$mapping = $this->getFieldMapping($field);
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'embed-one'})) {
foreach ($xmlRoot->{'embed-one'} as $embed) {
$mapping = $this->getEmbedMapping($embed, 'one');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'embed-many'})) {
foreach ($xmlRoot->{'embed-many'} as $embed) {
$mapping = $this->getEmbedMapping($embed, 'many');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'reference-many'})) {
foreach ($xmlRoot->{'reference-many'} as $reference) {
$mapping = $this->getReferenceMapping($reference, 'many');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'reference-one'})) {
foreach ($xmlRoot->{'reference-one'} as $reference) {
$mapping = $this->getReferenceMapping($reference, 'one');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ODM\\MongoDB\\ODMEvents::' . (string) $lifecycleCallback['type']));
}
}
}