PluginProbe
InfiniteWP Client / trunk
InfiniteWP Client vtrunk
1.13.10 1.13.7 trunk 0.1.4 0.1.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.11.0 1.11.1 1.12.1 1.12.3 All 92 releases
iwp-client / lib / Google / Config.php

Config.php in InfiniteWP Client trunk, at lib/Google/Config.php

316 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Copyright 2010 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /**
19 * A class to contain the library configuration for the Google API client.
20 */
21 class IWP_google_Config
22 {
23 const GZIP_DISABLED = true;
24 const GZIP_ENABLED = false;
25 const GZIP_UPLOADS_ENABLED = true;
26 const GZIP_UPLOADS_DISABLED = false;
27 const USE_AUTO_IO_SELECTION = "auto";
28 private $configuration;
29
30 /**
31 * Create a new IWP_google_Config. Can accept an ini file location with the
32 * local configuration. For example:
33 * application_name: "My App";
34 *
35 * @param [$ini_file_location] - optional - The location of the ini file to load
36 */
37 public function __construct($ini_file_location = null)
38 {
39 $this->configuration = array(
40 // The application_name is included in the User-Agent HTTP header.
41 'application_name' => '',
42
43 // Which Authentication, Storage and HTTP IO classes to use.
44 'auth_class' => 'IWP_google_Auth_OAuth2',
45 'io_class' => self::USE_AUTO_IO_SELECTION,
46 'cache_class' => 'IWP_google_Cache_File',
47
48 // Don't change these unless you're working against a special development
49 // or testing environment.
50 'base_path' => 'https://www.googleapis.com',
51
52 // Definition of class specific values, like file paths and so on.
53 'classes' => array(
54 'IWP_google_IO_Abstract' => array(
55 'request_timeout_seconds' => 100,
56 ),
57 'IWP_google_Http_Request' => array(
58 // Disable the use of gzip on calls if set to true. Defaults to false.
59 'disable_gzip' => self::GZIP_ENABLED,
60
61 // We default gzip to disabled on uploads even if gzip is otherwise
62 // enabled, due to some issues seen with small packet sizes for uploads.
63 // Please test with this option before enabling gzip for uploads in
64 // a production environment.
65 'enable_gzip_for_uploads' => self::GZIP_UPLOADS_DISABLED,
66 ),
67 // If you want to pass in OAuth 2.0 settings, they will need to be
68 // structured like this.
69 'IWP_google_Auth_OAuth2' => array(
70 // Keys for OAuth 2.0 access, see the API console at
71 // https://developers.google.com/console
72 'client_id' => '',
73 'client_secret' => '',
74 'redirect_uri' => '',
75
76 // Simple API access key, also from the API console. Ensure you get
77 // a Server key, and not a Browser key.
78 'developer_key' => '',
79
80 // Other parameters.
81 'access_type' => 'online',
82 'approval_prompt' => 'auto',
83 'request_visible_actions' => '',
84 'federated_signon_certs_url' =>
85 'https://www.googleapis.com/oauth2/v1/certs',
86 ),
87 // Set a default directory for the file cache.
88 'IWP_google_Cache_File' => array(
89 'directory' => sys_get_temp_dir() . '/IWP_google_Client'
90 )
91 ),
92
93 // Definition of service specific values like scopes, oauth token URLs,
94 // etc. Example:
95 'services' => array(
96 ),
97 );
98 if ($ini_file_location) {
99 $ini = parse_ini_file($ini_file_location, true);
100 if (is_array($ini) && count($ini)) {
101 $this->configuration = array_merge($this->configuration, $ini);
102 }
103 }
104 }
105
106 /**
107 * Set configuration specific to a given class.
108 * $config->setClassConfig('IWP_google_Cache_File',
109 * array('directory' => '/tmp/cache'));
110 * @param $class The class name for the configuration
111 * @param $config string key or an array of configuration values
112 * @param $value optional - if $config is a key, the value
113 */
114 public function setClassConfig($class, $config, $value = null)
115 {
116 if (!is_array($config)) {
117 if (!isset($this->configuration['classes'][$class])) {
118 $this->configuration['classes'][$class] = array();
119 }
120 $this->configuration['classes'][$class][$config] = $value;
121 } else {
122 $this->configuration['classes'][$class] = $config;
123 }
124 }
125
126 public function getClassConfig($class, $key = null)
127 {
128 if (!isset($this->configuration['classes'][$class])) {
129 return null;
130 }
131 if ($key === null) {
132 return $this->configuration['classes'][$class];
133 } else {
134 return $this->configuration['classes'][$class][$key];
135 }
136 }
137
138 /**
139 * Return the configured cache class.
140 * @return string
141 */
142 public function getCacheClass()
143 {
144 return $this->configuration['cache_class'];
145 }
146
147 /**
148 * Return the configured Auth class.
149 * @return string
150 */
151 public function getAuthClass()
152 {
153 return $this->configuration['auth_class'];
154 }
155
156 /**
157 * Set the auth class.
158 *
159 * @param $class the class name to set
160 */
161 public function setAuthClass($class)
162 {
163 $prev = $this->configuration['auth_class'];
164 if (!isset($this->configuration['classes'][$class]) &&
165 isset($this->configuration['classes'][$prev])) {
166 $this->configuration['classes'][$class] =
167 $this->configuration['classes'][$prev];
168 }
169 $this->configuration['auth_class'] = $class;
170 }
171
172 /**
173 * Set the IO class.
174 *
175 * @param $class the class name to set
176 */
177 public function setIoClass($class)
178 {
179 $prev = $this->configuration['io_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 }
185 $this->configuration['io_class'] = $class;
186 }
187
188 /**
189 * Set the cache class.
190 *
191 * @param $class the class name to set
192 */
193 public function setCacheClass($class)
194 {
195 $prev = $this->configuration['cache_class'];
196 if (!isset($this->configuration['classes'][$class]) &&
197 isset($this->configuration['classes'][$prev])) {
198 $this->configuration['classes'][$class] =
199 $this->configuration['classes'][$prev];
200 }
201 $this->configuration['cache_class'] = $class;
202 }
203
204 /**
205 * Return the configured IO class.
206 * @return string
207 */
208 public function getIoClass()
209 {
210 return $this->configuration['io_class'];
211 }
212
213 /**
214 * Set the application name, this is included in the User-Agent HTTP header.
215 * @param string $name
216 */
217 public function setApplicationName($name)
218 {
219 $this->configuration['application_name'] = $name;
220 }
221
222 /**
223 * @return string the name of the application
224 */
225 public function getApplicationName()
226 {
227 return $this->configuration['application_name'];
228 }
229
230 /**
231 * Set the client ID for the auth class.
232 * @param $key string - the API console client ID
233 */
234 public function setClientId($clientId)
235 {
236 $this->setAuthConfig('client_id', $clientId);
237 }
238
239 /**
240 * Set the client secret for the auth class.
241 * @param $key string - the API console client secret
242 */
243 public function setClientSecret($secret)
244 {
245 $this->setAuthConfig('client_secret', $secret);
246 }
247
248 /**
249 * Set the redirect uri for the auth class. Note that if using the
250 * Javascript based sign in flow, this should be the string 'postmessage'.
251 * @param $key string - the URI that users should be redirected to
252 */
253 public function setRedirectUri($uri)
254 {
255 $this->setAuthConfig('redirect_uri', $uri);
256 }
257
258 /**
259 * Set the app activities for the auth class.
260 * @param $rva string a space separated list of app activity types
261 */
262 public function setRequestVisibleActions($rva)
263 {
264 $this->setAuthConfig('request_visible_actions', $rva);
265 }
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 {
273 $this->setAuthConfig('access_type', $access);
274 }
275
276 /**
277 * Set when to show the approval prompt (auto or force)
278 * @param $approval string - the approval request
279 */
280 public function setApprovalPrompt($approval)
281 {
282 $this->setAuthConfig('approval_prompt', $approval);
283 }
284
285 /**
286 * Set the developer key for the auth class. Note that this is separate value
287 * from the client ID - if it looks like a URL, its a client ID!
288 * @param $key string - the API console developer key
289 */
290 public function setDeveloperKey($key)
291 {
292 $this->setAuthConfig('developer_key', $key);
293 }
294
295 /**
296 * @return string the base URL to use for API calls
297 */
298 public function getBasePath()
299 {
300 return $this->configuration['base_path'];
301 }
302
303 /**
304 * Set the auth configuration for the current auth class.
305 * @param $key - the key to set
306 * @param $value - the parameter value
307 */
308 private function setAuthConfig($key, $value)
309 {
310 if (!isset($this->configuration['classes'][$this->getAuthClass()])) {
311 $this->configuration['classes'][$this->getAuthClass()] = array();
312 }
313 $this->configuration['classes'][$this->getAuthClass()][$key] = $value;
314 }
315 }
316