diff --git a/composer.json b/composer.json index 34e37fae..28cef46c 100644 --- a/composer.json +++ b/composer.json @@ -69,6 +69,7 @@ } }, "suggest": { + "laravel-doctrine/fluent": "Fluent mapping driver (alternative to xml, yaml, ... (~2.0).", "fzaninotto/faker": "Required to use the entity factory builder (~1.4).", "laravel-doctrine/acl": "to integrate Doctrine roles & permissions with Laravel's Authorization system (~1.0)", "laravel-doctrine/extensions": "to add Behavioral and Query/Type Extensions for Laravel Doctrine (~1.0)", diff --git a/docs/configuration.rst b/docs/configuration.rst index b9e9df67..26fa22bd 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -35,7 +35,7 @@ Within the entity manager name array are configuration settings. These are conditional clauses of queries, regardless the place where the SQL is generated * ``mapping_types`` - Link a database type to a local Doctrine type * ``meta`` - The type of metadata configuration. Valid values are - ``attributes``, ``xml``, ``simplified_xml``, ``static_php``, ``php``. + ``attributes``, ``fluent``, ``xml``, ``simplified_xml``, ``static_php``, ``php``. The majority of configurations use ``attributes`` or ``xml`` and these metadata configurations are recommended. * ``namespaces`` - If your entities are not located in the configured app diff --git a/src/Configuration/MetaData/Fluent.php b/src/Configuration/MetaData/Fluent.php new file mode 100644 index 00000000..d7b43c97 --- /dev/null +++ b/src/Configuration/MetaData/Fluent.php @@ -0,0 +1,65 @@ +getNamingStrategy($settings); + + $driver->setFluentFactory(static function (ClassMetadata $meta) use ($namingStrategy) { + return new Builder(new ClassMetadataBuilder($meta), $namingStrategy); + }); + + return $driver; + } + + /** + * @param mixed[] $settings + * + * @throws BindingResolutionException + */ + protected function getNamingStrategy(array $settings = []): mixed + { + return $this->container->make(Arr::get($settings, 'naming_strategy', LaravelNamingStrategy::class)); + } + + /** + * @param mixed[] $settings + * + * @throws BindingResolutionException + */ + protected function getQuoteStrategy(array $settings = []): mixed + { + return $this->container->make(Arr::get($settings, 'quote_strategy')); + } + + public function getClassMetadataFactoryName(): string + { + return ExtensibleClassMetadataFactory::class; + } +} diff --git a/tests/Feature/EntityManagerFactoryTest.php b/tests/Feature/EntityManagerFactoryTest.php index af9434a2..a311f8ac 100644 --- a/tests/Feature/EntityManagerFactoryTest.php +++ b/tests/Feature/EntityManagerFactoryTest.php @@ -918,6 +918,7 @@ protected function mockORMConfiguration(): void { $this->configuration = m::mock(Configuration::class); $this->configuration->shouldReceive('setSQLLogger'); + $this->configuration->shouldReceive('isNativeLazyObjectsEnabled'); $this->configuration->shouldReceive('getMetadataDriverImpl') ->andReturn($this->mappingDriver); @@ -925,7 +926,7 @@ protected function mockORMConfiguration(): void $this->configuration->shouldReceive('setMetadataDriverImpl') ->atLeast()->once(); $this->configuration->shouldReceive('setMiddlewares') - ->atLeast()->once(); + ->atLeast()->once(); $this->configuration->shouldReceive('getAutoCommit') ->atLeast()->once()