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. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace DoctrineORMModule\Service; |
20
|
|
|
|
21
|
|
|
use Interop\Container\ContainerInterface; |
22
|
|
|
use Zend\ServiceManager\FactoryInterface; |
23
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Service factory for migrations command |
27
|
|
|
* |
28
|
|
|
* @license MIT |
29
|
|
|
* @author Aleksandr Sandrovskiy <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class MigrationsCommandFactory implements FactoryInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $name; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $name |
40
|
|
|
*/ |
41
|
5 |
|
public function __construct($name) |
42
|
|
|
{ |
43
|
5 |
|
$this->name = ucfirst(strtolower($name)); |
44
|
5 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritDoc} |
48
|
|
|
* |
49
|
|
|
* @return \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand |
50
|
|
|
* @throws \InvalidArgumentException |
51
|
|
|
*/ |
52
|
5 |
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
|
|
|
53
|
|
|
{ |
54
|
5 |
|
$className = 'Doctrine\DBAL\Migrations\Tools\Console\Command\\' . $this->name . 'Command'; |
55
|
|
|
|
56
|
5 |
|
if (! class_exists($className)) { |
57
|
1 |
|
throw new \InvalidArgumentException(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// @TODO currently hardcoded: `orm_default` should be injected |
61
|
|
|
/* @var $configuration \Doctrine\DBAL\Migrations\Configuration\Configuration */ |
62
|
4 |
|
$configuration = $container->get('doctrine.migrations_configuration.orm_default'); |
63
|
|
|
/* @var $command \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand */ |
64
|
4 |
|
$command = new $className; |
65
|
|
|
|
66
|
4 |
|
$command->setMigrationConfiguration($configuration); |
67
|
|
|
|
68
|
4 |
|
return $command; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param \Zend\ServiceManager\ServiceLocatorInterface $container |
73
|
|
|
* @return \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand |
74
|
|
|
* @throws \InvalidArgumentException |
75
|
|
|
*/ |
76
|
5 |
|
public function createService(ServiceLocatorInterface $container) |
77
|
|
|
{ |
78
|
5 |
|
return $this($container, 'Doctrine\DBAL\Migrations\Tools\Console\Command\\' . $this->name . 'Command'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.