1 | <?php |
||
60 | class FactoryListContainer |
||
61 | implements FactoryList |
||
|
|||
62 | { |
||
63 | // satisfies WriteProtectedEntity interface |
||
64 | use WriteProtectTab; |
||
65 | |||
66 | // the file that we are declared in |
||
67 | const file = __FILE__; |
||
68 | |||
69 | /** |
||
70 | * the list of factories |
||
71 | * |
||
72 | * the 'key' is the alias for the instance. We recommend using either the |
||
73 | * fully-qualified class name, or the class name with no namespace |
||
74 | * |
||
75 | * the 'value' is a callable that returns something. We recommend that this |
||
76 | * always returns an object of some kind, but we deliberately do not |
||
77 | * enforce that, in case you find new and novel ways to use this provider |
||
78 | * |
||
79 | * @var array |
||
80 | */ |
||
81 | private $factories = []; |
||
82 | |||
83 | /** |
||
84 | * the list of exceptions to throw |
||
85 | * |
||
86 | * @var FactoryList |
||
87 | */ |
||
88 | private $exceptions; |
||
89 | |||
90 | /** |
||
91 | * create a managed list of factories |
||
92 | * |
||
93 | * the array has the following format: |
||
94 | * - 'key' is the name or alias for your factor |
||
95 | * - 'value' is a callable that will return something |
||
96 | * |
||
97 | * examples of keys include: |
||
98 | * |
||
99 | * - 'NotAFactoryList::newFromVar' |
||
100 | * - 'NotAFactory::newFromNonCallable' |
||
101 | * |
||
102 | * the only requirements on 'value' are that |
||
103 | * - it is a callable |
||
104 | * |
||
105 | * @param array $factories |
||
106 | * the list of factories to define |
||
107 | * @param FactoryList $exceptions |
||
108 | * the list of exceptions to throw |
||
109 | */ |
||
110 | public function __construct($factories = [], FactoryList $exceptions = null) |
||
138 | |||
139 | /** |
||
140 | * get a factory for you to call |
||
141 | * |
||
142 | * @param string $factoryName |
||
143 | * a valid key into the list of factories stored in this entity |
||
144 | * @return callable |
||
145 | * |
||
146 | * @throws NoSuchFactory |
||
147 | * if we can't find a factory for $factoryName |
||
148 | */ |
||
149 | public function offsetGet($factoryName) |
||
159 | |||
160 | /** |
||
161 | * do we have a factory for a given instance alias? |
||
162 | * |
||
163 | * @param string $factoryName |
||
164 | * the factory to look for |
||
165 | */ |
||
166 | public function offsetExists($factoryName) |
||
174 | |||
175 | /** |
||
176 | * set a factory for a given instance alias |
||
177 | * |
||
178 | * @param string $factoryName |
||
179 | * the name or alias to give to $factory |
||
180 | * @param callable $factory |
||
181 | * the factory to add to our container |
||
182 | * |
||
183 | * @throws NotAFactory |
||
184 | * if $factory isn't callable |
||
185 | */ |
||
186 | public function offsetSet($factoryName, $factory) |
||
199 | |||
200 | /** |
||
201 | * forget a factory |
||
202 | * |
||
203 | * @param string $factoryName |
||
204 | * the factory that we want to forget |
||
205 | */ |
||
206 | public function offsetUnset($factoryName) |
||
220 | |||
221 | /** |
||
222 | * return the full list of factories as a real PHP array |
||
223 | * |
||
224 | * @return array |
||
225 | */ |
||
226 | public function getList() |
||
230 | } |
||
231 |