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).

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