Skip to content

Commit

Permalink
feat add support for ORM SchemaIgnoreClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod authored and ostrolucky committed Jun 10, 2022
1 parent 0c50581 commit d2088fc
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 4 deletions.
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
->append($this->getOrmCacheDriverNode('metadata_cache_driver'))
->append($this->getOrmCacheDriverNode('result_cache_driver'))
->append($this->getOrmEntityListenersNode())
->fixXmlConfig('schema_ignore_class', 'schema_ignore_classes')
->children()
->scalarNode('connection')->end()
->scalarNode('class_metadata_factory_name')->defaultValue(ClassMetadataFactory::class)->end()
Expand All @@ -602,6 +603,9 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
->scalarNode('quote_strategy')->defaultValue('doctrine.orm.quote_strategy.default')->end()
->scalarNode('entity_listener_resolver')->defaultNull()->end()
->scalarNode('repository_factory')->defaultValue('doctrine.orm.container_repository_factory')->end()
->arrayNode('schema_ignore_classes')
->prototype('scalar')->end()
->end()
->end()
->children()
->arrayNode('second_level_cache')
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
'setProxyDir' => '%doctrine.orm.proxy_dir%',
'setProxyNamespace' => '%doctrine.orm.proxy_namespace%',
'setAutoGenerateProxyClasses' => '%doctrine.orm.auto_generate_proxy_classes%',
'setSchemaIgnoreClasses' => $entityManager['schema_ignore_classes'],
'setClassMetadataFactoryName' => $entityManager['class_metadata_factory_name'],
'setDefaultRepositoryClassName' => $entityManager['default_repository_class'],
'setNamingStrategy' => new Reference($entityManager['naming_strategy']),
Expand Down
1 change: 1 addition & 0 deletions Resources/config/schema/doctrine-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
<xsd:element name="filter" type="filter" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="entity-listeners" type="entity_listeners" minOccurs="0" maxOccurs="1" />
<xsd:element name="second-level-cache" type="second-level-cache" minOccurs="0" maxOccurs="1" />
<xsd:element name="schema-ignore-class" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:choice>
</xsd:group>

Expand Down
6 changes: 6 additions & 0 deletions Resources/doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ Configuration Reference
# example
foo_param: bar_value
schema_ignore_classes:
- Acme\AppBundle\Entity\Order
- Acme\AppBundle\Entity\PhoneNumber
# Search for the "ResolveTargetEntityListener" class for a cookbook about this
resolve_target_entities:
Expand Down Expand Up @@ -729,6 +733,8 @@ Configuration Reference
</doctrine:filter>
<doctrine:schema-ignore-class>Acme\AppBundle\Entity\Order</doctrine:resolve-target-entity>
<doctrine:schema-ignore-class>Acme\AppBundle\Entity\PhoneNumber</doctrine:resolve-target-entity>
</doctrine:entity-manager>
<!-- example -->
Expand Down
13 changes: 13 additions & 0 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,19 @@ public function testResolveTargetEntity(): void
$this->assertEquals(['doctrine.event_subscriber' => [[]]], $tags);
}

public function testSchemaIgnoreClasses(): void
{
if (! interface_exists(EntityManagerInterface::class)) {
self::markTestSkipped('This test requires ORM');
}

$container = $this->loadContainer('orm_schema_ignore_classes');

$def1 = $container->getDefinition('doctrine.orm.em1_configuration');

$this->assertDICDefinitionMethodCallOnce($def1, 'setSchemaIgnoreClasses', [0 => ['Class\A', 'Class\B']]);
}

public function testAttachEntityListeners(): void
{
if (! interface_exists(EntityManagerInterface::class)) {
Expand Down
6 changes: 3 additions & 3 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ public function testDependencyInjectionConfigurationDefaults(): void
$this->assertEquals('doctrine.orm.default_query_cache', (string) $calls[2][1][0]);
$this->assertEquals('doctrine.orm.default_result_cache', (string) $calls[3][1][0]);

$this->assertEquals('doctrine.orm.naming_strategy.default', (string) $calls[10][1][0]);
$this->assertEquals('doctrine.orm.quote_strategy.default', (string) $calls[11][1][0]);
$this->assertEquals('doctrine.orm.default_entity_listener_resolver', (string) $calls[12][1][0]);
$this->assertEquals('doctrine.orm.naming_strategy.default', (string) $calls[11][1][0]);
$this->assertEquals('doctrine.orm.quote_strategy.default', (string) $calls[12][1][0]);
$this->assertEquals('doctrine.orm.default_entity_listener_resolver', (string) $calls[13][1][0]);

$definition = $container->getDefinition('doctrine.orm.default_metadata_cache_warmer');
$this->assertSame(DoctrineMetadataCacheWarmer::class, $definition->getClass());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>

<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<dbal default-connection="default">
</dbal>

<orm default-entity-manager="em1">
<entity-manager name="em1">
<schema-ignore-class>Class\A</schema-ignore-class>
<schema-ignore-class>Class\B</schema-ignore-class>
</entity-manager>
</orm>
</config>
</srv:container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
doctrine:
dbal:
default_connection: default

orm:
entity_managers:
em1:
schema_ignore_classes:
- Class\A
- Class\B
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"require-dev": {
"doctrine/coding-standard": "^9.0",
"doctrine/orm": "^2.10 || ^3.0",
"doctrine/orm": "^2.11 || ^3.0",
"friendsofphp/proxy-manager-lts": "^1.0",
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.3 || ^10.0",
"psalm/plugin-phpunit": "^0.16.1",
Expand Down

0 comments on commit d2088fc

Please sign in to comment.