diff --git a/src/DependencyInjection/DoctrineMongoDBExtension.php b/src/DependencyInjection/DoctrineMongoDBExtension.php index b4b23847..44c5c4a9 100644 --- a/src/DependencyInjection/DoctrineMongoDBExtension.php +++ b/src/DependencyInjection/DoctrineMongoDBExtension.php @@ -25,6 +25,8 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations\View; use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; +use Doctrine\Persistence\Mapping\Driver\PHPDriver; +use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver; use Doctrine\Persistence\Proxy; use InvalidArgumentException; use LogicException; @@ -326,7 +328,7 @@ protected function assertValidMappingConfiguration( } if (! in_array($mappingConfig['type'], ['xml', 'php', 'staticphp', 'attribute'])) { - throw new InvalidArgumentException(sprintf('Can only configure "xml", "yml", "php", "staticphp" or "attribute" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. You can register them by adding a new driver to the "%s" service definition.', $this->getObjectManagerElementName($objectManagerName . '_metadata_driver'))); + throw new InvalidArgumentException(sprintf('Can only configure "xml", "php", "staticphp" or "attribute" through the DoctrineMongoDBBundle. Use your own bundle to configure other metadata drivers. You can register them by adding a new driver to the "%s" service definition.', $this->getObjectManagerElementName($objectManagerName . '_metadata_driver'))); } } @@ -1024,6 +1026,8 @@ protected function getMetadataDriverClass(string $driverType): string return match ($driverType) { 'driver_chain' => MappingDriverChain::class, 'attribute' => AttributeDriver::class, + 'staticphp' => StaticPHPDriver::class, + 'php' => PHPDriver::class, 'xml' => XmlDriver::class, default => throw new InvalidArgumentException(sprintf('Metadata driver not supported: "%s"', $driverType)) }; diff --git a/src/Mapping/StaticClassMetadata.php b/src/Mapping/StaticClassMetadata.php new file mode 100644 index 00000000..f5429ae2 --- /dev/null +++ b/src/Mapping/StaticClassMetadata.php @@ -0,0 +1,12 @@ +mapField([ + 'name' => '_id', + 'fieldName' => 'id', + 'type' => Type::ID, + 'id' => true, + ]); + $metadata->mapField([ + 'name' => 'name', + 'fieldName' => 'name', + 'type' => Type::STRING, + ]); +}; diff --git a/tests/DependencyInjection/Fixtures/Bundles/StaticPhpBundle/Document/TestDocument.php b/tests/DependencyInjection/Fixtures/Bundles/StaticPhpBundle/Document/TestDocument.php new file mode 100644 index 00000000..f214cf83 --- /dev/null +++ b/tests/DependencyInjection/Fixtures/Bundles/StaticPhpBundle/Document/TestDocument.php @@ -0,0 +1,27 @@ +mapField([ + 'name' => '_id', + 'fieldName' => 'id', + 'type' => Type::ID, + 'id' => true, + ]); + $metadata->mapField([ + 'name' => 'name', + 'fieldName' => 'name', + 'type' => Type::STRING, + ]); + } +} diff --git a/tests/DependencyInjection/Fixtures/Bundles/StaticPhpBundle/StaticPhpBundle.php b/tests/DependencyInjection/Fixtures/Bundles/StaticPhpBundle/StaticPhpBundle.php new file mode 100644 index 00000000..81e3de21 --- /dev/null +++ b/tests/DependencyInjection/Fixtures/Bundles/StaticPhpBundle/StaticPhpBundle.php @@ -0,0 +1,11 @@ +