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

/lib/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. protected $configuration; 
  8.  
  9. /** 
  10. * Create a new Google_Config. Can accept an ini file location with the 
  11. * local configuration. For example: 
  12. * application_name="My App" 
  13. * @param [$ini_file_location] - optional - The location of the ini file to load 
  14. */ 
  15. public function __construct($ini_file_location = null) 
  16. $this->configuration = array( 
  17. // The application_name is included in the User-Agent HTTP header. 
  18. 'application_name' => '',  
  19.  
  20. // Which Authentication, Storage and HTTP IO classes to use. 
  21. 'auth_class' => 'Google_Auth_OAuth2',  
  22. 'io_class' => self::USE_AUTO_IO_SELECTION,  
  23. 'cache_class' => 'Google_Cache_File',  
  24.  
  25. // Don't change these unless you're working against a special development 
  26. // or testing environment. 
  27. 'base_path' => 'https://www.googleapis.com',  
  28.  
  29. // Definition of class specific values, like file paths and so on. 
  30. 'classes' => array( 
  31. 'Google_IO_Abstract' => array( 
  32. 'request_timeout_seconds' => 100,  
  33. ),  
  34. 'Google_Http_Request' => array( 
  35. // Disable the use of gzip on calls if set to true. Defaults to false. 
  36. 'disable_gzip' => self::GZIP_ENABLED,  
  37.  
  38. // We default gzip to disabled on uploads even if gzip is otherwise 
  39. // enabled, due to some issues seen with small packet sizes for uploads. 
  40. // Please test with this option before enabling gzip for uploads in 
  41. // a production environment. 
  42. 'enable_gzip_for_uploads' => self::GZIP_UPLOADS_DISABLED,  
  43. ),  
  44. // If you want to pass in OAuth 2.0 settings, they will need to be 
  45. // structured like this. 
  46. 'Google_Auth_OAuth2' => array( 
  47. // Keys for OAuth 2.0 access, see the API console at 
  48. // https://developers.google.com/console 
  49. 'client_id' => '',  
  50. 'client_secret' => '',  
  51. 'redirect_uri' => '',  
  52.  
  53. // Simple API access key, also from the API console. Ensure you get 
  54. // a Server key, and not a Browser key. 
  55. 'developer_key' => '',  
  56.  
  57. // Other parameters. 
  58. 'hd' => '',  
  59. 'prompt' => '',  
  60. 'openid.realm' => '',  
  61. 'include_granted_scopes' => '',  
  62. 'login_hint' => '',  
  63. 'request_visible_actions' => '',  
  64. 'access_type' => 'online',  
  65. 'approval_prompt' => 'auto',  
  66. 'federated_signon_certs_url' => 
  67. 'https://www.googleapis.com/oauth2/v1/certs',  
  68. ),  
  69. // Set a default directory for the file cache. 
  70. 'Google_Cache_File' => array( 
  71. 'directory' => sys_get_temp_dir() . '/Google_Client' 
  72. ),  
  73. ); 
  74. if ($ini_file_location) { 
  75. $ini = parse_ini_file($ini_file_location, true); 
  76. if (is_array($ini) && count($ini)) { 
  77. $this->configuration = array_merge($this->configuration, $ini); 
  78.  
  79. /** 
  80. * Set configuration specific to a given class. 
  81. * $config->setClassConfig('Google_Cache_File',  
  82. * array('directory' => '/tmp/cache')); 
  83. * @param $class The class name for the configuration 
  84. * @param $config string key or an array of configuration values 
  85. * @param $value optional - if $config is a key, the value 
  86. */ 
  87. public function setClassConfig($class, $config, $value = null) 
  88. if (!is_array($config)) { 
  89. if (!isset($this->configuration['classes'][$class])) { 
  90. $this->configuration['classes'][$class] = array(); 
  91. $this->configuration['classes'][$class][$config] = $value; 
  92. } else { 
  93. $this->configuration['classes'][$class] = $config; 
  94.  
  95. public function getClassConfig($class, $key = null) 
  96. if (!isset($this->configuration['classes'][$class])) { 
  97. return null; 
  98. if ($key === null) { 
  99. return $this->configuration['classes'][$class]; 
  100. } else { 
  101. return $this->configuration['classes'][$class][$key]; 
  102.  
  103. /** 
  104. * Return the configured cache class. 
  105. * @return string 
  106. */ 
  107. public function getCacheClass() 
  108. return $this->configuration['cache_class']; 
  109.  
  110. /** 
  111. * Return the configured Auth class. 
  112. * @return string 
  113. */ 
  114. public function getAuthClass() 
  115. return $this->configuration['auth_class']; 
  116.  
  117. /** 
  118. * Set the auth class. 
  119. * @param $class the class name to set 
  120. */ 
  121. public function setAuthClass($class) 
  122. $prev = $this->configuration['auth_class']; 
  123. if (!isset($this->configuration['classes'][$class]) && 
  124. isset($this->configuration['classes'][$prev])) { 
  125. $this->configuration['classes'][$class] = 
  126. $this->configuration['classes'][$prev]; 
  127. $this->configuration['auth_class'] = $class; 
  128.  
  129. /** 
  130. * Set the IO class. 
  131. * @param $class the class name to set 
  132. */ 
  133. public function setIoClass($class) 
  134. $prev = $this->configuration['io_class']; 
  135. if (!isset($this->configuration['classes'][$class]) && 
  136. isset($this->configuration['classes'][$prev])) { 
  137. $this->configuration['classes'][$class] = 
  138. $this->configuration['classes'][$prev]; 
  139. $this->configuration['io_class'] = $class; 
  140.  
  141. /** 
  142. * Set the cache class. 
  143. * @param $class the class name to set 
  144. */ 
  145. public function setCacheClass($class) 
  146. $prev = $this->configuration['cache_class']; 
  147. if (!isset($this->configuration['classes'][$class]) && 
  148. isset($this->configuration['classes'][$prev])) { 
  149. $this->configuration['classes'][$class] = 
  150. $this->configuration['classes'][$prev]; 
  151. $this->configuration['cache_class'] = $class; 
  152.  
  153. /** 
  154. * Return the configured IO class. 
  155. * @return string 
  156. */ 
  157. public function getIoClass() 
  158. return $this->configuration['io_class']; 
  159.  
  160. /** 
  161. * Set the application name, this is included in the User-Agent HTTP header. 
  162. * @param string $name 
  163. */ 
  164. public function setApplicationName($name) 
  165. $this->configuration['application_name'] = $name; 
  166.  
  167. /** 
  168. * @return string the name of the application 
  169. */ 
  170. public function getApplicationName() 
  171. return $this->configuration['application_name']; 
  172.  
  173. /** 
  174. * Set the client ID for the auth class. 
  175. * @param $key string - the API console client ID 
  176. */ 
  177. public function setClientId($clientId) 
  178. $this->setAuthConfig('client_id', $clientId); 
  179.  
  180. /** 
  181. * Set the client secret for the auth class. 
  182. * @param $key string - the API console client secret 
  183. */ 
  184. public function setClientSecret($secret) 
  185. $this->setAuthConfig('client_secret', $secret); 
  186.  
  187. /** 
  188. * Set the redirect uri for the auth class. Note that if using the 
  189. * Javascript based sign in flow, this should be the string 'postmessage'. 
  190. * @param $key string - the URI that users should be redirected to 
  191. */ 
  192. public function setRedirectUri($uri) 
  193. $this->setAuthConfig('redirect_uri', $uri); 
  194.  
  195. /** 
  196. * Set the app activities for the auth class. 
  197. * @param $rva string a space separated list of app activity types 
  198. */ 
  199. public function setRequestVisibleActions($rva) 
  200. $this->setAuthConfig('request_visible_actions', $rva); 
  201.  
  202. /** 
  203. * Set the the access type requested (offline or online.) 
  204. * @param $access string - the access type 
  205. */ 
  206. public function setAccessType($access) 
  207. $this->setAuthConfig('access_type', $access); 
  208.  
  209. /** 
  210. * Set when to show the approval prompt (auto or force) 
  211. * @param $approval string - the approval request 
  212. */ 
  213. public function setApprovalPrompt($approval) 
  214. $this->setAuthConfig('approval_prompt', $approval); 
  215.  
  216. /** 
  217. * Set the login hint (email address or sub identifier) 
  218. * @param $hint string 
  219. */ 
  220. public function setLoginHint($hint) 
  221. $this->setAuthConfig('login_hint', $hint); 
  222.  
  223. /** 
  224. * Set the developer key for the auth class. Note that this is separate value 
  225. * from the client ID - if it looks like a URL, its a client ID! 
  226. * @param $key string - the API console developer key 
  227. */ 
  228. public function setDeveloperKey($key) 
  229. $this->setAuthConfig('developer_key', $key); 
  230.  
  231. /** 
  232. * Set the hd (hosted domain) parameter streamlines the login process for 
  233. * Google Apps hosted accounts. By including the domain of the user, you 
  234. * restrict sign-in to accounts at that domain. 
  235. * @param $hd string - the domain to use. 
  236. */ 
  237. public function setHostedDomain($hd) 
  238. $this->setAuthConfig('hd', $hd); 
  239.  
  240. /** 
  241. * Set the prompt hint. Valid values are none, consent and select_account. 
  242. * If no value is specified and the user has not previously authorized 
  243. * access, then the user is shown a consent screen. 
  244. * @param $prompt string 
  245. */ 
  246. public function setPrompt($prompt) 
  247. $this->setAuthConfig('prompt', $prompt); 
  248.  
  249. /** 
  250. * openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth 
  251. * 2.0. It is used in OpenID 2.0 requests to signify the URL-space for which 
  252. * an authentication request is valid. 
  253. * @param $realm string - the URL-space to use. 
  254. */ 
  255. public function setOpenidRealm($realm) 
  256. $this->setAuthConfig('openid.realm', $realm); 
  257.  
  258. /** 
  259. * If this is provided with the value true, and the authorization request is 
  260. * granted, the authorization will include any previous authorizations 
  261. * granted to this user/application combination for other scopes. 
  262. * @param $include boolean - the URL-space to use. 
  263. */ 
  264. public function setIncludeGrantedScopes($include) 
  265. $this->setAuthConfig( 
  266. 'include_granted_scopes',  
  267. $include ? "true" : "false" 
  268. ); 
  269.  
  270. /** 
  271. * @return string the base URL to use for API calls 
  272. */ 
  273. public function getBasePath() 
  274. return $this->configuration['base_path']; 
  275.  
  276. /** 
  277. * Set the auth configuration for the current auth class. 
  278. * @param $key - the key to set 
  279. * @param $value - the parameter value 
  280. */ 
  281. private function setAuthConfig($key, $value) 
  282. if (!isset($this->configuration['classes'][$this->getAuthClass()])) { 
  283. $this->configuration['classes'][$this->getAuthClass()] = array(); 
  284. $this->configuration['classes'][$this->getAuthClass()][$key] = $value;