1- <?php
2- namespace LangleyFoxall \SimpleGoogleMaps \Objects \ApiAuthDrivers ;
3-
4- use LangleyFoxall \SimpleGoogleMaps \Interfaces \ApiAuthInterface ;
5- use Exception ;
6-
7- /**
8- * Class EnterpriseApiAuthDriver
9- * @package LangleyFoxall\SimpleGoogleMaps\Objects\ApiAuthDrivers
10- */
11- class EnterpriseApiAuthDriver implements ApiAuthInterface
12- {
13- /**
14- * @var string API client name
15- */
16- private $ clientName ;
17- /**
18- * @var string API crypt key
19- */
20- private $ cryptKey ;
21-
22- /**
23- * EnterpriseApiAuthDriver constructor.
24- * @param $clientName
25- * @param $cryptKey
26- * @throws Exception
27- */
28- public function __construct ($ clientName , $ cryptKey )
29- {
30- if (!$ clientName ){
31- throw new Exception ("ClientName not set " );
32- }
33-
34- if (!$ cryptKey ){
35- throw new Exception ("CryptKey not set " );
36- }
37- $ this ->clientName = $ clientName ;
38- $ this ->cryptKey = $ cryptKey ;
39- }
40-
41- /**
42- * @param $url
43- * @return string
44- */
45- public function applyToUrl ($ url )
46- {
47- $ urlWithClient = $ url ."&client= " .$ this ->clientName ;
48-
49- $ parsedUrl = parse_url ($ urlWithClient );
50-
51- $ urlToEncode = $ parsedUrl ['path ' ].'? ' .$ parsedUrl ['query ' ];
52- $ baseKey = base64_decode (str_replace (array ('- ' , '_ ' ), array ('+ ' , '/ ' ), $ this ->cryptKey ));
53-
54- $ signature = hash_hmac ('sha1 ' , $ urlToEncode , $ baseKey , true );
55-
56- $ encodedSignature = str_replace (array ('+ ' , '/ ' ), array ('- ' , '_ ' ), base64_encode ($ signature ));
57-
58- $ appendedUrl = $ urlWithClient ."&signature= " .$ encodedSignature ;
59-
60- return $ appendedUrl ;
61- }
62- }
63-
64- ?>
1+ <?php
2+
3+ namespace LangleyFoxall \SimpleGoogleMaps \Objects \ApiAuthDrivers ;
4+
5+ use Exception ;
6+ use LangleyFoxall \SimpleGoogleMaps \Interfaces \ApiAuthInterface ;
7+
8+ /**
9+ * Class EnterpriseApiAuthDriver.
10+ */
11+ class EnterpriseApiAuthDriver implements ApiAuthInterface
12+ {
13+ /**
14+ * @var string API client name
15+ */
16+ private $ clientName ;
17+ /**
18+ * @var string API crypt key
19+ */
20+ private $ cryptKey ;
21+
22+ /**
23+ * EnterpriseApiAuthDriver constructor.
24+ *
25+ * @param $clientName
26+ * @param $cryptKey
27+ *
28+ * @throws Exception
29+ */
30+ public function __construct ($ clientName , $ cryptKey )
31+ {
32+ if (!$ clientName ) {
33+ throw new Exception ('ClientName not set ' );
34+ }
35+
36+ if (!$ cryptKey ) {
37+ throw new Exception ('CryptKey not set ' );
38+ }
39+ $ this ->clientName = $ clientName ;
40+ $ this ->cryptKey = $ cryptKey ;
41+ }
42+
43+ /**
44+ * @param $url
45+ *
46+ * @return string
47+ */
48+ public function applyToUrl ($ url )
49+ {
50+ $ urlWithClient = $ url .'&client= ' .$ this ->clientName ;
51+
52+ $ parsedUrl = parse_url ($ urlWithClient );
53+
54+ $ urlToEncode = $ parsedUrl ['path ' ].'? ' .$ parsedUrl ['query ' ];
55+ $ baseKey = base64_decode (str_replace (['- ' , '_ ' ], ['+ ' , '/ ' ], $ this ->cryptKey ));
56+
57+ $ signature = hash_hmac ('sha1 ' , $ urlToEncode , $ baseKey , true );
58+
59+ $ encodedSignature = str_replace (['+ ' , '/ ' ], ['- ' , '_ ' ], base64_encode ($ signature ));
60+
61+ $ appendedUrl = $ urlWithClient .'&signature= ' .$ encodedSignature ;
62+
63+ return $ appendedUrl ;
64+ }
65+ }
0 commit comments