22
33namespace Bookboon \ApiBundle \Service ;
44
5-
65use Bookboon \Api \Bookboon ;
7- use Bookboon \Api \Cache \Cache ;
86use Bookboon \Api \Client \Headers ;
97use Bookboon \Api \Client \Oauth \OauthGrants ;
108use Bookboon \Api \Client \OauthClient ;
119use Bookboon \ApiBundle \Helper \ConfigurationHolder ;
10+ use Psr \SimpleCache \CacheInterface ;
1211
1312class ApiFactory
1413{
1514 /**
1615 * @param ConfigurationHolder $config
17- * @param Cache $cache
16+ * @param CacheInterface $cache
1817 * @return Bookboon
1918 */
20- public static function create (ConfigurationHolder $ config , Cache $ cache )
19+ public static function create (ConfigurationHolder $ config , CacheInterface $ cache )
2120 {
2221 $ bookboon = new Bookboon (
2322 new OauthClient (
@@ -26,7 +25,7 @@ public static function create(ConfigurationHolder $config, Cache $cache)
2625 self ::headersFromConfig ($ config ),
2726 $ config ->getScopes (),
2827 $ cache ,
29- "" ,
28+ '' ,
3029 null ,
3130 $ config ->getOverrideAuthUri (),
3231 $ config ->getOverrideApiUri ()
@@ -38,15 +37,15 @@ public static function create(ConfigurationHolder $config, Cache $cache)
3837 return $ bookboon ;
3938 }
4039
41- public static function credentialFactory (Bookboon $ bookboon , Cache $ cache , ConfigurationHolder $ config )
40+ public static function credentialFactory (Bookboon $ bookboon , CacheInterface $ cache , ConfigurationHolder $ config )
4241 {
4342 $ token = $ cache ->get ("bookboonapi. {$ config ->getId ()}" );
4443
45- if ($ token === false ) {
44+ if ($ token === null ) {
4645 $ token = $ bookboon ->getClient ()->requestAccessToken ([], OauthGrants::CLIENT_CREDENTIALS );
4746
4847 $ ttl = $ token ->getExpires () - time ();
49- $ cache ->save ("bookboonapi. {$ config ->getId ()}" , $ token , $ ttl );
48+ $ cache ->set ("bookboonapi. {$ config ->getId ()}" , $ token , $ ttl );
5049 }
5150
5251 return $ token ;
@@ -87,10 +86,10 @@ private static function headersFromConfig(ConfigurationHolder $config)
8786 */
8887 private static function createAcceptLanguageString ($ languages )
8988 {
90- $ acceptLanguage = "" ;
91- for ($ i =0 ; count ($ languages ) > $ i ; $ i ++) {
89+ $ acceptLanguage = '' ;
90+ for ($ i =0 , $ iMax = count ($ languages ); $ iMax > $ i ; $ i ++) {
9291 /* TODO: logic might need to be updated if $i > 10 */
93- $ acceptLanguage .= $ i == 0 ? $ languages [$ i ] . ', ' : $ languages [$ i ] . ';q= ' . (1 - $ i /10 ) . ', ' ;
92+ $ acceptLanguage .= $ i === 0 ? $ languages [$ i ] . ', ' : $ languages [$ i ] . ';q= ' . (1 - $ i /10 ) . ', ' ;
9493 }
9594 return rtrim ($ acceptLanguage ,', ' );
9695 }
0 commit comments