Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for Symfony 4 #1586

Merged
merged 1 commit into from Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 2 additions & 8 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -39,13 +39,7 @@ jobs:
php-version: "7.4"
symfony-deprecations-helper: "weak"

# Test legacy LTS
- symfony-require: "4.4.*"
dependencies: "stable"
php-version: "7.4"
symfony-deprecations-helper: "weak"

# Test latest LTS
# Test LTS
- symfony-require: "5.4.*"
dependencies: "highest"
php-version: "8.0"
Expand Down Expand Up @@ -82,7 +76,7 @@ jobs:

- name: "Require symfony/messenger"
run: "composer require --dev symfony/messenger --no-update"
if: "${{ startsWith(matrix.symfony-require, '4.') }}"
if: "${{ startsWith(matrix.symfony-require, '5.') }}"
derrabus marked this conversation as resolved.
Show resolved Hide resolved

- name: "Enforce using stable dependencies"
run: "composer config minimum-stability stable"
Expand Down
2 changes: 0 additions & 2 deletions DependencyInjection/Compiler/CacheSchemaSubscriberPass.php
Expand Up @@ -20,8 +20,6 @@ class CacheSchemaSubscriberPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
// available in Symfony 5.4 and higher
/** @psalm-suppress UndefinedClass */
$this->injectAdapters($container, 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_subscriber', DoctrineDbalAdapter::class);

// available in Symfony 5.1 and up to Symfony 5.4 (deprecated)
Expand Down
43 changes: 14 additions & 29 deletions DependencyInjection/Configuration.php
Expand Up @@ -7,7 +7,6 @@
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use ReflectionClass;
use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand All @@ -30,7 +29,6 @@
use function is_int;
use function is_string;
use function key;
use function method_exists;
use function reset;
use function sprintf;
use function strlen;
Expand Down Expand Up @@ -115,7 +113,9 @@ private function addDbalSection(ArrayNodeDefinition $node): void
->scalarNode('class')->isRequired()->end()
->booleanNode('commented')
->setDeprecated(
...$this->getDeprecationMsg('The doctrine-bundle type commenting features were removed; the corresponding config parameter was deprecated in 2.0 and will be dropped in 3.0.', '2.0')
'doctrine/doctrine-bundle',
'2.0',
'The doctrine-bundle type commenting features were removed; the corresponding config parameter was deprecated in 2.0 and will be dropped in 3.0.',
)
->end()
->end()
Expand Down Expand Up @@ -173,7 +173,9 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
->scalarNode('wrapper_class')->end()
->booleanNode('keep_slave')
->setDeprecated(
...$this->getDeprecationMsg('The "keep_slave" configuration key is deprecated since doctrine-bundle 2.2. Use the "keep_replica" configuration key instead.', '2.2')
'doctrine/doctrine-bundle',
'2.2',
'The "keep_slave" configuration key is deprecated since doctrine-bundle 2.2. Use the "keep_replica" configuration key instead.',
)
->end()
->booleanNode('keep_replica')->end()
Expand All @@ -200,7 +202,9 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
->children()
->arrayNode('slaves')
->setDeprecated(
...$this->getDeprecationMsg('The "slaves" configuration key will be renamed to "replicas" in doctrine-bundle 3.0. "slaves" is deprecated since doctrine-bundle 2.2.', '2.2')
'doctrine/doctrine-bundle',
'2.2',
'The "slaves" configuration key will be renamed to "replicas" in doctrine-bundle 3.0. "slaves" is deprecated since doctrine-bundle 2.2.',
)
->useAttributeAsKey('name')
->prototype('array');
Expand Down Expand Up @@ -255,7 +259,11 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node): void
->scalarNode('port')->info('Defaults to null at runtime.')->end()
->scalarNode('user')->info('Defaults to "root" at runtime.')->end()
->scalarNode('password')->info('Defaults to null at runtime.')->end()
->booleanNode('override_url')->setDeprecated(...$this->getDeprecationMsg('The "doctrine.dbal.override_url" configuration key is deprecated.', '2.4'))->end()
->booleanNode('override_url')->setDeprecated(
'doctrine/doctrine-bundle',
'2.4',
'The "doctrine.dbal.override_url" configuration key is deprecated.',
)->end()
->scalarNode('dbname_suffix')->end()
->scalarNode('application_name')->end()
->scalarNode('charset')->end()
Expand Down Expand Up @@ -775,27 +783,4 @@ private function getAutoGenerateModes(): array
'values' => $valuesArray,
];
}

/**
* Returns the correct deprecation param's as an array for setDeprecated.
*
* Symfony/Config v5.1 introduces a deprecation notice when calling
* setDeprecation() with less than 3 args and the getDeprecation method was
* introduced at the same time. By checking if getDeprecation() exists,
* we can determine the correct param count to use when calling setDeprecated.
*
* @return list<string>|array{0:string, 1: numeric-string, string}
*/
private function getDeprecationMsg(string $message, string $version): array
{
if (method_exists(BaseNode::class, 'getDeprecation')) {
return [
'doctrine/doctrine-bundle',
$version,
$message,
];
}

return [$message];
}
}
137 changes: 31 additions & 106 deletions DependencyInjection/DoctrineExtension.php
Expand Up @@ -31,14 +31,8 @@
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware;
use Symfony\Bridge\Doctrine\Middleware\Debug\Middleware as SfDebugMiddleware;
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaSubscriber;
use Symfony\Bridge\Doctrine\SchemaListener\MessengerTransportDoctrineSchemaSubscriber;
use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber;
use Symfony\Bridge\Doctrine\SchemaListener\RememberMeTokenProviderDoctrineSchemaSubscriber;
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
Expand All @@ -51,7 +45,6 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
Expand All @@ -61,13 +54,10 @@
use function class_exists;
use function interface_exists;
use function is_dir;
use function method_exists;
use function reset;
use function sprintf;
use function str_replace;

use const PHP_VERSION_ID;

/**
* DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
*/
Expand Down Expand Up @@ -158,19 +148,17 @@ protected function dbalLoad(array $config, ContainerBuilder $container)

$container->registerForAutoconfiguration(MiddlewareInterface::class)->addTag('doctrine.middleware');

if (PHP_VERSION_ID >= 80000 && method_exists(ContainerBuilder::class, 'registerAttributeForAutoconfiguration')) {
$container->registerAttributeForAutoconfiguration(AsMiddleware::class, static function (ChildDefinition $definition, AsMiddleware $attribute) {
if ($attribute->connections === []) {
$definition->addTag('doctrine.middleware');
$container->registerAttributeForAutoconfiguration(AsMiddleware::class, static function (ChildDefinition $definition, AsMiddleware $attribute) {
if ($attribute->connections === []) {
$definition->addTag('doctrine.middleware');

return;
}
return;
}

foreach ($attribute->connections as $connName) {
$definition->addTag('doctrine.middleware', ['connection' => $connName]);
}
});
}
foreach ($attribute->connections as $connName) {
$definition->addTag('doctrine.middleware', ['connection' => $connName]);
}
});

$this->useMiddlewaresIfAvailable($container, $connWithLogging, $connWithProfiling, $connWithBacktrace);
}
Expand All @@ -185,24 +173,11 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
protected function loadDbalConnection($name, array $connection, ContainerBuilder $container)
{
$configuration = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), new ChildDefinition('doctrine.dbal.connection.configuration'));
$logger = null;
unset($connection['logging']);

$dataCollectorDefinition = $container->getDefinition('data_collector.doctrine');
$dataCollectorDefinition->replaceArgument(1, $connection['profiling_collect_schema_errors']);

if (! $this->isSfDebugMiddlewareAvailable() && $connection['profiling']) {
$profilingAbstractId = $connection['profiling_collect_backtrace'] ?
'doctrine.dbal.logger.backtrace' :
'doctrine.dbal.logger.profiling';

$profilingLoggerId = $profilingAbstractId . '.' . $name;
$container->setDefinition($profilingLoggerId, new ChildDefinition($profilingAbstractId));
$profilingLogger = new Reference($profilingLoggerId);
$dataCollectorDefinition->addMethodCall('addLogger', [$name, $profilingLogger]);
$logger = $profilingLogger;
}

unset(
$connection['profiling'],
$connection['profiling_collect_backtrace'],
Expand All @@ -223,10 +198,6 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder

unset($connection['schema_filter']);

if ($logger) {
$configuration->addMethodCall('setSQLLogger', [$logger]);
}

// event manager
$container->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), new ChildDefinition('doctrine.dbal.connection.event_manager'));

Expand Down Expand Up @@ -400,21 +371,11 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->getDefinition('form.type.entity')->addTag('kernel.reset', ['method' => 'reset']);
}

// available in Symfony 5.4 and higher
if (! class_exists(DoctrineDbalCacheAdapterSchemaSubscriber::class)) {
$container->removeDefinition('doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_subscriber');
}

// available in Symfony 5.1 and up to Symfony 5.4 (deprecated)
if (! class_exists(PdoCacheAdapterDoctrineSchemaSubscriber::class)) {
$container->removeDefinition('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber');
}

// available in Symfony 5.3 and higher
if (! class_exists(RememberMeTokenProviderDoctrineSchemaSubscriber::class)) {
$container->removeDefinition('doctrine.orm.listeners.doctrine_token_provider_schema_subscriber');
}

if (! class_exists(UlidGenerator::class)) {
$container->removeDefinition('doctrine.ulid_generator');
}
Expand Down Expand Up @@ -535,25 +496,22 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->registerForAutoconfiguration(AbstractIdGenerator::class)
->addTag(IdGeneratorPass::ID_GENERATOR_TAG);

/** @psalm-suppress RedundantCondition */
if (method_exists($container, 'registerAttributeForAutoconfiguration')) {
$container->registerAttributeForAutoconfiguration(AsEntityListener::class, static function (ChildDefinition $definition, AsEntityListener $attribute) {
$definition->addTag('doctrine.orm.entity_listener', [
'event' => $attribute->event,
'method' => $attribute->method,
'lazy' => $attribute->lazy,
'entity_manager' => $attribute->entityManager,
'entity' => $attribute->entity,
]);
});
$container->registerAttributeForAutoconfiguration(AsEventListener::class, static function (ChildDefinition $definition, AsEventListener $attribute) {
$definition->addTag('doctrine.event_listener', [
'event' => $attribute->event,
'priority' => $attribute->priority,
'connection' => $attribute->connection,
]);
});
}
$container->registerAttributeForAutoconfiguration(AsEntityListener::class, static function (ChildDefinition $definition, AsEntityListener $attribute) {
$definition->addTag('doctrine.orm.entity_listener', [
'event' => $attribute->event,
'method' => $attribute->method,
'lazy' => $attribute->lazy,
'entity_manager' => $attribute->entityManager,
'entity' => $attribute->entity,
]);
});
$container->registerAttributeForAutoconfiguration(AsEventListener::class, static function (ChildDefinition $definition, AsEventListener $attribute) {
$definition->addTag('doctrine.event_listener', [
'event' => $attribute->event,
'priority' => $attribute->priority,
'connection' => $attribute->connection,
]);
});

/** @see DoctrineBundle::boot() */
$container->getDefinition($defaultEntityManagerDefinitionId)
Expand Down Expand Up @@ -1034,34 +992,12 @@ private function loadMessengerServices(ContainerBuilder $container): void
{
// If the Messenger component is installed and the doctrine transaction middleware is available, wire it:
/** @psalm-suppress UndefinedClass Optional dependency */
if (! interface_exists(MessageBusInterface::class) || ! class_exists(DoctrineTransactionMiddleware::class)) {
if (! interface_exists(MessageBusInterface::class)) {
return;
}

$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('messenger.xml');

if (! class_exists(DoctrineClearEntityManagerWorkerSubscriber::class)) {
$container->removeDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager');
}

// available in Symfony 5.1 and higher
if (! class_exists(MessengerTransportDoctrineSchemaSubscriber::class)) {
$container->removeDefinition('doctrine.orm.messenger.doctrine_schema_subscriber');
}

$transportFactoryDefinition = $container->getDefinition('messenger.transport.doctrine.factory');
if (! class_exists(DoctrineTransportFactory::class)) {
// If symfony/messenger < 5.1
if (! class_exists(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class)) {
// Dont add the tag
return;
}

$transportFactoryDefinition->setClass(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class);
}

$transportFactoryDefinition->addTag('messenger.transport_factory');
}

private function createArrayAdapterCachePool(ContainerBuilder $container, string $objectManagerName, string $cacheName): string
Expand Down Expand Up @@ -1098,22 +1034,11 @@ private function useMiddlewaresIfAvailable(
$loggingMiddlewareAbstractDef->addTag('doctrine.middleware', ['connection' => $connName]);
}

if ($this->isSfDebugMiddlewareAvailable()) {
$container->getDefinition('doctrine.debug_data_holder')->replaceArgument(0, $connWithBacktrace);
$debugMiddlewareAbstractDef = $container->getDefinition('doctrine.dbal.debug_middleware');
foreach ($connWithProfiling as $connName) {
$debugMiddlewareAbstractDef
->addTag('doctrine.middleware', ['connection' => $connName]);
}
} else {
$container->removeDefinition('doctrine.dbal.debug_middleware');
$container->removeDefinition('doctrine.debug_data_holder');
$container->getDefinition('doctrine.debug_data_holder')->replaceArgument(0, $connWithBacktrace);
$debugMiddlewareAbstractDef = $container->getDefinition('doctrine.dbal.debug_middleware');
foreach ($connWithProfiling as $connName) {
$debugMiddlewareAbstractDef
->addTag('doctrine.middleware', ['connection' => $connName]);
}
}

private function isSfDebugMiddlewareAvailable(): bool
{
/** @psalm-suppress UndefinedClass */
return class_exists(SfDebugMiddleware::class);
}
}
1 change: 1 addition & 0 deletions Resources/config/messenger.xml
Expand Up @@ -44,6 +44,7 @@
-->
<service id="messenger.transport.doctrine.factory" class="Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory" public="false">
<argument type="service" id="doctrine" />
<tag name="messenger.transport_factory" />
</service>

<service id="doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager" class="Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber" public="false">
Expand Down
5 changes: 0 additions & 5 deletions Tests/CacheSchemaSubscriberTest.php
Expand Up @@ -90,11 +90,6 @@ public function testSchemaSubscriberWiring(string $adapterId, string $subscriber

public function getSchemaSubscribers(): Generator
{
/**
* available in Symfony 5.4 and higher
*
* @psalm-suppress UndefinedClass
*/
yield ['cache.adapter.doctrine_dbal', 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_subscriber', DoctrineDbalCacheAdapterSchemaSubscriber::class];

/**
Expand Down