|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of slick/mvc |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Slick\Mvc\Console\Service; |
|
11
|
|
|
|
|
12
|
|
|
use Slick\Di\ContainerBuilder; |
|
13
|
|
|
use Slick\Di\ContainerInterface; |
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Container Factory |
|
18
|
|
|
* |
|
19
|
|
|
* @package Slick\Mvc\Console\Service |
|
20
|
|
|
* @author Filipe Silva <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
final class ContainerFactory |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var ContainerInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private static $container; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Command |
|
32
|
|
|
*/ |
|
33
|
|
|
private $command; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Container Factory is only created with self::create() method |
|
37
|
|
|
*/ |
|
38
|
|
|
private function __construct(Command $command) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->command = $command; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Creates a new container factory |
|
45
|
|
|
* |
|
46
|
|
|
* @return ContainerFactory |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function create(Command $command) |
|
49
|
|
|
{ |
|
50
|
|
|
$containerFactory = new ContainerFactory($command); |
|
51
|
|
|
return $containerFactory; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get dependency container |
|
56
|
|
|
* |
|
57
|
|
|
* @return ContainerInterface |
|
58
|
|
|
*/ |
|
59
|
|
|
public function container() |
|
60
|
|
|
{ |
|
61
|
|
|
if (!self::$container) { |
|
62
|
|
|
$this->createContainer(); |
|
63
|
|
|
} |
|
64
|
|
|
return self::$container; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Creates the dependency container |
|
69
|
|
|
*/ |
|
70
|
|
|
private function createContainer() |
|
71
|
|
|
{ |
|
72
|
|
|
$containerBuilder = new ContainerBuilder(__DIR__ . '/Definitions'); |
|
73
|
|
|
self::$container = $containerBuilder->getContainer(); |
|
|
|
|
|
|
74
|
|
|
self::$container->register(Command::class, $this->command); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..