GoogleGAL_Config

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

Defined (1)

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

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