Skip to content

Commit 48bff17

Browse files
authored
Merge pull request #31 from smoench/fix-requirements
fix requirements + fix symfony 5 compatibility
2 parents 5e1731a + 8f8cc04 commit 48bff17

11 files changed

+65
-55
lines changed

.scrutinizer.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
tools:
22
external_code_coverage:
33
timeout: 720
4+
5+
build:
6+
environment:
7+
php:
8+
version: '7.4'

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ matrix:
1111
- php: 7.1
1212
- php: 7.2
1313
- php: 7.3
14+
- php: 7.4
1415

1516
# Test with the lowest dependencies
16-
- php: 7.3
17+
- php: 7.4
1718
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest --prefer-dist"
1819

1920
before_script:

Command/CommandHelper.php

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,26 @@
1212
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;
1313

1414
use AntiMattr\MongoDB\Migrations\Configuration\Configuration;
15+
use AntiMattr\MongoDB\Migrations\Version;
16+
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
17+
use Doctrine\ODM\MongoDB\DocumentManager;
1518
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper;
19+
use ErrorException;
1620
use Symfony\Bundle\FrameworkBundle\Console\Application;
17-
use Symfony\Component\DependencyInjection\ContainerInterface;
1821
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
22+
use Symfony\Component\DependencyInjection\ContainerInterface;
1923

2024
/**
2125
* @author Matthew Fitzgerald <matthewfitz@gmail.com>
2226
*/
2327
final class CommandHelper
2428
{
25-
/**
26-
* configureMigrations.
27-
*
28-
* @param ContainerInterface $container
29-
* @param Configuration $configuration
30-
*/
31-
public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
29+
public static function configureMigrations(ContainerInterface $container, Configuration $configuration): void
3230
{
3331
$dir = $container->getParameter('mongo_db_migrations.dir_name');
34-
if (!file_exists($dir)) {
35-
mkdir($dir, 0777, true);
32+
if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
33+
$error = error_get_last();
34+
throw new ErrorException(sprintf('Failed to create directory "%s" with message "%s"', $dir, $error['message']));
3635
}
3736

3837
$configuration->setMigrationsCollectionName($container->getParameter('mongo_db_migrations.collection_name'));
@@ -47,30 +46,26 @@ public static function configureMigrations(ContainerInterface $container, Config
4746
}
4847

4948
/**
50-
* @param Application $application
51-
* @param string $dmName
49+
* @param string $dmName
5250
*/
53-
public static function setApplicationDocumentManager(Application $application, $dmName)
51+
public static function setApplicationDocumentManager(Application $application, $dmName): void
5452
{
55-
/* @var $dm \Doctrine\ODM\DocumentManager */
56-
$alias = sprintf(
57-
'doctrine_mongodb.odm.%s',
58-
$dmName
59-
);
60-
$dm = $application->getKernel()->getContainer()->get($alias);
53+
/** @var ManagerRegistry $managerRegistry */
54+
$managerRegistry = $application->getKernel()->getContainer()->get('doctrine_mongodb');
55+
56+
/** @var DocumentManager $dm */
57+
$dm = $managerRegistry->getManager($dmName);
58+
6159
$helperSet = $application->getHelperSet();
6260
$helperSet->set(new DocumentManagerHelper($dm), 'dm');
6361
}
6462

6563
/**
66-
* injectContainerToMigrations.
67-
*
68-
* Injects the container to migrations aware of it.
64+
* @param Version[] $versions
6965
*
70-
* @param ContainerInterface $container
71-
* @param array $versions
66+
* Injects the container to migrations aware of it
7267
*/
73-
private static function injectContainerToMigrations(ContainerInterface $container, array $versions)
68+
private static function injectContainerToMigrations(ContainerInterface $container, array $versions): void
7469
{
7570
foreach ($versions as $version) {
7671
$migration = $version->getMigration();

Command/MigrationsExecuteCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;
1313

1414
use AntiMattr\MongoDB\Migrations\Tools\Console\Command\ExecuteCommand;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -33,11 +34,13 @@ protected function configure()
3334

3435
public function execute(InputInterface $input, OutputInterface $output)
3536
{
36-
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
37+
/** @var Application $application */
38+
$application = $this->getApplication();
39+
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));
3740

3841
$configuration = $this->getMigrationConfiguration($input, $output);
39-
CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
42+
CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration);
4043

41-
parent::execute($input, $output);
44+
return parent::execute($input, $output);
4245
}
4346
}

Command/MigrationsGenerateCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;
1313

1414
use AntiMattr\MongoDB\Migrations\Tools\Console\Command\GenerateCommand;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -33,11 +34,13 @@ protected function configure()
3334

3435
public function execute(InputInterface $input, OutputInterface $output)
3536
{
36-
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
37+
/** @var Application $application */
38+
$application = $this->getApplication();
39+
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));
3740

3841
$configuration = $this->getMigrationConfiguration($input, $output);
39-
CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
42+
CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration);
4043

41-
parent::execute($input, $output);
44+
return parent::execute($input, $output);
4245
}
4346
}

Command/MigrationsMigrateCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;
1313

1414
use AntiMattr\MongoDB\Migrations\Tools\Console\Command\MigrateCommand;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -33,11 +34,13 @@ protected function configure()
3334

3435
public function execute(InputInterface $input, OutputInterface $output)
3536
{
36-
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
37+
/** @var Application $application */
38+
$application = $this->getApplication();
39+
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));
3740

3841
$configuration = $this->getMigrationConfiguration($input, $output);
39-
CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
42+
CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration);
4043

41-
parent::execute($input, $output);
44+
return parent::execute($input, $output);
4245
}
4346
}

Command/MigrationsStatusCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;
1313

1414
use AntiMattr\MongoDB\Migrations\Tools\Console\Command\StatusCommand;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -33,11 +34,13 @@ protected function configure()
3334

3435
public function execute(InputInterface $input, OutputInterface $output)
3536
{
36-
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
37+
/** @var Application $application */
38+
$application = $this->getApplication();
39+
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));
3740

3841
$configuration = $this->getMigrationConfiguration($input, $output);
39-
CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
42+
CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration);
4043

41-
parent::execute($input, $output);
44+
return parent::execute($input, $output);
4245
}
4346
}

Command/MigrationsVersionCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;
1313

1414
use AntiMattr\MongoDB\Migrations\Tools\Console\Command\VersionCommand;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -33,11 +34,13 @@ protected function configure()
3334

3435
public function execute(InputInterface $input, OutputInterface $output)
3536
{
36-
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
37+
/** @var Application $application */
38+
$application = $this->getApplication();
39+
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));
3740

3841
$configuration = $this->getMigrationConfiguration($input, $output);
39-
CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
42+
CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration);
4043

41-
parent::execute($input, $output);
44+
return parent::execute($input, $output);
4245
}
4346
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The original authors are @rcatlin and @matthewfitz
1414

1515
## PHP Version Support
1616

17-
If you require php 5.6 support use version `^1.0`. Version `^2.0` requires at least php 7.1. The `1.x` releases will only receive bug fixes.
17+
If you require php 5.6 support use version `^1.0`. Version `^3.0` requires at least php 7.1. The `1.x` releases will only receive bug fixes.
1818

1919
## Installation
2020

@@ -25,7 +25,7 @@ Install with composer:
2525
composer require "doesntmattr/mongodb-migrations-bundle=^1.0"
2626

2727
# For php 7.1
28-
composer require "doesntmattr/mongodb-migrations-bundle=^2.0"
28+
composer require "doesntmattr/mongodb-migrations-bundle=^3.0"
2929
```
3030

3131
then enable the bundle in `AppKernel.php` by including the following:

composer.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
},
1414
"require": {
1515
"php": "^7.1",
16-
"symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0",
17-
"symfony/http-kernel": "^3.4 || ^4.0 || ^5.0",
18-
"symfony/console": "^3.4 || ^4.0 || ^5.0",
19-
"symfony/config": "^3.4 || ^4.0 || ^5.0",
20-
"doesntmattr/mongodb-migrations": "^2.0",
21-
"doctrine/mongodb-odm": "^1.0 || ^2.0"
16+
"doesntmattr/mongodb-migrations": "^3.0",
17+
"doctrine/mongodb-odm-bundle": "^3.0 || ^4.0",
18+
"symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0",
19+
"symfony/console": "^3.4 || ^4.0 || ^5.0"
2220
},
2321
"require-dev": {
2422
"friendsofphp/php-cs-fixer": "^2.0",
@@ -37,7 +35,7 @@
3735
},
3836
"extra": {
3937
"branch-alias": {
40-
"dev-master": "2.0.x-dev"
38+
"dev-master": "3.0.x-dev"
4139
}
4240
}
4341
}

0 commit comments

Comments
 (0)