Skip to content

Commit

Permalink
allow installation with phpcr-odm 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Apr 4, 2024
1 parent 321955f commit 7cef0e2
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 40 deletions.
17 changes: 5 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: '8.1'
symfony-version: '^5.4'

- php-version: '8.1'
symfony-version: '6.0.*'

- php-version: '8.1'
symfony-version: '^6.0'

Expand All @@ -42,16 +36,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
4 changes: 3 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

$finder = PhpCsFixer\Finder::create()
->in('src/')
->in('tests/');
->in('tests/')
->exclude(__DIR__.'/tests/Resources/App/var')
;
$config = new PhpCsFixer\Config();

return $config->setFinder($finder)
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
=========

2.0.0
-----

* Replace ContainerAwareInterface from Symfony with `PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface`.
While 1.5.0 can be installed with Symfony 7, the container aware mechanism stopped working.
* Allow installation with PHPCR-ODM 3.0.
* Drop support for Symfony 5.

1.5.0
-----

Expand Down
21 changes: 14 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@
"php": "^8.1",
"phpcr/phpcr-migrations": "^1.1",
"phpcr/phpcr-implementation": "^2.1",
"doctrine/phpcr-bundle": "^1.3 || ^2.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",
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0"
"doctrine/phpcr-bundle": "^1.3 || ^2.0 || ^3.0",
"symfony/config": "^6.0 || ^7.0",
"symfony/console": "^6.0 || ^7.0",
"symfony/dependency-injection": "^6.0 || ^7.0",
"symfony/http-kernel": "^6.0 || ^7.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/phpcr-odm": "^1.4 || ^2.0",
"jackalope/jackalope-doctrine-dbal": "^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": "^5.0",
"symfony/security-bundle": "^6.0 || ^7.0",
"symfony/twig-bundle": "^6.0 || ^7.0",
"symfony/yaml": "^6.0 || ^7.0",
"symfony/translation": "^6.0 || ^7.0",
"symfony/form": "^6.0 || ^7.0",
"symfony/validator": "^6.0 || ^7.0",
"symfony/property-access": "^6.0 || ^7.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
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;

This comment has been minimized.

Copy link
@alexander-schranz

alexander-schranz Apr 4, 2024

Contributor

We should keep the support for Symfony\Component\DependencyInjection\ContainerAwareInterface; here via:

use Symfony\Component\DependencyInjection\ContainerAwareInterface as SymfonyContainerAwareInterface;

and go with

            if ($version instanceof ContainerAwareInterface || $version instanceof SymfonyContainerInterface) {

Else we need to backport the PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface; to 1.xbranch, so sulu can do ^1.6 || ^2.0

use Symfony\Component\DependencyInjection\ContainerInterface;

class MigrateCommand extends Command
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;
}

This comment has been minimized.

Copy link
@alexander-schranz

alexander-schranz Apr 4, 2024

Contributor

we could also do something like:

namespace PHPCR\PhpcrMigrationsBundle

use Symfony\Component\DependencyInjection\ContainerInterface;

if (\interface_exists(\Symfony\Component\DependencyInjection\ContainerInterface::class) {
    \class_alias(
        \Symfony\Component\DependencyInjection\ContainerInterface::class,
        ContainerAwareInterface::class,
    );
} else {
    interface ContainerAwareInterface
    {
        public function setContainer(?ContainerInterface $container = null): void;
    }
}

then we don't need to check in migrate command for both interfaces.

2 changes: 1 addition & 1 deletion tests/Functional/MigrateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class MigrateCommandTest extends BaseTestCase
{
/**
* It should migrate all the unexecuted migrators.
* It should migrate all the non-executed migrators.
*/
public function testMigrateToLatest(): void
{
Expand Down
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 @@ -14,12 +14,12 @@

class Version201501011200 implements VersionInterface
{
public function up(SessionInterface $session)
public function up(SessionInterface $session): void
{
$session->getRootNode()->addNode('hello');
}

public function down(SessionInterface $session)
public function down(SessionInterface $session): void
{
$session->getRootNode()->getNode('hello')->remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

class Version201501011212 implements VersionInterface
{
public function up(SessionInterface $session)
public function up(SessionInterface $session): void
{
$session->getNode('/hello')->addNode('world');
}

public function down(SessionInterface $session)
public function down(SessionInterface $session): void
{
$session->getNode('/hello')->getNode('world')->remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

class Version201501011215 implements VersionInterface
{
public function up(SessionInterface $session)
public function up(SessionInterface $session): void
{
$session->getNode('/hello')->addNode('dan');
}

public function down(SessionInterface $session)
public function down(SessionInterface $session): void
{
$session->getNode('/hello')->getNode('dan')->remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@
*/

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;
private ?ContainerInterface $container;

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

public function up(SessionInterface $session)
public function up(SessionInterface $session): void
{
if (!$this->container) {
if (!isset($this->container)) {
throw new Exception('This Version class implements ContainerAwareInterface but no container has been set.');
}
$session->getRootNode()->addNode('camel');
}

public function down(SessionInterface $session)
public function down(SessionInterface $session): void
{
$session->getRootNode()->getNode('camel')->remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

class Version201501011500 implements VersionInterface
{
public function up(SessionInterface $session)
public function up(SessionInterface $session): void
{
$session->getNode('/camel')->addNode('dan');
}

public function down(SessionInterface $session)
public function down(SessionInterface $session): void
{
$session->getNode('/camel')->getNode('dan')->remove();
}
Expand Down

0 comments on commit 7cef0e2

Please sign in to comment.