20
20
use Stormpath \Cache \ArrayCacheManager ;
21
21
use Stormpath \Cache \MemcachedCacheManager ;
22
22
use Stormpath \Cache \NullCacheManager ;
23
- use Stormpath \Cache \RedisCacheManager ;
24
23
use Stormpath \Cache \PSR6CacheManagerInterface ;
25
- use Stormpath \Cache \Exceptions \InvalidCacheManagerException ;
26
- use Stormpath \Http \Authc \SAuthc1RequestSigner ;
24
+ use Stormpath \Cache \RedisCacheManager ;
27
25
use Stormpath \Http \DefaultRequest ;
28
26
use Stormpath \Http \HttpClientRequestExecutor ;
29
27
use Stormpath \Http \Request ;
30
28
use Stormpath \Util \Magic ;
31
- use Stormpath \Util \Spyc ;
32
- use Stormpath \Util \YAMLUtil ;
33
29
34
30
/**
35
31
* A <a href="http://en.wikipedia.org/wiki/Builder_pattern">Builder design pattern</a> implementation used to
@@ -57,7 +53,7 @@ class ClientBuilder extends Magic
57
53
private $ apiKeySecretPropertyName = "apiKey.secret " ;
58
54
private $ apiKeyProperties ;
59
55
private $ apiKeyFileLocation ;
60
- private $ cacheManager = NULL ;
56
+ private $ cacheManager = null ;
61
57
private $ cacheManagerOptions = array ();
62
58
private $ baseURL ;
63
59
private $ authenticationScheme = Stormpath::SAUTHC1_AUTHENTICATION_SCHEME ;
@@ -216,7 +212,7 @@ public function setApiKeyProperties($apiKeyProperties)
216
212
217
213
public function setCacheManager ($ cacheManager )
218
214
{
219
- if ($ cacheManager instanceOf PSR6CacheManagerInterface) {
215
+ if ($ cacheManager instanceof PSR6CacheManagerInterface) {
220
216
$ this ->cacheManager = $ cacheManager ;
221
217
} else {
222
218
switch ($ cacheManager ) {
@@ -240,10 +236,10 @@ public function setCacheManager($cacheManager)
240
236
return $ this ;
241
237
}
242
238
243
- public function setCacheManagerOptions (Array $ cacheManagerOptions = array ())
239
+ public function setCacheManagerOptions (array $ cacheManagerOptions = array ())
244
240
{
245
241
$ this ->cacheManagerOptions = $ this ->setCacheOptionsArray ($ cacheManagerOptions );
246
- if (!$ this ->cacheManager ) {
242
+ if (!$ this ->cacheManager ) {
247
243
$ this ->setCacheManager ($ this ->cacheManagerOptions ['cachemanager ' ]);
248
244
}
249
245
return $ this ;
@@ -278,46 +274,39 @@ public function build()
278
274
{
279
275
$ apiKeyProperties = null ;
280
276
281
- if ($ this ->apiKeyProperties )
282
- {
277
+ if ($ this ->apiKeyProperties ) {
283
278
284
279
$ apiKeyProperties = parse_ini_string ($ this ->apiKeyProperties );
285
280
286
- } else
287
- {
281
+ } else {
288
282
289
283
// need to load the properties file
290
284
$ apiKeyProperties = $ this ->getFileExtract ();
291
285
292
- if (!$ apiKeyProperties )
293
- {
286
+ if (!$ apiKeyProperties ) {
294
287
throw new \InvalidArgumentException ('No API Key file could be found or loaded from a file location. ' .
295
288
'Please configure the "apiKeyFileLocation" property or alternatively configure a ' .
296
289
"PHP 'ini' compliant string, by setting the 'apiKeyProperties' property. " );
297
290
}
298
291
}
299
292
300
- if (!$ this ->cacheManager )
301
- {
293
+ if (!$ this ->cacheManager ) {
302
294
$ this ->setCacheManagerOptions ();
303
295
}
304
296
305
-
306
297
$ apiKeyId = $ this ->getRequiredPropertyValue ($ apiKeyProperties , 'apiKeyId ' , $ this ->apiKeyIdPropertyName );
307
298
308
299
$ apiKeySecret = $ this ->getRequiredPropertyValue ($ apiKeyProperties , 'apiKeySecret ' , $ this ->apiKeySecretPropertyName );
309
300
310
301
$ apiKey = new ApiKey ($ apiKeyId , $ apiKeySecret );
311
302
312
- $ signer = $ this ->resolveSigner ();
313
- $ requestSigner = new $ signer ;
314
-
315
303
return new Client (
316
304
$ apiKey ,
317
305
$ this ->cacheManager ,
318
306
$ this ->cacheManagerOptions ,
319
307
$ this ->baseURL ,
320
- $ requestSigner
308
+ null ,
309
+ $ this ->authenticationScheme
321
310
);
322
311
323
312
}
@@ -332,8 +321,7 @@ private function getRequiredPropertyValue(array $apiKeyProperties, $masterName,
332
321
{
333
322
$ result = array_key_exists ($ propertyName , $ apiKeyProperties ) ? $ apiKeyProperties [$ propertyName ] : false ;
334
323
335
- if (!$ result )
336
- {
324
+ if (!$ result ) {
337
325
throw new \InvalidArgumentException ("There is no ' $ propertyName' property in the " .
338
326
"configured apiKey file or properties string. You can either specify that property or " .
339
327
"configure the ' $ masterName' PropertyName value on the ClientBuilder to specify a " .
@@ -346,29 +334,25 @@ private function getRequiredPropertyValue(array $apiKeyProperties, $masterName,
346
334
private function getFileExtract ()
347
335
{
348
336
// @codeCoverageIgnoreStart
349
- if (stripos ($ this ->apiKeyFileLocation , 'http ' ) === 0 )
350
- {
337
+ if (stripos ($ this ->apiKeyFileLocation , 'http ' ) === 0 ) {
351
338
$ request = new DefaultRequest (Request::METHOD_GET , $ this ->apiKeyFileLocation );
352
339
353
340
$ executor = new HttpClientRequestExecutor ;
354
341
355
342
try {
356
343
$ response = $ executor ->executeRequest ($ request );
357
344
358
- if (!$ response ->isError ())
359
- {
345
+ if (!$ response ->isError ()) {
360
346
return parse_ini_string ($ response ->getBody ());
361
347
362
348
}
363
- } catch (Exception $ e )
364
- {
349
+ } catch (Exception $ e ) {
365
350
return false ;
366
351
}
367
352
}
368
353
// @codeCoverageIgnoreEnd
369
354
370
- if ($ this ->apiKeyFileLocation )
371
- {
355
+ if ($ this ->apiKeyFileLocation ) {
372
356
return parse_ini_file ($ this ->apiKeyFileLocation );
373
357
}
374
358
}
@@ -384,25 +368,25 @@ private function setCacheOptionsArray($overrides)
384
368
'regions ' => array (
385
369
'accounts ' => array (
386
370
'ttl ' => 60 ,
387
- 'tti ' => 120
371
+ 'tti ' => 120 ,
388
372
),
389
373
'applications ' => array (
390
374
'ttl ' => 60 ,
391
- 'tti ' => 120
375
+ 'tti ' => 120 ,
392
376
),
393
377
'directories ' => array (
394
378
'ttl ' => 60 ,
395
- 'tti ' => 120
379
+ 'tti ' => 120 ,
396
380
),
397
381
'groups ' => array (
398
382
'ttl ' => 60 ,
399
- 'tti ' => 120
383
+ 'tti ' => 120 ,
400
384
),
401
385
'tenants ' => array (
402
386
'ttl ' => 60 ,
403
- 'tti ' => 120
387
+ 'tti ' => 120 ,
404
388
),
405
- )
389
+ ),
406
390
);
407
391
return array_replace ($ defaults , $ overrides );
408
392
}
@@ -411,30 +395,23 @@ private function qualifyCacheManager($cacheManager)
411
395
{
412
396
$ notCoreClass = true ;
413
397
414
- if (class_exists ($ cacheManager ))
398
+ if (class_exists ($ cacheManager )) {
415
399
$ notCoreClass = class_implements ($ cacheManager ) == 'Stormpath\Cache\CacheManager ' ;
400
+ }
416
401
417
- if (class_exists ($ cacheManager ) && $ notCoreClass ) return $ cacheManager ;
402
+ if (class_exists ($ cacheManager ) && $ notCoreClass ) {
403
+ return $ cacheManager ;
404
+ }
418
405
419
- if (strpos ($ cacheManager , 'CacheManager ' )) {
406
+ if (strpos ($ cacheManager , 'CacheManager ' )) {
420
407
$ cacheManagerPath = "{$ cacheManager }" ;
421
408
} else {
422
409
$ cacheManagerPath = "Stormpath \\Cache \\{$ cacheManager }CacheManager " ;
423
410
}
424
411
425
-
426
- if (class_exists ($ cacheManagerPath )) return $ cacheManagerPath ;
427
-
428
- }
429
-
430
- private function resolveSigner ()
431
- {
432
- $ signer = "\\Stormpath \\Http \\Authc \\" . $ this ->authenticationScheme . "RequestSigner " ;
433
-
434
- if (!class_exists ($ signer ))
435
- throw new \InvalidArgumentException ('Authentication Scheme is not supported. ' );
436
-
437
- return new $ signer ;
412
+ if (class_exists ($ cacheManagerPath )) {
413
+ return $ cacheManagerPath ;
414
+ }
438
415
439
416
}
440
417
}
0 commit comments