|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace DoctrineORMModule\Listener; |
|
21
|
|
|
|
|
22
|
|
|
use Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand as MigrationCommand; |
|
23
|
|
|
use Symfony\Component\Console\Event\ConsoleCommandEvent; |
|
24
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @license MIT |
|
28
|
|
|
* @link www.doctrine-project.org |
|
29
|
|
|
* @author Thomas Dutrion <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
|
|
final class MigrationConfigurationListener |
|
32
|
|
|
{ |
|
33
|
|
|
private $container; |
|
34
|
|
|
|
|
35
|
16 |
|
public function __construct(ServiceLocatorInterface $container) |
|
36
|
|
|
{ |
|
37
|
16 |
|
$this->container = $container; |
|
38
|
16 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param ConsoleCommandEvent $consoleCommandEvent |
|
42
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
|
43
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __invoke(ConsoleCommandEvent $consoleCommandEvent) |
|
46
|
|
|
{ |
|
47
|
|
|
if (!class_exists(MigrationCommand::class)) { |
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
if (!$consoleCommandEvent->getCommand() instanceof MigrationCommand) { |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
/* @var $command MigrationCommand */ |
|
54
|
|
|
$command = $consoleCommandEvent->getCommand(); |
|
55
|
|
|
$input = $consoleCommandEvent->getInput(); |
|
56
|
|
|
$objectManagerName = 'doctrine.entitymanager.orm_default'; |
|
57
|
|
|
if ($input->hasParameterOption(['--object-manager'])) { |
|
58
|
|
|
$objectManagerName = $input->getParameterOption(['--object-manager']); |
|
59
|
|
|
} |
|
60
|
|
|
$migrationConfiguration = $this->container->get( |
|
61
|
|
|
str_replace('entitymanager', 'migrations_configuration', $objectManagerName) |
|
62
|
|
|
); |
|
63
|
|
|
$command->setMigrationConfiguration($migrationConfiguration); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|