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/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. private $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. 'access_type' => 'online',  
  59. 'approval_prompt' => 'auto',  
  60. 'request_visible_actions' => '',  
  61. 'federated_signon_certs_url' => 
  62. 'https://www.googleapis.com/oauth2/v1/certs',  
  63. ),  
  64. // Set a default directory for the file cache. 
  65. 'Google_Cache_File' => array( 
  66. 'directory' => sys_get_temp_dir() . '/Google_Client' 
  67. ),  
  68.  
  69. // Definition of service specific values like scopes, oauth token URLs,  
  70. // etc. Example: 
  71. 'services' => array( 
  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 developer key for the auth class. Note that this is separate value 
  218. * from the client ID - if it looks like a URL, its a client ID! 
  219. * @param $key string - the API console developer key 
  220. */ 
  221. public function setDeveloperKey($key) 
  222. $this->setAuthConfig('developer_key', $key); 
  223.  
  224. /** 
  225. * @return string the base URL to use for API calls 
  226. */ 
  227. public function getBasePath() 
  228. return $this->configuration['base_path']; 
  229.  
  230. /** 
  231. * Set the auth configuration for the current auth class. 
  232. * @param $key - the key to set 
  233. * @param $value - the parameter value 
  234. */ 
  235. private function setAuthConfig($key, $value) 
  236. if (!isset($this->configuration['classes'][$this->getAuthClass()])) { 
  237. $this->configuration['classes'][$this->getAuthClass()] = array(); 
  238. $this->configuration['classes'][$this->getAuthClass()][$key] = $value;