Skip to content

Commit d59c4a9

Browse files
authored
Merge pull request #7 from phpcr/backport-container-aware
backport container aware
2 parents 321955f + fcc932e commit d59c4a9

File tree

12 files changed

+90
-29
lines changed

12 files changed

+90
-29
lines changed

.github/workflows/ci.yaml

+10-9
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ on:
1010

1111
jobs:
1212
php:
13-
name: "PHP ${{ matrix.php-version }} Symfony ${{ matrix.symfony-version }}"
13+
name: "PHP ${{ matrix.php-version }} Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}}"
1414
runs-on: ubuntu-latest
1515

1616
env:
1717
KERNEL_CLASS: PHPCR\PhpcrMigrationsBundle\Tests\Resources\App\AppKernel
18+
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
1819

1920
strategy:
2021
fail-fast: false
@@ -24,10 +25,11 @@ jobs:
2425
symfony-version: '^5.4'
2526

2627
- php-version: '8.1'
27-
symfony-version: '6.0.*'
28+
symfony-version: '^6.0'
29+
dependencies: 'lowest'
2830

2931
- php-version: '8.1'
30-
symfony-version: '^6.0'
32+
symfony-version: '^6.4'
3133

3234
- php-version: '8.2'
3335

@@ -42,16 +44,15 @@ jobs:
4244
with:
4345
php-version: ${{ matrix.php-version }}
4446
extensions: ctype, iconv, mysql
47+
tools: composer:v2, flex
4548
ini-values: memory_limit=-1
4649
coverage: none
4750

48-
- name: Add additional packages
49-
run: |
50-
composer require symfony/symfony:${{ matrix.symfony-version }} --no-update
51-
if: ${{ matrix.symfony-version }}
52-
53-
- name: Install composer dependencies
51+
- name: Install dependencies with Composer
5452
uses: ramsey/composer-install@v3
53+
with:
54+
dependency-versions: ${{ matrix.dependencies }}
55+
composer-options: --prefer-dist
5556

5657
- name: Prepare phpcr odm doctrine dbal
5758
run: vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh

.php-cs-fixer.dist.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
$finder = PhpCsFixer\Finder::create()
44
->in('src/')
5-
->in('tests/');
5+
->in('tests/')
6+
->exclude('tests/Resources/App/var/')
7+
;
68
$config = new PhpCsFixer\Config();
79

810
return $config->setFinder($finder)

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 be 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

composer.json

+13-5
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@
1616
"php": "^8.1",
1717
"phpcr/phpcr-migrations": "^1.1",
1818
"phpcr/phpcr-implementation": "^2.1",
19-
"doctrine/phpcr-bundle": "^1.3 || ^2.0",
19+
"doctrine/phpcr-bundle": "^2.2 || ^3.0",
2020
"symfony/config": "^5.4 || ^6.0 || ^7.0",
2121
"symfony/console": "^5.4 || ^6.0 || ^7.0",
2222
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
2323
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0"
2424
},
2525
"require-dev": {
26-
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
26+
"doctrine/doctrine-bundle": "^1.8 || ^2.5",
2727
"doctrine/phpcr-odm": "^1.4 || ^2.0",
28+
"doctrine/annotations": "^1.14 || ^2.0",
29+
"jackalope/jackalope-doctrine-dbal": "^1.4 || ^2.0",
2830
"symfony/monolog-bundle": "^3.0",
29-
"symfony/phpunit-bridge": "^7.0",
30-
"symfony/symfony": "^5.4 || ^6.0 || ^7.0",
31-
"symfony-cmf/testing": "^2.1 || ^3.0 || ^4.0"
31+
"symfony/phpunit-bridge": "^7.0.6",
32+
"symfony-cmf/testing": "^4.5.0",
33+
"symfony/security-bundle": "^5.4 || ^6.0 || ^7.0",
34+
"symfony/twig-bundle": "^5.4 || ^6.0 || ^7.0",
35+
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
36+
"symfony/translation": "^5.4 || ^6.0 || ^7.0",
37+
"symfony/form": "^5.4 || ^6.0 || ^7.0",
38+
"symfony/validator": "^5.4 || ^6.0 || ^7.0",
39+
"symfony/property-access": "^5.4 || ^6.0 || ^7.0"
3240
},
3341
"autoload": {
3442
"psr-4": {

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 <daniel@dantleech.com>
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/Functional/BaseTestCase.php

+3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111

1212
namespace PHPCR\PhpcrMigrationsBundle\Tests\Functional;
1313

14+
use PHPCR\SessionInterface;
1415
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase as CmfBaseTestCase;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617

1718
abstract class BaseTestCase extends CmfBaseTestCase
1819
{
20+
protected SessionInterface $session;
21+
1922
public function setUp(): void
2023
{
2124
$this->db('PHPCR')->purgeRepository();

tests/Functional/MigrateCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class MigrateCommandTest extends BaseTestCase
1515
{
1616
/**
17-
* It should migrate all the unexecuted migrators.
17+
* It should migrate all the non-executed migrators.
1818
*/
1919
public function testMigrateToLatest(): void
2020
{

tests/Resources/App/AppKernel.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class AppKernel extends TestKernel
2222
{
23-
public function configure()
23+
public function configure(): void
2424
{
2525
$this->requireBundleSets([
2626
'default',
@@ -34,14 +34,14 @@ public function configure()
3434
]);
3535
}
3636

37-
public function registerContainerConfiguration(LoaderInterface $loader)
37+
public function registerContainerConfiguration(LoaderInterface $loader): void
3838
{
3939
$loader->import(CMF_TEST_CONFIG_DIR.'/default.php');
4040
$loader->import(CMF_TEST_CONFIG_DIR.'/phpcr_odm.php');
41-
$loader->load(__DIR__.'/config/config.yml');
41+
$loader->load(__DIR__.'/config/config.php');
4242
}
4343

44-
protected function prepareContainer(ContainerBuilder $container)
44+
protected function prepareContainer(ContainerBuilder $container): void
4545
{
4646
parent::prepareContainer($container);
4747
$container->setParameter('cmf_testing.bundle_fqn', 'Phpcr\PhpcrMigrationsBundle\PhpcrMigrationsBundle');

tests/Resources/App/config/config.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$frameworkConfig = [
4+
'property_access' => true,
5+
];
6+
7+
if (class_exists(Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::class)) {
8+
// Symfony < 7
9+
$frameworkConfig['annotations'] = true;
10+
}
11+
12+
$container->loadFromExtension('framework', $frameworkConfig);
13+
$container->loadFromExtension('phpcr_migrations', [
14+
'version_node_name' => 'jcr:migrations',
15+
]);

tests/Resources/App/config/config.yml

-5
This file was deleted.

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)