1 | <?php |
||
8 | class BootstrapManager implements LoggerAwareInterface |
||
9 | { |
||
10 | use LoggerAwareTrait; |
||
11 | |||
12 | /** |
||
13 | * @var Consolidation\Bootstrap\BootInterface[] |
||
14 | */ |
||
15 | protected $bootstrapCandidates = []; |
||
16 | |||
17 | /** |
||
18 | * @var BootstrapCurator |
||
19 | */ |
||
20 | protected $curator; |
||
21 | |||
22 | /** |
||
23 | * Constructor. |
||
24 | */ |
||
25 | public function __construct() |
||
28 | |||
29 | public function setBootstrapCurator(BootstrapCurator $curator) |
||
33 | |||
34 | public function getBootstrapCurator() |
||
41 | |||
42 | /** |
||
43 | * Add a bootstrap selection object to the list of candidates |
||
44 | * |
||
45 | * @param BootstrapSelectionInterface |
||
46 | * List of boot candidates |
||
47 | */ |
||
48 | public function add(BootstrapSelectionInterface $candidate) |
||
52 | |||
53 | /** |
||
54 | * Register a factory with an object-creation listener, and |
||
55 | * the bootstrap manager will ensure that the bootstrap object |
||
56 | * will be set on any object that implements BootstrapAwareInterface. |
||
57 | * This is an alternative to using dependency injection container |
||
58 | * inflection (e.g. if the commandfile objects are not always |
||
59 | * created via the container). |
||
60 | * |
||
61 | * @param mixed $factory A factory object that creates or uses |
||
62 | * bootstrap-aware objects. |
||
63 | * @param string $listenerMethod The method to call to register a |
||
64 | * listener callback function. |
||
65 | * @example $bootstrapManager->registerFactory($annotationCommandFactory); |
||
66 | */ |
||
67 | public function registerFactory($factory, $listenerMethod = 'addListener') |
||
68 | { |
||
69 | $factory->$listenerMethod( |
||
70 | function ($object) { |
||
71 | if ($object instanceof BootstrapAwareInterface) { |
||
72 | $object->setBootstrapCurator($this->getBootstrapCurator()); |
||
73 | } |
||
74 | } |
||
75 | ); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Look up the best bootstrap class for the given location |
||
80 | * from the set of available candidates. |
||
81 | * |
||
82 | * @param string $path Path to the desired framework |
||
83 | * |
||
84 | * @return null|BootInterface |
||
85 | */ |
||
86 | public function selectBootstrap($path) |
||
98 | |||
99 | /** |
||
100 | * Get the bootstrap object for the selected framework. |
||
101 | * |
||
102 | * @param BootstrapSelectionInterface $candidate A valid selection object. |
||
103 | * |
||
104 | * @return BootInterface |
||
105 | */ |
||
106 | protected function setSelectedBootstrap(BootstrapSelectionInterface $candidate, $path) |
||
110 | |||
111 | /** |
||
112 | * Record the bootstrap object that was selected. |
||
113 | * |
||
114 | * @param BootInterface $bootstrap |
||
115 | * |
||
116 | * @return BootInterface |
||
117 | */ |
||
118 | protected function setBootstrap(BootInterface $bootstrap) |
||
123 | } |
||
124 |