1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DoctrineORMModule\Service; |
6
|
|
|
|
7
|
|
|
use Doctrine\Migrations\Configuration\Configuration; |
8
|
|
|
use Doctrine\Migrations\Tools\Console\Command\AbstractCommand; |
9
|
|
|
use Interop\Container\ContainerInterface; |
10
|
|
|
use InvalidArgumentException; |
11
|
|
|
use Laminas\ServiceManager\FactoryInterface; |
12
|
|
|
use Laminas\ServiceManager\ServiceLocatorInterface; |
13
|
|
|
use function assert; |
14
|
|
|
use function class_exists; |
15
|
|
|
use function strtolower; |
16
|
|
|
use function ucfirst; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Service factory for migrations command |
20
|
|
|
*/ |
21
|
|
|
class MigrationsCommandFactory implements FactoryInterface |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** @var string */ |
24
|
|
|
private $name; |
25
|
|
|
|
26
|
1 |
|
public function __construct(string $name) |
27
|
|
|
{ |
28
|
1 |
|
$this->name = ucfirst(strtolower($name)); |
29
|
1 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritDoc} |
33
|
|
|
* |
34
|
|
|
* @return AbstractCommand |
35
|
|
|
* |
36
|
|
|
* @throws InvalidArgumentException |
37
|
|
|
*/ |
38
|
1 |
|
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null) |
39
|
|
|
{ |
40
|
1 |
|
$className = 'Doctrine\Migrations\Tools\Console\Command\\' . $this->name . 'Command'; |
41
|
|
|
|
42
|
1 |
|
if (! class_exists($className)) { |
43
|
1 |
|
throw new InvalidArgumentException(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$configuration = $container->get('doctrine.migrations_configuration.orm_default'); |
47
|
|
|
assert($configuration instanceof Configuration); |
48
|
|
|
$command = new $className(); |
49
|
|
|
assert($command instanceof AbstractCommand); |
50
|
|
|
|
51
|
|
|
$command->setMigrationConfiguration($configuration); |
52
|
|
|
|
53
|
|
|
return $command; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @throws InvalidArgumentException |
58
|
|
|
*/ |
59
|
1 |
|
public function createService(ServiceLocatorInterface $container) : AbstractCommand |
60
|
|
|
{ |
61
|
1 |
|
return $this($container, 'Doctrine\Migrations\Tools\Console\Command\\' . $this->name . 'Command'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.