1 | <?php |
||
12 | class ProvidersContainer implements ProvidersContainerInterface |
||
13 | { |
||
14 | /** |
||
15 | * References to the request and response classes that travels |
||
16 | * through the application |
||
17 | * |
||
18 | * @var RequestInterface |
||
19 | */ |
||
20 | protected $request; |
||
21 | /** |
||
22 | * @var ResponseInterface |
||
23 | */ |
||
24 | protected $response; |
||
25 | |||
26 | const PROVIDERS_NAMESPACE = "seregazhuk\\PinterestBot\\Api\\Providers\\"; |
||
27 | |||
28 | /** |
||
29 | * A array containing the cached providers |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private $providers = []; |
||
34 | |||
35 | public function __construct(RequestInterface $request, ResponseInterface $response) |
||
40 | |||
41 | /** |
||
42 | * Gets provider object by name. If there is no such provider |
||
43 | * in providers array, it will try to create it, then save |
||
44 | * it, and then return. |
||
45 | * |
||
46 | * @param string $provider |
||
47 | * @return Provider |
||
48 | * @throws WrongProviderException |
||
49 | */ |
||
50 | public function getProvider($provider) |
||
61 | |||
62 | /** |
||
63 | * Creates provider by class name, and if success saves |
||
64 | * it to providers array. Provider class must be in PROVIDERS_NAMESPACE. |
||
65 | * |
||
66 | * @param string $provider |
||
67 | * @throws WrongProviderException |
||
68 | */ |
||
69 | private function addProvider($provider) |
||
79 | |||
80 | /** |
||
81 | * Build Provider object with reflection API. |
||
82 | * |
||
83 | * @param string $className |
||
84 | * @return object |
||
85 | * @throws WrongProviderException |
||
86 | */ |
||
87 | private function buildProvider($className) |
||
96 | |||
97 | /** |
||
98 | * @return RequestInterface |
||
99 | */ |
||
100 | public function getRequest() |
||
104 | |||
105 | /** |
||
106 | * @return ResponseInterface |
||
107 | */ |
||
108 | public function getResponse() |
||
112 | } |