1 | <?php |
||
26 | class ServiceFactory |
||
27 | { |
||
28 | /** |
||
29 | *@var ClientInterface |
||
30 | */ |
||
31 | protected $httpClient; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $serviceClassMap = array( |
||
37 | 'OAuth1' => array(), |
||
38 | 'OAuth2' => array() |
||
39 | ); |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $serviceBuilders = array( |
||
45 | 'OAuth2' => 'buildV2Service', |
||
46 | 'OAuth1' => 'buildV1Service', |
||
47 | ); |
||
48 | |||
49 | /** |
||
50 | * @param ClientInterface $httpClient |
||
51 | * |
||
52 | * @return ServiceFactory |
||
53 | */ |
||
54 | public function setHttpClient(ClientInterface $httpClient) |
||
55 | { |
||
56 | $this->httpClient = $httpClient; |
||
57 | |||
58 | return $this; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Register a custom service to classname mapping. |
||
63 | * |
||
64 | * @param string $serviceName Name of the service |
||
65 | * @param string $className Class to instantiate |
||
66 | * |
||
67 | * @return ServiceFactory |
||
68 | * |
||
69 | * @throws Exception If the class is nonexistent or does not implement a valid ServiceInterface |
||
70 | */ |
||
71 | public function registerService($serviceName, $className) |
||
89 | |||
90 | /** |
||
91 | * Builds and returns oauth services |
||
92 | * |
||
93 | * It will first try to build an OAuth2 service and if none found it will try to build an OAuth1 service |
||
94 | * |
||
95 | * @param string $serviceName Name of service to create |
||
96 | * @param CredentialsInterface $credentials |
||
97 | * @param TokenStorageInterface $storage |
||
98 | * @param array|null $scopes If creating an oauth2 service, array of scopes |
||
99 | * @param UriInterface|null $baseApiUri |
||
100 | * @param string $apiVersion version of the api call |
||
101 | * |
||
102 | * @return ServiceInterface |
||
103 | */ |
||
104 | public function createService( |
||
134 | |||
135 | /** |
||
136 | * Gets the fully qualified name of the service |
||
137 | * |
||
138 | * @param string $serviceName The name of the service of which to get the fully qualified name |
||
139 | * @param string $type The type of the service to get (either OAuth1 or OAuth2) |
||
140 | * |
||
141 | * @return string The fully qualified name of the service |
||
142 | */ |
||
143 | private function getFullyQualifiedServiceName($serviceName, $type) |
||
153 | |||
154 | /** |
||
155 | * Builds v2 services |
||
156 | * |
||
157 | * @param string $serviceName The fully qualified service name |
||
158 | * @param CredentialsInterface $credentials |
||
159 | * @param TokenStorageInterface $storage |
||
160 | * @param array|null $scopes Array of scopes for the service |
||
161 | * @param UriInterface|null $baseApiUri |
||
162 | * |
||
163 | * @return ServiceInterface |
||
164 | * |
||
165 | * @throws Exception |
||
166 | */ |
||
167 | private function buildV2Service( |
||
184 | |||
185 | /** |
||
186 | * Resolves scopes for v2 services |
||
187 | * |
||
188 | * @param string $serviceName The fully qualified service name |
||
189 | * @param array $scopes List of scopes for the service |
||
190 | * |
||
191 | * @return array List of resolved scopes |
||
192 | */ |
||
193 | private function resolveScopes($serviceName, array $scopes) |
||
211 | |||
212 | /** |
||
213 | * Builds v1 services |
||
214 | * |
||
215 | * @param string $serviceName The fully qualified service name |
||
216 | * @param CredentialsInterface $credentials |
||
217 | * @param TokenStorageInterface $storage |
||
218 | * @param array $scopes |
||
219 | * @param UriInterface $baseApiUri |
||
220 | * |
||
221 | * @return ServiceInterface |
||
222 | * |
||
223 | * @throws Exception |
||
224 | */ |
||
225 | private function buildV1Service( |
||
240 | } |
||
241 |