Skip to content

Commit

Permalink
Integrate with symfony/deprecation-contracts
Browse files Browse the repository at this point in the history
We decided against use of doctrine/deprecations here, otherwise we would be forced to use mixed deprecations approach, which would increase complexity in our test suite when handling deprecations there.

Rel: #1300
  • Loading branch information
ostrolucky committed May 28, 2021
1 parent cff8a85 commit 7898211
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 29 deletions.
12 changes: 7 additions & 5 deletions Command/Proxy/ClearMetadataCacheDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;
use function trigger_deprecation;

/**
* Command to clear the metadata cache of the various cache drivers.
Expand Down Expand Up @@ -42,7 +39,12 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@trigger_error(sprintf('The "%s" (doctrine:cache:clear-metadata) is deprecated, metadata cache now uses PHP Array cache which can not be cleared.', self::class), E_USER_DEPRECATED);
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.3',
'The "%s" (doctrine:cache:clear-metadata) is deprecated, metadata cache now uses PHP Array cache which can not be cleared.',
self::class
);

DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

Expand Down
12 changes: 7 additions & 5 deletions Command/Proxy/ImportDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;
use function trigger_deprecation;

/**
* Loads an SQL file and executes it.
Expand All @@ -36,7 +33,12 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@trigger_error(sprintf('The "%s" (doctrine:database:import) command is deprecated, use a database client instead.', self::class), E_USER_DEPRECATED);
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.2',
'The "%s" (doctrine:database:import) is deprecated, use a database client instead.',
self::class
);

DoctrineCommandHelper::setApplicationConnection($this->getApplication(), $input->getOption('connection'));

Expand Down
12 changes: 7 additions & 5 deletions Command/Proxy/RunSqlDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;
use function trigger_deprecation;

/**
* Execute a SQL query and output the results.
Expand Down Expand Up @@ -59,7 +56,12 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@trigger_error(sprintf('The "%s" (doctrine:query:sql) is deprecated, use dbal:run-sql command instead.', self::class), E_USER_DEPRECATED);
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.2',
'The "%s" (doctrine:query:sql) is deprecated, use dbal:run-sql command instead.',
self::class
);

if (! $this->connectionProvider) {
DoctrineCommandHelper::setApplicationConnection($this->getApplication(), $input->getOption('connection'));
Expand Down
5 changes: 2 additions & 3 deletions ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
use function array_merge;
use function class_exists;
use function is_subclass_of;
use function trigger_error;
use function trigger_deprecation;

use const E_USER_DEPRECATED;
use const PHP_EOL;

/** @psalm-import-type Params from DriverManager */
Expand Down Expand Up @@ -53,7 +52,7 @@ public function createConnection(array $params, ?Configuration $config = null, ?

$overriddenOptions = [];
if (isset($params['connection_override_options'])) {
@trigger_error('The "connection_override_options" connection parameter is deprecated since DoctrineBundle 2.4.', E_USER_DEPRECATED);
trigger_deprecation('doctrine/doctrine-bundle', '2.4', 'The "connection_override_options" connection parameter is deprecated');
$overriddenOptions = $params['connection_override_options'];
unset($params['connection_override_options']);
}
Expand Down
13 changes: 8 additions & 5 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
use function strpos;
use function strtoupper;
use function substr;
use function trigger_error;

use const E_USER_DEPRECATED;
use function trigger_deprecation;

/**
* This class contains the configuration information for the bundle
Expand Down Expand Up @@ -255,8 +253,13 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node): void

if ($urlConflictingValues) {
$tail = count($urlConflictingValues) > 1 ? sprintf('or "%s" options', array_pop($urlConflictingValues)) : 'option';

@trigger_error(sprintf('Setting the "doctrine.dbal.%s" %s while the "url" one is defined is deprecated since DoctrineBundle 2.4.', implode('", "', $urlConflictingValues), $tail), E_USER_DEPRECATED);
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.4',
'Setting the "doctrine.dbal.%s" %s while the "url" one is defined is deprecated',
implode('", "', $urlConflictingValues),
$tail
);
}

return $values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
/** @group legacy */
public function testMetadataCacheConfigUsingPsr6ServiceDefinedByApplication(): void
{
$this->expectDeprecation('Since doctrine/doctrine-bundle 2.3: The "metadata_cache_driver" configuration key is deprecated. PHP Array cache is now automatically registered when %kernel.debug% is false.');
$this->expectDeprecation('%aThe "metadata_cache_driver" configuration key is deprecated.%a');
(new class () extends TestKernel {
public function registerContainerConfiguration(LoaderInterface $loader): void
{
Expand Down
11 changes: 7 additions & 4 deletions Twig/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
use function sprintf;
use function strtoupper;
use function substr;
use function trigger_error;

use const E_USER_DEPRECATED;
use function trigger_deprecation;

/**
* This class contains the needed functions in order to do the query highlighting
Expand Down Expand Up @@ -147,7 +145,12 @@ static function ($matches) use ($parameters, &$i) {
*/
public function formatQuery($sql, $highlightOnly = false)
{
@trigger_error(sprintf('The "%s()" method is deprecated and will be removed in DoctrineBundle 3.0.', __METHOD__), E_USER_DEPRECATED);
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.1',
'The "%s()" method is deprecated and will be removed in doctrine-bundle 3.0.',
__METHOD__
);

$this->setUpSqlFormatter(true, true);

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"require-dev": {
"doctrine/coding-standard": "^9.0",
"doctrine/orm": "^2.9-dev",
"doctrine/orm": "^2.9",
"friendsofphp/proxy-manager-lts": "^1.0",
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.3",
"psalm/plugin-phpunit": "^0.15.1",
Expand Down

0 comments on commit 7898211

Please sign in to comment.