Skip to content

Commit

Permalink
Merge pull request #31 from smoench/fix-requirements
Browse files Browse the repository at this point in the history
fix requirements + fix symfony 5 compatibility
  • Loading branch information
caciobanu authored Mar 21, 2020
2 parents 5e1731a + 8f8cc04 commit 48bff17
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
tools:
external_code_coverage:
timeout: 720

build:
environment:
php:
version: '7.4'
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ matrix:
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4

# Test with the lowest dependencies
- php: 7.3
- php: 7.4
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest --prefer-dist"

before_script:
Expand Down
45 changes: 20 additions & 25 deletions Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;

use AntiMattr\MongoDB\Migrations\Configuration\Configuration;
use AntiMattr\MongoDB\Migrations\Version;
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper;
use ErrorException;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* @author Matthew Fitzgerald <[email protected]>
*/
final class CommandHelper
{
/**
* configureMigrations.
*
* @param ContainerInterface $container
* @param Configuration $configuration
*/
public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
public static function configureMigrations(ContainerInterface $container, Configuration $configuration): void
{
$dir = $container->getParameter('mongo_db_migrations.dir_name');
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
$error = error_get_last();
throw new ErrorException(sprintf('Failed to create directory "%s" with message "%s"', $dir, $error['message']));
}

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

/**
* @param Application $application
* @param string $dmName
* @param string $dmName
*/
public static function setApplicationDocumentManager(Application $application, $dmName)
public static function setApplicationDocumentManager(Application $application, $dmName): void
{
/* @var $dm \Doctrine\ODM\DocumentManager */
$alias = sprintf(
'doctrine_mongodb.odm.%s',
$dmName
);
$dm = $application->getKernel()->getContainer()->get($alias);
/** @var ManagerRegistry $managerRegistry */
$managerRegistry = $application->getKernel()->getContainer()->get('doctrine_mongodb');

/** @var DocumentManager $dm */
$dm = $managerRegistry->getManager($dmName);

$helperSet = $application->getHelperSet();
$helperSet->set(new DocumentManagerHelper($dm), 'dm');
}

/**
* injectContainerToMigrations.
*
* Injects the container to migrations aware of it.
* @param Version[] $versions
*
* @param ContainerInterface $container
* @param array $versions
* Injects the container to migrations aware of it
*/
private static function injectContainerToMigrations(ContainerInterface $container, array $versions)
private static function injectContainerToMigrations(ContainerInterface $container, array $versions): void
{
foreach ($versions as $version) {
$migration = $version->getMigration();
Expand Down
9 changes: 6 additions & 3 deletions Command/MigrationsExecuteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;

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

public function execute(InputInterface $input, OutputInterface $output)
{
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
/** @var Application $application */
$application = $this->getApplication();
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));

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

parent::execute($input, $output);
return parent::execute($input, $output);
}
}
9 changes: 6 additions & 3 deletions Command/MigrationsGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;

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

public function execute(InputInterface $input, OutputInterface $output)
{
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
/** @var Application $application */
$application = $this->getApplication();
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));

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

parent::execute($input, $output);
return parent::execute($input, $output);
}
}
9 changes: 6 additions & 3 deletions Command/MigrationsMigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;

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

public function execute(InputInterface $input, OutputInterface $output)
{
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
/** @var Application $application */
$application = $this->getApplication();
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));

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

parent::execute($input, $output);
return parent::execute($input, $output);
}
}
9 changes: 6 additions & 3 deletions Command/MigrationsStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;

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

public function execute(InputInterface $input, OutputInterface $output)
{
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
/** @var Application $application */
$application = $this->getApplication();
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));

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

parent::execute($input, $output);
return parent::execute($input, $output);
}
}
9 changes: 6 additions & 3 deletions Command/MigrationsVersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command;

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

public function execute(InputInterface $input, OutputInterface $output)
{
CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));
/** @var Application $application */
$application = $this->getApplication();
CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm'));

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

parent::execute($input, $output);
return parent::execute($input, $output);
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The original authors are @rcatlin and @matthewfitz

## PHP Version Support

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

## Installation

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

# For php 7.1
composer require "doesntmattr/mongodb-migrations-bundle=^2.0"
composer require "doesntmattr/mongodb-migrations-bundle=^3.0"
```

then enable the bundle in `AppKernel.php` by including the following:
Expand Down
12 changes: 5 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
},
"require": {
"php": "^7.1",
"symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0",
"symfony/http-kernel": "^3.4 || ^4.0 || ^5.0",
"symfony/console": "^3.4 || ^4.0 || ^5.0",
"symfony/config": "^3.4 || ^4.0 || ^5.0",
"doesntmattr/mongodb-migrations": "^2.0",
"doctrine/mongodb-odm": "^1.0 || ^2.0"
"doesntmattr/mongodb-migrations": "^3.0",
"doctrine/mongodb-odm-bundle": "^3.0 || ^4.0",
"symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0",
"symfony/console": "^3.4 || ^4.0 || ^5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
Expand All @@ -37,7 +35,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "3.0.x-dev"
}
}
}
6 changes: 1 addition & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">DependencyInjection</directory>
<directory suffix=".php">Command</directory>
<file suffix=".php">MongoDBMigrationsBundle.php</file>
<file>MongoDBMigrationsBundle.php</file>
</whitelist>
<blacklist>
<directory>vendor</directory>
<directory>Tests</directory>
</blacklist>
</filter>
</phpunit>

0 comments on commit 48bff17

Please sign in to comment.