Google_Config

A class to contain the library configuration for the Google API client.

Defined (1)

The class is defined in the following location(s).

/vendor/google/apiclient/src/Google/Config.php  
  1. class Google_Config 
  2. const GZIP_DISABLED = true; 
  3. const GZIP_ENABLED = false; 
  4. const GZIP_UPLOADS_ENABLED = true; 
  5. const GZIP_UPLOADS_DISABLED = false; 
  6. const USE_AUTO_IO_SELECTION = "auto"; 
  7. const TASK_RETRY_NEVER = 0; 
  8. const TASK_RETRY_ONCE = 1; 
  9. const TASK_RETRY_ALWAYS = -1; 
  10. protected $configuration; 
  11.  
  12. /** 
  13. * Create a new Google_Config. Can accept an ini file location with the 
  14. * local configuration. For example: 
  15. * application_name="My App" 
  16. * @param [$ini_file_location] - optional - The location of the ini file to load 
  17. */ 
  18. public function __construct($ini_file_location = null) 
  19. $this->configuration = array( 
  20. // The application_name is included in the User-Agent HTTP header. 
  21. 'application_name' => '',  
  22.  
  23. // Which Authentication, Storage and HTTP IO classes to use. 
  24. 'auth_class' => 'Google_Auth_OAuth2',  
  25. 'io_class' => self::USE_AUTO_IO_SELECTION,  
  26. 'cache_class' => 'Google_Cache_File',  
  27. 'logger_class' => 'Google_Logger_Null',  
  28.  
  29. // Don't change these unless you're working against a special development 
  30. // or testing environment. 
  31. 'base_path' => 'https://www.googleapis.com',  
  32.  
  33. // Definition of class specific values, like file paths and so on. 
  34. 'classes' => array( 
  35. 'Google_IO_Abstract' => array( 
  36. 'request_timeout_seconds' => 100,  
  37. ),  
  38. 'Google_IO_Curl' => array( 
  39. 'disable_proxy_workaround' => false,  
  40. 'options' => null,  
  41. ),  
  42. 'Google_Logger_Abstract' => array( 
  43. 'level' => 'debug',  
  44. 'log_format' => "[%datetime%] %level%: %message% %context%\n",  
  45. 'date_format' => 'd/M/Y:H:i:s O',  
  46. 'allow_newlines' => true 
  47. ),  
  48. 'Google_Logger_File' => array( 
  49. 'file' => 'php://stdout',  
  50. 'mode' => 0640,  
  51. 'lock' => false,  
  52. ),  
  53. 'Google_Http_Request' => array( 
  54. // Disable the use of gzip on calls if set to true. Defaults to false. 
  55. 'disable_gzip' => self::GZIP_ENABLED,  
  56.  
  57. // We default gzip to disabled on uploads even if gzip is otherwise 
  58. // enabled, due to some issues seen with small packet sizes for uploads. 
  59. // Please test with this option before enabling gzip for uploads in 
  60. // a production environment. 
  61. 'enable_gzip_for_uploads' => self::GZIP_UPLOADS_DISABLED,  
  62. ),  
  63. // If you want to pass in OAuth 2.0 settings, they will need to be 
  64. // structured like this. 
  65. 'Google_Auth_OAuth2' => array( 
  66. // Keys for OAuth 2.0 access, see the API console at 
  67. // https://developers.google.com/console 
  68. 'client_id' => '',  
  69. 'client_secret' => '',  
  70. 'redirect_uri' => '',  
  71.  
  72. // Simple API access key, also from the API console. Ensure you get 
  73. // a Server key, and not a Browser key. 
  74. 'developer_key' => '',  
  75.  
  76. // Other parameters. 
  77. 'hd' => '',  
  78. 'prompt' => '',  
  79. 'openid.realm' => '',  
  80. 'include_granted_scopes' => '',  
  81. 'login_hint' => '',  
  82. 'request_visible_actions' => '',  
  83. 'access_type' => 'online',  
  84. 'approval_prompt' => 'auto',  
  85. 'federated_signon_certs_url' => 
  86. 'https://www.googleapis.com/oauth2/v1/certs',  
  87. ),  
  88. 'Google_Task_Runner' => array( 
  89. // Delays are specified in seconds 
  90. 'initial_delay' => 1,  
  91. 'max_delay' => 60,  
  92. // Base number for exponential backoff 
  93. 'factor' => 2,  
  94. // A random number between -jitter and jitter will be added to the 
  95. // factor on each iteration to allow for better distribution of 
  96. // retries. 
  97. 'jitter' => .5,  
  98. // Maximum number of retries allowed 
  99. 'retries' => 0 
  100. ),  
  101. 'Google_Service_Exception' => array( 
  102. 'retry_map' => array( 
  103. '500' => self::TASK_RETRY_ALWAYS,  
  104. '503' => self::TASK_RETRY_ALWAYS,  
  105. 'rateLimitExceeded' => self::TASK_RETRY_ALWAYS,  
  106. 'userRateLimitExceeded' => self::TASK_RETRY_ALWAYS 
  107. ),  
  108. 'Google_IO_Exception' => array( 
  109. 'retry_map' => !extension_loaded('curl') ? array() : array( 
  110. CURLE_COULDNT_RESOLVE_HOST => self::TASK_RETRY_ALWAYS,  
  111. CURLE_COULDNT_CONNECT => self::TASK_RETRY_ALWAYS,  
  112. CURLE_OPERATION_TIMEOUTED => self::TASK_RETRY_ALWAYS,  
  113. CURLE_SSL_CONNECT_ERROR => self::TASK_RETRY_ALWAYS,  
  114. CURLE_GOT_NOTHING => self::TASK_RETRY_ALWAYS 
  115. ),  
  116. // Set a default directory for the file cache. 
  117. 'Google_Cache_File' => array( 
  118. 'directory' => sys_get_temp_dir() . '/Google_Client' 
  119. ),  
  120. ); 
  121. if ($ini_file_location) { 
  122. $ini = parse_ini_file($ini_file_location, true); 
  123. if (is_array($ini) && count($ini)) { 
  124. $merged_configuration = $ini + $this->configuration; 
  125. if (isset($ini['classes']) && isset($this->configuration['classes'])) { 
  126. $merged_configuration['classes'] = $ini['classes'] + $this->configuration['classes']; 
  127. $this->configuration = $merged_configuration; 
  128.  
  129. /** 
  130. * Set configuration specific to a given class. 
  131. * $config->setClassConfig('Google_Cache_File',  
  132. * array('directory' => '/tmp/cache')); 
  133. * @param $class string The class name for the configuration 
  134. * @param $config string key or an array of configuration values 
  135. * @param $value string optional - if $config is a key, the value 
  136. */ 
  137. public function setClassConfig($class, $config, $value = null) 
  138. if (!is_array($config)) { 
  139. if (!isset($this->configuration['classes'][$class])) { 
  140. $this->configuration['classes'][$class] = array(); 
  141. $this->configuration['classes'][$class][$config] = $value; 
  142. } else { 
  143. $this->configuration['classes'][$class] = $config; 
  144.  
  145. public function getClassConfig($class, $key = null) 
  146. if (!isset($this->configuration['classes'][$class])) { 
  147. return null; 
  148. if ($key === null) { 
  149. return $this->configuration['classes'][$class]; 
  150. } else { 
  151. return $this->configuration['classes'][$class][$key]; 
  152.  
  153. /** 
  154. * Return the configured cache class. 
  155. * @return string 
  156. */ 
  157. public function getCacheClass() 
  158. return $this->configuration['cache_class']; 
  159.  
  160. /** 
  161. * Return the configured logger class. 
  162. * @return string 
  163. */ 
  164. public function getLoggerClass() 
  165. return $this->configuration['logger_class']; 
  166.  
  167. /** 
  168. * Return the configured Auth class. 
  169. * @return string 
  170. */ 
  171. public function getAuthClass() 
  172. return $this->configuration['auth_class']; 
  173.  
  174. /** 
  175. * Set the auth class. 
  176. * @param $class string the class name to set 
  177. */ 
  178. public function setAuthClass($class) 
  179. $prev = $this->configuration['auth_class']; 
  180. if (!isset($this->configuration['classes'][$class]) && 
  181. isset($this->configuration['classes'][$prev])) { 
  182. $this->configuration['classes'][$class] = 
  183. $this->configuration['classes'][$prev]; 
  184. $this->configuration['auth_class'] = $class; 
  185.  
  186. /** 
  187. * Set the IO class. 
  188. * @param $class string the class name to set 
  189. */ 
  190. public function setIoClass($class) 
  191. $prev = $this->configuration['io_class']; 
  192. if (!isset($this->configuration['classes'][$class]) && 
  193. isset($this->configuration['classes'][$prev])) { 
  194. $this->configuration['classes'][$class] = 
  195. $this->configuration['classes'][$prev]; 
  196. $this->configuration['io_class'] = $class; 
  197.  
  198. /** 
  199. * Set the cache class. 
  200. * @param $class string the class name to set 
  201. */ 
  202. public function setCacheClass($class) 
  203. $prev = $this->configuration['cache_class']; 
  204. if (!isset($this->configuration['classes'][$class]) && 
  205. isset($this->configuration['classes'][$prev])) { 
  206. $this->configuration['classes'][$class] = 
  207. $this->configuration['classes'][$prev]; 
  208. $this->configuration['cache_class'] = $class; 
  209.  
  210. /** 
  211. * Set the logger class. 
  212. * @param $class string the class name to set 
  213. */ 
  214. public function setLoggerClass($class) 
  215. $prev = $this->configuration['logger_class']; 
  216. if (!isset($this->configuration['classes'][$class]) && 
  217. isset($this->configuration['classes'][$prev])) { 
  218. $this->configuration['classes'][$class] = 
  219. $this->configuration['classes'][$prev]; 
  220. $this->configuration['logger_class'] = $class; 
  221.  
  222. /** 
  223. * Return the configured IO class. 
  224. * @return string 
  225. */ 
  226. public function getIoClass() 
  227. return $this->configuration['io_class']; 
  228.  
  229. /** 
  230. * Set the application name, this is included in the User-Agent HTTP header. 
  231. * @param string $name 
  232. */ 
  233. public function setApplicationName($name) 
  234. $this->configuration['application_name'] = $name; 
  235.  
  236. /** 
  237. * @return string the name of the application 
  238. */ 
  239. public function getApplicationName() 
  240. return $this->configuration['application_name']; 
  241.  
  242. /** 
  243. * Set the client ID for the auth class. 
  244. * @param $clientId string - the API console client ID 
  245. */ 
  246. public function setClientId($clientId) 
  247. $this->setAuthConfig('client_id', $clientId); 
  248.  
  249. /** 
  250. * Set the client secret for the auth class. 
  251. * @param $secret string - the API console client secret 
  252. */ 
  253. public function setClientSecret($secret) 
  254. $this->setAuthConfig('client_secret', $secret); 
  255.  
  256. /** 
  257. * Set the redirect uri for the auth class. Note that if using the 
  258. * Javascript based sign in flow, this should be the string 'postmessage'. 
  259. * @param $uri string - the URI that users should be redirected to 
  260. */ 
  261. public function setRedirectUri($uri) 
  262. $this->setAuthConfig('redirect_uri', $uri); 
  263.  
  264. /** 
  265. * Set the app activities for the auth class. 
  266. * @param $rva string a space separated list of app activity types 
  267. */ 
  268. public function setRequestVisibleActions($rva) 
  269. $this->setAuthConfig('request_visible_actions', $rva); 
  270.  
  271. /** 
  272. * Set the the access type requested (offline or online.) 
  273. * @param $access string - the access type 
  274. */ 
  275. public function setAccessType($access) 
  276. $this->setAuthConfig('access_type', $access); 
  277.  
  278. /** 
  279. * Set when to show the approval prompt (auto or force) 
  280. * @param $approval string - the approval request 
  281. */ 
  282. public function setApprovalPrompt($approval) 
  283. $this->setAuthConfig('approval_prompt', $approval); 
  284.  
  285. /** 
  286. * Set the login hint (email address or sub identifier) 
  287. * @param $hint string 
  288. */ 
  289. public function setLoginHint($hint) 
  290. $this->setAuthConfig('login_hint', $hint); 
  291.  
  292. /** 
  293. * Set the developer key for the auth class. Note that this is separate value 
  294. * from the client ID - if it looks like a URL, its a client ID! 
  295. * @param $key string - the API console developer key 
  296. */ 
  297. public function setDeveloperKey($key) 
  298. $this->setAuthConfig('developer_key', $key); 
  299.  
  300. /** 
  301. * Set the hd (hosted domain) parameter streamlines the login process for 
  302. * Google Apps hosted accounts. By including the domain of the user, you 
  303. * restrict sign-in to accounts at that domain. 
  304. * This should not be used to ensure security on your application - check 
  305. * the hd values within an id token (@see Google_Auth_LoginTicket) after sign 
  306. * in to ensure that the user is from the domain you were expecting. 
  307. * @param $hd string - the domain to use. 
  308. */ 
  309. public function setHostedDomain($hd) 
  310. $this->setAuthConfig('hd', $hd); 
  311.  
  312. /** 
  313. * Set the prompt hint. Valid values are none, consent and select_account. 
  314. * If no value is specified and the user has not previously authorized 
  315. * access, then the user is shown a consent screen. 
  316. * @param $prompt string 
  317. */ 
  318. public function setPrompt($prompt) 
  319. $this->setAuthConfig('prompt', $prompt); 
  320.  
  321. /** 
  322. * openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth 
  323. * 2.0. It is used in OpenID 2.0 requests to signify the URL-space for which 
  324. * an authentication request is valid. 
  325. * @param $realm string - the URL-space to use. 
  326. */ 
  327. public function setOpenidRealm($realm) 
  328. $this->setAuthConfig('openid.realm', $realm); 
  329.  
  330. /** 
  331. * If this is provided with the value true, and the authorization request is 
  332. * granted, the authorization will include any previous authorizations 
  333. * granted to this user/application combination for other scopes. 
  334. * @param $include boolean - the URL-space to use. 
  335. */ 
  336. public function setIncludeGrantedScopes($include) 
  337. $this->setAuthConfig( 
  338. 'include_granted_scopes',  
  339. $include ? "true" : "false" 
  340. ); 
  341.  
  342. /** 
  343. * @return string the base URL to use for API calls 
  344. */ 
  345. public function getBasePath() 
  346. return $this->configuration['base_path']; 
  347.  
  348. /** 
  349. * Set the auth configuration for the current auth class. 
  350. * @param $key - the key to set 
  351. * @param $value - the parameter value 
  352. */ 
  353. private function setAuthConfig($key, $value) 
  354. if (!isset($this->configuration['classes'][$this->getAuthClass()])) { 
  355. $this->configuration['classes'][$this->getAuthClass()] = array(); 
  356. $this->configuration['classes'][$this->getAuthClass()][$key] = $value;