Skip to content

Commit c0e7dff

Browse files
committed
backport container aware
1 parent 321955f commit c0e7dff

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

CHANGELOG.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
CHANGELOG
22
=========
33

4+
1.x
5+
===
6+
7+
1.6.0
8+
-----
9+
10+
* Deprecate using `Symfony\Component\DependencyInjection\ContainerAwareInterface` in favor of
11+
`PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface` as Symfony 7 dropped its
12+
ContainerAwareInterface.
13+
On Symfony 6, the legacy ContainerAwareInterface continues to e supported.
14+
415
1.5.0
516
-----
617

7-
* Allow installation with Symfony 7
18+
* Allow installation with Symfony 7 (! broken if you use `Symfony\Component\DependencyInjection\ContainerAwareInterface`)
819
* Drop support for PHP < 8.1 and modernize code
920

1021
1.4.0

src/Command/MigrateCommand.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
namespace PHPCR\PhpcrMigrationsBundle\Command;
1313

1414
use PHPCR\Migrations\MigratorFactory;
15+
use PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface;
1516
use Symfony\Component\Console\Command\Command;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Output\OutputInterface;
19-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
20+
use Symfony\Component\DependencyInjection\ContainerAwareInterface as SymfonyContainerAwareInterface;
2021
use Symfony\Component\DependencyInjection\ContainerInterface;
2122

2223
class MigrateCommand extends Command
@@ -77,6 +78,9 @@ public function execute(InputInterface $input, OutputInterface $output): int
7778
foreach ($migrator->getVersions() as $version) {
7879
if ($version instanceof ContainerAwareInterface) {
7980
$version->setContainer($this->container);
81+
} elseif ($version instanceof SymfonyContainerAwareInterface) {
82+
$version->setContainer($this->container);
83+
@trigger_error('Relying on '.SymfonyContainerAwareInterface::class.' is deprecated and will break when upgrading to Symfony 7. Use '.ContainerAwareInterface::class.' instead.', \E_USER_DEPRECATED);
8084
}
8185
}
8286

src/ContainerAwareInterface.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHPCR Migrations package
5+
*
6+
* (c) Daniel Leech <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace PHPCR\PhpcrMigrationsBundle;
13+
14+
use Symfony\Component\DependencyInjection\ContainerInterface;
15+
16+
/**
17+
* Interface for migrations to get the Symfony container injected.
18+
*/
19+
interface ContainerAwareInterface
20+
{
21+
public function setContainer(?ContainerInterface $container = null): void;
22+
}

tests/Resources/Bundle/TwoTestBundle/Resources/phpcr-migrations/Version201401011300.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
*/
1111

1212
use PHPCR\Migrations\VersionInterface;
13+
use PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface;
1314
use PHPCR\SessionInterface;
14-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
1616

1717
class Version201401011300 implements VersionInterface, ContainerAwareInterface
1818
{
1919
private $container;
2020

21-
public function setContainer(?ContainerInterface $container = null)
21+
public function setContainer(?ContainerInterface $container = null): void
2222
{
2323
$this->container = $container;
2424
}

0 commit comments

Comments
 (0)