-
Notifications
You must be signed in to change notification settings - Fork 23
/
helpers.php
97 lines (83 loc) · 1.88 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
*
* Helper functions to be used anywhere.
*
* All function names are prefixed by an "e" to prevent possible conflicts with any framework functions
*
*/
use Edujugon\GoogleAds\Exceptions\Config;
use Edujugon\GoogleAds\Reports\Fields;
use Edujugon\GoogleAds\Reports\Report;
use Edujugon\GoogleAds\Services\Service;
/**
* Get an instance of Report
* @param null $session
* @return Report
*/
function google_report($session = null)
{
return new Report($session);
}
/**
* Get an instance of Service
* @param Google Service $service
* @param null $session
* @return Service
*/
function google_service($service,$session = null)
{
return new Service($service,$session);
}
/**
* Get an instance of Fields
*
* @param null $session
* @return Fields
*/
function google_report_fields($session = null)
{
return new Fields($session);
}
/**
* Get configuration array data.
*
* @return array
*/
function e_ads_config()
{
if(function_exists('config_path'))
{
if(file_exists(config_path('google-ads.php')))
{
$configuration = include(config_path('google-ads.php'));
return $configuration;
}
}
$configuration = include(__DIR__ . '/../Config/config.php');
return $configuration;
}
/**
* Get the adwords configuration based on the environment.
* If env is not passed as parameter it'll take the env value from config file.
*
* @param null $env
* @return mixed
* @throws Config
*/
function e_ads_config_google_ads($env = null)
{
$config = e_ads_config();
if($env && !array_key_exists($env,$config))
throw new Config('Please provide a correct environment. Available options: production/test');
return $env ? $config[$env] : $config[$config['env']];
}
/**
* Get the oAuth2 configuration
* @return mixed
*/
function e_config_oauth()
{
$config = e_ads_config();
return $config['oAuth2'];
}