Checks if the types of the passed arguments in a function/method call are compatible.
1 | <?php |
||
2 | |||
3 | namespace Backend\Modules\Analytics\GoogleClient; |
||
4 | |||
5 | use Google_Auth_AssertionCredentials; |
||
6 | use Google_Cache_File; |
||
7 | use Google_Client; |
||
8 | use Google_Config; |
||
9 | use Google_Service_Analytics; |
||
10 | use Common\ModulesSettings; |
||
11 | |||
12 | /** |
||
13 | * Factory to easily create google client instances |
||
14 | */ |
||
15 | class ClientFactory |
||
16 | { |
||
17 | /** |
||
18 | * @var ModulesSettings |
||
19 | */ |
||
20 | private $settings; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $cacheDir; |
||
26 | |||
27 | 5 | public function __construct(ModulesSettings $modulesSettings, string $cacheDir) |
|
28 | { |
||
29 | 5 | $this->settings = $modulesSettings; |
|
30 | 5 | $this->cacheDir = $cacheDir; |
|
31 | 5 | } |
|
32 | |||
33 | 5 | public function createClient(): Google_Client |
|
34 | { |
||
35 | 5 | $config = new Google_Config(); |
|
36 | 5 | $config->setClassConfig(Google_Cache_File::class, ['directory' => $this->cacheDir]); |
|
37 | 5 | $client = new Google_Client($config); |
|
38 | |||
39 | // set assertion credentials |
||
40 | 5 | $client->setAssertionCredentials( |
|
41 | 5 | new Google_Auth_AssertionCredentials( |
|
42 | 5 | $this->settings->get('Analytics', 'email'), |
|
43 | 5 | ['https://www.googleapis.com/auth/analytics.readonly'], |
|
44 | 5 | base64_decode($this->settings->get('Analytics', 'certificate')) |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
45 | ) |
||
46 | ); |
||
47 | |||
48 | 5 | $client->setAccessType('offline_access'); |
|
49 | |||
50 | 5 | return $client; |
|
51 | } |
||
52 | |||
53 | 5 | public function createAnalyticsService(): Google_Service_Analytics |
|
54 | { |
||
55 | 5 | return new Google_Service_Analytics($this->createClient()); |
|
56 | } |
||
57 | } |
||
58 |