Skip to content

Commit

Permalink
backport container aware
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Apr 4, 2024
1 parent 321955f commit 5dd2c54
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 17 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: ctype, iconv, mysql
tools: composer:v2, flex
ini-values: memory_limit=-1
coverage: none

- name: Add additional packages
- name: Composer update
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
run: |
composer require symfony/symfony:${{ matrix.symfony-version }} --no-update
if: ${{ matrix.symfony-version }}

- name: Install composer dependencies
uses: ramsey/composer-install@v3
composer update ${{ matrix.composer-flag }} --prefer-dist --no-interaction --no-progress
- name: Prepare phpcr odm doctrine dbal
run: vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
CHANGELOG
=========

1.x
===

1.6.0
-----

* Deprecate using `Symfony\Component\DependencyInjection\ContainerAwareInterface` in favor of
`PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface` as Symfony 7 dropped its
ContainerAwareInterface.
On Symfony 6, the legacy ContainerAwareInterface continues to e supported.

1.5.0
-----

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

1.4.0
Expand Down
14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"php": "^8.1",
"phpcr/phpcr-migrations": "^1.1",
"phpcr/phpcr-implementation": "^2.1",
"doctrine/phpcr-bundle": "^1.3 || ^2.0",
"doctrine/phpcr-bundle": "^1.3 || ^2.0 || ^3.0",
"symfony/config": "^5.4 || ^6.0 || ^7.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
Expand All @@ -25,10 +25,18 @@
"require-dev": {
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/phpcr-odm": "^1.4 || ^2.0",
"doctrine/annotations": "^2.0",
"jackalope/jackalope-doctrine-dbal": "^1.4 || ^2.0",
"symfony/monolog-bundle": "^3.0",
"symfony/phpunit-bridge": "^7.0",
"symfony/symfony": "^5.4 || ^6.0 || ^7.0",
"symfony-cmf/testing": "^2.1 || ^3.0 || ^4.0"
"symfony-cmf/testing": "^4.0 || ^5.0",
"symfony/security-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/twig-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
"symfony/translation": "^5.4 || ^6.0 || ^7.0",
"symfony/form": "^5.4 || ^6.0 || ^7.0",
"symfony/validator": "^5.4 || ^6.0 || ^7.0",
"symfony/property-access": "^5.4 || ^6.0 || ^7.0"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 5 additions & 1 deletion src/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
namespace PHPCR\PhpcrMigrationsBundle\Command;

use PHPCR\Migrations\MigratorFactory;
use PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface as SymfonyContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

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

Expand Down
22 changes: 22 additions & 0 deletions src/ContainerAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the PHPCR Migrations package
*
* (c) Daniel Leech <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPCR\PhpcrMigrationsBundle;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Interface for migrations to get the Symfony container injected.
*/
interface ContainerAwareInterface
{
public function setContainer(?ContainerInterface $container = null): void;
}
6 changes: 3 additions & 3 deletions tests/Resources/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class AppKernel extends TestKernel
{
public function configure()
public function configure(): void
{
$this->requireBundleSets([
'default',
Expand All @@ -34,14 +34,14 @@ public function configure()
]);
}

public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->import(CMF_TEST_CONFIG_DIR.'/default.php');
$loader->import(CMF_TEST_CONFIG_DIR.'/phpcr_odm.php');
$loader->load(__DIR__.'/config/config.yml');
}

protected function prepareContainer(ContainerBuilder $container)
protected function prepareContainer(ContainerBuilder $container): void
{
parent::prepareContainer($container);
$container->setParameter('cmf_testing.bundle_fqn', 'Phpcr\PhpcrMigrationsBundle\PhpcrMigrationsBundle');
Expand Down
2 changes: 1 addition & 1 deletion tests/Resources/App/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ phpcr_migrations:
version_node_name: "jcr:migrations"

framework:
annotations: true
property_access: ~
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
*/

use PHPCR\Migrations\VersionInterface;
use PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface;
use PHPCR\SessionInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class Version201401011300 implements VersionInterface, ContainerAwareInterface
{
private $container;

public function setContainer(?ContainerInterface $container = null)
public function setContainer(?ContainerInterface $container = null): void
{
$this->container = $container;
}
Expand Down

0 comments on commit 5dd2c54

Please sign in to comment.