本文整理汇总了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo::setCustomRepositoryClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataInfo::setCustomRepositoryClass方法的具体用法?PHP ClassMetadataInfo::setCustomRepositoryClass怎么用?PHP ClassMetadataInfo::setCustomRepositoryClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo
的用法示例。
在下文中一共展示了ClassMetadataInfo::setCustomRepositoryClass方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* @param \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
* @param string $document
* @param array $fields
* @param Boolean $withRepository
* @throws \RuntimeException
*/
public function generate(BundleInterface $bundle, $document, array $fields, $withRepository)
{
$config = $this->documentManager->getConfiguration();
$config->addDocumentNamespace($bundle->getName(), $bundle->getNamespace() . '\\Document');
$documentClass = $config->getDocumentNamespace($bundle->getName()) . '\\' . $document;
$documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php';
if (file_exists($documentPath)) {
throw new \RuntimeException(sprintf('Document "%s" already exists.', $documentClass));
}
$class = new ClassMetadataInfo($documentClass);
if ($withRepository) {
$class->setCustomRepositoryClass($documentClass . 'Repository');
}
$class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
foreach ($fields as $field) {
$class->mapField($field);
}
$documentGenerator = $this->getDocumentGenerator();
$documentCode = $documentGenerator->generateDocumentClass($class);
$this->filesystem->mkdir(dirname($documentPath));
file_put_contents($documentPath, rtrim($documentCode) . PHP_EOL, LOCK_EX);
if ($withRepository) {
$path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
$this->getRepositoryGenerator()->writeDocumentRepositoryClass($class->customRepositoryClassName, $path);
}
}
示例2: setCustomRepositoryClasses
private function setCustomRepositoryClasses(ClassMetadataInfo $metadata)
{
foreach ($this->classes as $class) {
if (array_key_exists('model', $class) && $class['model'] === $metadata->getName()) {
$metadata->isMappedSuperclass = false;
if (array_key_exists('repository', $class)) {
$metadata->setCustomRepositoryClass($class['repository']);
}
}
}
}
示例3: convertToDocumentIfNeeded
/**
* @param ClassMetadataInfo $metadata
*/
private function convertToDocumentIfNeeded(ClassMetadataInfo $metadata)
{
foreach ($this->resourceRegistry->getAll() as $alias => $resourceMetadata) {
if ($metadata->getName() !== $resourceMetadata->getClass('model')) {
continue;
}
if ($resourceMetadata->hasClass('repository')) {
$metadata->setCustomRepositoryClass($resourceMetadata->getClass('repository'));
}
$metadata->isMappedSuperclass = false;
}
}
示例4: setCustomRepositoryClasses
private function setCustomRepositoryClasses(ClassMetadataInfo $metadata)
{
foreach ($this->classes as $application => $classes) {
foreach ($classes as $class) {
if (isset($class['model']) && $class['model'] === $metadata->getName()) {
$metadata->isMappedSuperclass = false;
if (isset($class['repository'])) {
$metadata->setCustomRepositoryClass($class['repository']);
}
}
}
}
}
示例5: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadataInfo $class)
{
$reflClass = $class->getReflectionClass();
$classAnnotations = $this->reader->getClassAnnotations($reflClass);
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Document'])) {
$documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Document'];
} elseif (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\MappedSuperclass'])) {
$documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\MappedSuperclass'];
$class->isMappedSuperclass = true;
} elseif (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\EmbeddedDocument'])) {
$documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\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\\Annotations\\Indexes'])) {
$indexes = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Indexes']->value;
$indexes = is_array($indexes) ? $indexes : array($indexes);
foreach ($indexes as $index) {
$this->addIndex($class, $index);
}
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Index'])) {
$index = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Index'];
$this->addIndex($class, $index);
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\UniqueIndex'])) {
$index = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\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\\Annotations\\InheritanceType'])) {
$inheritanceTypeAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\InheritanceType'];
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorField'])) {
$discrFieldAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorField'];
$class->setDiscriminatorField(array('fieldName' => $discrFieldAnnot->fieldName));
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorMap'])) {
$discrMapAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorMap'];
$class->setDiscriminatorMap($discrMapAnnot->value);
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorValue'])) {
$discrValueAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorValue'];
$class->setDiscriminatorValue($discrValueAnnot->value);
}
if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ChangeTrackingPolicy'])) {
$changeTrackingAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\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\\Annotations\\AlsoLoad')) {
$mapping['alsoLoadFields'] = (array) $alsoLoad->value;
}
if ($notSaved = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\NotSaved')) {
$mapping['notSaved'] = true;
}
if ($versionAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Version')) {
$mapping['version'] = true;
}
if ($versionAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Lock')) {
$mapping['lock'] = true;
}
$indexes = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Indexes');
$indexes = $indexes ? $indexes : array();
if ($index = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Index')) {
$indexes[] = $index;
}
if ($index = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\UniqueIndex')) {
$indexes[] = $index;
}
foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
if ($fieldAnnot instanceof \Doctrine\ODM\MongoDB\Mapping\Annotations\AbstractField) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$class->mapField($mapping);
}
}
//.........这里部分代码省略.........
示例6: testSetCustomRepositoryClass
public function testSetCustomRepositoryClass()
{
$cm = new ClassMetadataInfo('Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\ClassMetadataInfoTest');
$cm->namespace = 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping';
$cm->setCustomRepositoryClass('TestCustomRepositoryClass');
$this->assertEquals('Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\TestCustomRepositoryClass', $cm->customRepositoryClassName);
$cm->setCustomRepositoryClass('Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\TestCustomRepositoryClass');
$this->assertEquals('Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\TestCustomRepositoryClass', $cm->customRepositoryClassName);
}
示例7: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadataInfo $class)
{
$element = $this->getElement($className);
if ( ! $element) {
return;
}
$element['type'] = isset($element['type']) ? $element['type'] : 'document';
if (isset($element['db'])) {
$class->setDatabase($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, ClassMetadataInfo $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', 'file', 'distance');
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']));
}
}
}