@@ -51,8 +51,8 @@ |
||
51 | 51 | * Verifies the signature on data. |
52 | 52 | * |
53 | 53 | * Returns true if the signature is valid, false otherwise. |
54 | - * @param $data |
|
55 | - * @param $signature |
|
54 | + * @param string $data |
|
55 | + * @param string $signature |
|
56 | 56 | * @throws Google_AuthException |
57 | 57 | * @return bool |
58 | 58 | */ |
@@ -32,19 +32,19 @@ discard block |
||
32 | 32 | * @throws Google_Exception |
33 | 33 | */ |
34 | 34 | function __construct($pem) { |
35 | - if (!function_exists('openssl_x509_read')) { |
|
36 | - throw new Google_Exception('Google API PHP client needs the openssl PHP extension'); |
|
37 | - } |
|
38 | - $this->publicKey = openssl_x509_read($pem); |
|
39 | - if (!$this->publicKey) { |
|
40 | - throw new Google_AuthException("Unable to parse PEM: $pem"); |
|
41 | - } |
|
35 | + if (!function_exists('openssl_x509_read')) { |
|
36 | + throw new Google_Exception('Google API PHP client needs the openssl PHP extension'); |
|
37 | + } |
|
38 | + $this->publicKey = openssl_x509_read($pem); |
|
39 | + if (!$this->publicKey) { |
|
40 | + throw new Google_AuthException("Unable to parse PEM: $pem"); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | function __destruct() { |
45 | - if ($this->publicKey) { |
|
46 | - openssl_x509_free($this->publicKey); |
|
47 | - } |
|
45 | + if ($this->publicKey) { |
|
46 | + openssl_x509_free($this->publicKey); |
|
47 | + } |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | * @return bool |
58 | 58 | */ |
59 | 59 | function verify($data, $signature) { |
60 | - $status = openssl_verify($data, $signature, $this->publicKey, "sha256"); |
|
61 | - if ($status === -1) { |
|
62 | - throw new Google_AuthException('Signature verification error: ' . openssl_error_string()); |
|
63 | - } |
|
64 | - return $status === 1; |
|
60 | + $status = openssl_verify($data, $signature, $this->publicKey, "sha256"); |
|
61 | + if ($status === -1) { |
|
62 | + throw new Google_AuthException('Signature verification error: ' . openssl_error_string()); |
|
63 | + } |
|
64 | + return $status === 1; |
|
65 | 65 | } |
66 | 66 | } |
@@ -59,7 +59,7 @@ |
||
59 | 59 | function verify($data, $signature) { |
60 | 60 | $status = openssl_verify($data, $signature, $this->publicKey, "sha256"); |
61 | 61 | if ($status === -1) { |
62 | - throw new Google_AuthException('Signature verification error: ' . openssl_error_string()); |
|
62 | + throw new Google_AuthException('Signature verification error: '.openssl_error_string()); |
|
63 | 63 | } |
64 | 64 | return $status === 1; |
65 | 65 | } |
@@ -37,6 +37,9 @@ discard block |
||
37 | 37 | return file_exists($storageFile . '.lock'); |
38 | 38 | } |
39 | 39 | |
40 | + /** |
|
41 | + * @param string $storageFile |
|
42 | + */ |
|
40 | 43 | private function createLock($storageFile) { |
41 | 44 | $storageDir = dirname($storageFile); |
42 | 45 | if (! is_dir($storageDir)) { |
@@ -57,6 +60,9 @@ discard block |
||
57 | 60 | @unlink($storageFile . '.lock'); |
58 | 61 | } |
59 | 62 | |
63 | + /** |
|
64 | + * @param string $storageFile |
|
65 | + */ |
|
60 | 66 | private function waitForLock($storageFile) { |
61 | 67 | // 20 x 250 = 5 seconds |
62 | 68 | $tries = 20; |
@@ -81,6 +87,9 @@ discard block |
||
81 | 87 | return $this->path . '/' . substr($hash, 0, 2); |
82 | 88 | } |
83 | 89 | |
90 | + /** |
|
91 | + * @param string $hash |
|
92 | + */ |
|
84 | 93 | private function getCacheFile($hash) { |
85 | 94 | return $this->getCacheDir($hash) . '/' . $hash; |
86 | 95 | } |
@@ -28,110 +28,110 @@ |
||
28 | 28 | private $path; |
29 | 29 | |
30 | 30 | public function __construct() { |
31 | - global $apiConfig; |
|
32 | - $this->path = $apiConfig['ioFileCache_directory']; |
|
31 | + global $apiConfig; |
|
32 | + $this->path = $apiConfig['ioFileCache_directory']; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | private function isLocked($storageFile) { |
36 | - // our lock file convention is simple: /the/file/path.lock |
|
37 | - return file_exists($storageFile . '.lock'); |
|
36 | + // our lock file convention is simple: /the/file/path.lock |
|
37 | + return file_exists($storageFile . '.lock'); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | private function createLock($storageFile) { |
41 | - $storageDir = dirname($storageFile); |
|
42 | - if (! is_dir($storageDir)) { |
|
43 | - // @codeCoverageIgnoreStart |
|
44 | - if (! @mkdir($storageDir, 0755, true)) { |
|
45 | - // make sure the failure isn't because of a concurrency issue |
|
46 | - if (! is_dir($storageDir)) { |
|
47 | - throw new Google_CacheException("Could not create storage directory: $storageDir"); |
|
48 | - } |
|
49 | - } |
|
50 | - // @codeCoverageIgnoreEnd |
|
51 | - } |
|
52 | - @touch($storageFile . '.lock'); |
|
41 | + $storageDir = dirname($storageFile); |
|
42 | + if (! is_dir($storageDir)) { |
|
43 | + // @codeCoverageIgnoreStart |
|
44 | + if (! @mkdir($storageDir, 0755, true)) { |
|
45 | + // make sure the failure isn't because of a concurrency issue |
|
46 | + if (! is_dir($storageDir)) { |
|
47 | + throw new Google_CacheException("Could not create storage directory: $storageDir"); |
|
48 | + } |
|
49 | + } |
|
50 | + // @codeCoverageIgnoreEnd |
|
51 | + } |
|
52 | + @touch($storageFile . '.lock'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | private function removeLock($storageFile) { |
56 | - // suppress all warnings, if some other process removed it that's ok too |
|
57 | - @unlink($storageFile . '.lock'); |
|
56 | + // suppress all warnings, if some other process removed it that's ok too |
|
57 | + @unlink($storageFile . '.lock'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | private function waitForLock($storageFile) { |
61 | - // 20 x 250 = 5 seconds |
|
62 | - $tries = 20; |
|
63 | - $cnt = 0; |
|
64 | - do { |
|
65 | - // make sure PHP picks up on file changes. This is an expensive action but really can't be avoided |
|
66 | - clearstatcache(); |
|
67 | - // 250 ms is a long time to sleep, but it does stop the server from burning all resources on polling locks.. |
|
68 | - usleep(250); |
|
69 | - $cnt ++; |
|
70 | - } while ($cnt <= $tries && $this->isLocked($storageFile)); |
|
71 | - if ($this->isLocked($storageFile)) { |
|
72 | - // 5 seconds passed, assume the owning process died off and remove it |
|
73 | - $this->removeLock($storageFile); |
|
74 | - } |
|
61 | + // 20 x 250 = 5 seconds |
|
62 | + $tries = 20; |
|
63 | + $cnt = 0; |
|
64 | + do { |
|
65 | + // make sure PHP picks up on file changes. This is an expensive action but really can't be avoided |
|
66 | + clearstatcache(); |
|
67 | + // 250 ms is a long time to sleep, but it does stop the server from burning all resources on polling locks.. |
|
68 | + usleep(250); |
|
69 | + $cnt ++; |
|
70 | + } while ($cnt <= $tries && $this->isLocked($storageFile)); |
|
71 | + if ($this->isLocked($storageFile)) { |
|
72 | + // 5 seconds passed, assume the owning process died off and remove it |
|
73 | + $this->removeLock($storageFile); |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | private function getCacheDir($hash) { |
78 | - // use the first 2 characters of the hash as a directory prefix |
|
79 | - // this should prevent slowdowns due to huge directory listings |
|
80 | - // and thus give some basic amount of scalability |
|
81 | - return $this->path . '/' . substr($hash, 0, 2); |
|
78 | + // use the first 2 characters of the hash as a directory prefix |
|
79 | + // this should prevent slowdowns due to huge directory listings |
|
80 | + // and thus give some basic amount of scalability |
|
81 | + return $this->path . '/' . substr($hash, 0, 2); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | private function getCacheFile($hash) { |
85 | - return $this->getCacheDir($hash) . '/' . $hash; |
|
85 | + return $this->getCacheDir($hash) . '/' . $hash; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | public function get($key, $expiration = false) { |
89 | - $storageFile = $this->getCacheFile(md5($key)); |
|
90 | - // See if this storage file is locked, if so we wait up to 5 seconds for the lock owning process to |
|
91 | - // complete it's work. If the lock is not released within that time frame, it's cleaned up. |
|
92 | - // This should give us a fair amount of 'Cache Stampeding' protection |
|
93 | - if ($this->isLocked($storageFile)) { |
|
94 | - $this->waitForLock($storageFile); |
|
95 | - } |
|
96 | - if (file_exists($storageFile) && is_readable($storageFile)) { |
|
97 | - $now = time(); |
|
98 | - if (! $expiration || (($mtime = @filemtime($storageFile)) !== false && ($now - $mtime) < $expiration)) { |
|
99 | - if (($data = @file_get_contents($storageFile)) !== false) { |
|
100 | - $data = unserialize($data); |
|
101 | - return $data; |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - return false; |
|
89 | + $storageFile = $this->getCacheFile(md5($key)); |
|
90 | + // See if this storage file is locked, if so we wait up to 5 seconds for the lock owning process to |
|
91 | + // complete it's work. If the lock is not released within that time frame, it's cleaned up. |
|
92 | + // This should give us a fair amount of 'Cache Stampeding' protection |
|
93 | + if ($this->isLocked($storageFile)) { |
|
94 | + $this->waitForLock($storageFile); |
|
95 | + } |
|
96 | + if (file_exists($storageFile) && is_readable($storageFile)) { |
|
97 | + $now = time(); |
|
98 | + if (! $expiration || (($mtime = @filemtime($storageFile)) !== false && ($now - $mtime) < $expiration)) { |
|
99 | + if (($data = @file_get_contents($storageFile)) !== false) { |
|
100 | + $data = unserialize($data); |
|
101 | + return $data; |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + return false; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | public function set($key, $value) { |
109 | - $storageDir = $this->getCacheDir(md5($key)); |
|
110 | - $storageFile = $this->getCacheFile(md5($key)); |
|
111 | - if ($this->isLocked($storageFile)) { |
|
112 | - // some other process is writing to this file too, wait until it's done to prevent hiccups |
|
113 | - $this->waitForLock($storageFile); |
|
114 | - } |
|
115 | - if (! is_dir($storageDir)) { |
|
116 | - if (! @mkdir($storageDir, 0755, true)) { |
|
117 | - throw new Google_CacheException("Could not create storage directory: $storageDir"); |
|
118 | - } |
|
119 | - } |
|
120 | - // we serialize the whole request object, since we don't only want the |
|
121 | - // responseContent but also the postBody used, headers, size, etc |
|
122 | - $data = serialize($value); |
|
123 | - $this->createLock($storageFile); |
|
124 | - if (! @file_put_contents($storageFile, $data)) { |
|
125 | - $this->removeLock($storageFile); |
|
126 | - throw new Google_CacheException("Could not store data in the file"); |
|
127 | - } |
|
128 | - $this->removeLock($storageFile); |
|
109 | + $storageDir = $this->getCacheDir(md5($key)); |
|
110 | + $storageFile = $this->getCacheFile(md5($key)); |
|
111 | + if ($this->isLocked($storageFile)) { |
|
112 | + // some other process is writing to this file too, wait until it's done to prevent hiccups |
|
113 | + $this->waitForLock($storageFile); |
|
114 | + } |
|
115 | + if (! is_dir($storageDir)) { |
|
116 | + if (! @mkdir($storageDir, 0755, true)) { |
|
117 | + throw new Google_CacheException("Could not create storage directory: $storageDir"); |
|
118 | + } |
|
119 | + } |
|
120 | + // we serialize the whole request object, since we don't only want the |
|
121 | + // responseContent but also the postBody used, headers, size, etc |
|
122 | + $data = serialize($value); |
|
123 | + $this->createLock($storageFile); |
|
124 | + if (! @file_put_contents($storageFile, $data)) { |
|
125 | + $this->removeLock($storageFile); |
|
126 | + throw new Google_CacheException("Could not store data in the file"); |
|
127 | + } |
|
128 | + $this->removeLock($storageFile); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | public function delete($key) { |
132 | - $file = $this->getCacheFile(md5($key)); |
|
133 | - if (! @unlink($file)) { |
|
134 | - throw new Google_CacheException("Cache file could not be deleted"); |
|
135 | - } |
|
132 | + $file = $this->getCacheFile(md5($key)); |
|
133 | + if (! @unlink($file)) { |
|
134 | + throw new Google_CacheException("Cache file could not be deleted"); |
|
135 | + } |
|
136 | 136 | } |
137 | 137 | } |
@@ -34,27 +34,27 @@ discard block |
||
34 | 34 | |
35 | 35 | private function isLocked($storageFile) { |
36 | 36 | // our lock file convention is simple: /the/file/path.lock |
37 | - return file_exists($storageFile . '.lock'); |
|
37 | + return file_exists($storageFile.'.lock'); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | private function createLock($storageFile) { |
41 | 41 | $storageDir = dirname($storageFile); |
42 | - if (! is_dir($storageDir)) { |
|
42 | + if (!is_dir($storageDir)) { |
|
43 | 43 | // @codeCoverageIgnoreStart |
44 | - if (! @mkdir($storageDir, 0755, true)) { |
|
44 | + if (!@mkdir($storageDir, 0755, true)) { |
|
45 | 45 | // make sure the failure isn't because of a concurrency issue |
46 | - if (! is_dir($storageDir)) { |
|
46 | + if (!is_dir($storageDir)) { |
|
47 | 47 | throw new Google_CacheException("Could not create storage directory: $storageDir"); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | // @codeCoverageIgnoreEnd |
51 | 51 | } |
52 | - @touch($storageFile . '.lock'); |
|
52 | + @touch($storageFile.'.lock'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | private function removeLock($storageFile) { |
56 | 56 | // suppress all warnings, if some other process removed it that's ok too |
57 | - @unlink($storageFile . '.lock'); |
|
57 | + @unlink($storageFile.'.lock'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | private function waitForLock($storageFile) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | clearstatcache(); |
67 | 67 | // 250 ms is a long time to sleep, but it does stop the server from burning all resources on polling locks.. |
68 | 68 | usleep(250); |
69 | - $cnt ++; |
|
69 | + $cnt++; |
|
70 | 70 | } while ($cnt <= $tries && $this->isLocked($storageFile)); |
71 | 71 | if ($this->isLocked($storageFile)) { |
72 | 72 | // 5 seconds passed, assume the owning process died off and remove it |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | // use the first 2 characters of the hash as a directory prefix |
79 | 79 | // this should prevent slowdowns due to huge directory listings |
80 | 80 | // and thus give some basic amount of scalability |
81 | - return $this->path . '/' . substr($hash, 0, 2); |
|
81 | + return $this->path.'/'.substr($hash, 0, 2); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | private function getCacheFile($hash) { |
85 | - return $this->getCacheDir($hash) . '/' . $hash; |
|
85 | + return $this->getCacheDir($hash).'/'.$hash; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | public function get($key, $expiration = false) { |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | } |
96 | 96 | if (file_exists($storageFile) && is_readable($storageFile)) { |
97 | 97 | $now = time(); |
98 | - if (! $expiration || (($mtime = @filemtime($storageFile)) !== false && ($now - $mtime) < $expiration)) { |
|
98 | + if (!$expiration || (($mtime = @filemtime($storageFile)) !== false && ($now - $mtime) < $expiration)) { |
|
99 | 99 | if (($data = @file_get_contents($storageFile)) !== false) { |
100 | 100 | $data = unserialize($data); |
101 | 101 | return $data; |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | // some other process is writing to this file too, wait until it's done to prevent hiccups |
113 | 113 | $this->waitForLock($storageFile); |
114 | 114 | } |
115 | - if (! is_dir($storageDir)) { |
|
116 | - if (! @mkdir($storageDir, 0755, true)) { |
|
115 | + if (!is_dir($storageDir)) { |
|
116 | + if (!@mkdir($storageDir, 0755, true)) { |
|
117 | 117 | throw new Google_CacheException("Could not create storage directory: $storageDir"); |
118 | 118 | } |
119 | 119 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | // responseContent but also the postBody used, headers, size, etc |
122 | 122 | $data = serialize($value); |
123 | 123 | $this->createLock($storageFile); |
124 | - if (! @file_put_contents($storageFile, $data)) { |
|
124 | + if (!@file_put_contents($storageFile, $data)) { |
|
125 | 125 | $this->removeLock($storageFile); |
126 | 126 | throw new Google_CacheException("Could not store data in the file"); |
127 | 127 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | public function delete($key) { |
132 | 132 | $file = $this->getCacheFile(md5($key)); |
133 | - if (! @unlink($file)) { |
|
133 | + if (!@unlink($file)) { |
|
134 | 134 | throw new Google_CacheException("Cache file could not be deleted"); |
135 | 135 | } |
136 | 136 | } |
@@ -43,6 +43,9 @@ discard block |
||
43 | 43 | public static $reserved; |
44 | 44 | public static $reserved_pct; |
45 | 45 | |
46 | + /** |
|
47 | + * @param string $template |
|
48 | + */ |
|
46 | 49 | public function __construct($template) { |
47 | 50 | self::$reserved = array_merge(self::$gen_delims, self::$sub_delims); |
48 | 51 | self::$reserved_pct = array_merge(self::$gen_delims_pct, self::$sub_delims_pct); |
@@ -150,6 +153,9 @@ discard block |
||
150 | 153 | return $this->expansion; |
151 | 154 | } |
152 | 155 | |
156 | + /** |
|
157 | + * @param stdClass $exp |
|
158 | + */ |
|
153 | 159 | private function val_from_var($var, $exp) { |
154 | 160 | $val = ''; |
155 | 161 | if (is_array($var->data)) { |
@@ -31,30 +31,30 @@ discard block |
||
31 | 31 | if( ! class_exists( 'URI_Template_Parser' ) ) { |
32 | 32 | class URI_Template_Parser { |
33 | 33 | |
34 | - public static $operators = array('+', ';', '?', '/', '.'); |
|
35 | - public static $reserved_operators = array('|', '!', '@'); |
|
36 | - public static $explode_modifiers = array('+', '*'); |
|
37 | - public static $partial_modifiers = array(':', '^'); |
|
38 | - |
|
39 | - public static $gen_delims = array(':', '/', '?', '#', '[', ']', '@'); |
|
40 | - public static $gen_delims_pct = array('%3A', '%2F', '%3F', '%23', '%5B', '%5D', '%40'); |
|
41 | - public static $sub_delims = array('!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '='); |
|
42 | - public static $sub_delims_pct = array('%21', '%24', '%26', '%27', '%28', '%29', '%2A', '%2B', '%2C', '%3B', '%3D'); |
|
43 | - public static $reserved; |
|
44 | - public static $reserved_pct; |
|
45 | - |
|
46 | - public function __construct($template) { |
|
47 | - self::$reserved = array_merge(self::$gen_delims, self::$sub_delims); |
|
48 | - self::$reserved_pct = array_merge(self::$gen_delims_pct, self::$sub_delims_pct); |
|
49 | - $this->template = $template; |
|
50 | - } |
|
51 | - |
|
52 | - public function expand($data) { |
|
53 | - // Modification to make this a bit more performant (since gettype is very slow) |
|
54 | - if (! is_array($data)) { |
|
55 | - $data = (array)$data; |
|
56 | - } |
|
57 | - /* |
|
34 | + public static $operators = array('+', ';', '?', '/', '.'); |
|
35 | + public static $reserved_operators = array('|', '!', '@'); |
|
36 | + public static $explode_modifiers = array('+', '*'); |
|
37 | + public static $partial_modifiers = array(':', '^'); |
|
38 | + |
|
39 | + public static $gen_delims = array(':', '/', '?', '#', '[', ']', '@'); |
|
40 | + public static $gen_delims_pct = array('%3A', '%2F', '%3F', '%23', '%5B', '%5D', '%40'); |
|
41 | + public static $sub_delims = array('!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '='); |
|
42 | + public static $sub_delims_pct = array('%21', '%24', '%26', '%27', '%28', '%29', '%2A', '%2B', '%2C', '%3B', '%3D'); |
|
43 | + public static $reserved; |
|
44 | + public static $reserved_pct; |
|
45 | + |
|
46 | + public function __construct($template) { |
|
47 | + self::$reserved = array_merge(self::$gen_delims, self::$sub_delims); |
|
48 | + self::$reserved_pct = array_merge(self::$gen_delims_pct, self::$sub_delims_pct); |
|
49 | + $this->template = $template; |
|
50 | + } |
|
51 | + |
|
52 | + public function expand($data) { |
|
53 | + // Modification to make this a bit more performant (since gettype is very slow) |
|
54 | + if (! is_array($data)) { |
|
55 | + $data = (array)$data; |
|
56 | + } |
|
57 | + /* |
|
58 | 58 | // Original code, which uses a slow gettype() statement, kept in place for if the assumption that is_array always works here is incorrect |
59 | 59 | switch (gettype($data)) { |
60 | 60 | case "boolean": |
@@ -67,146 +67,146 @@ discard block |
||
67 | 67 | } |
68 | 68 | */ |
69 | 69 | |
70 | - // Resolve template vars |
|
71 | - preg_match_all('/\{([^\}]*)\}/', $this->template, $em); |
|
72 | - |
|
73 | - foreach ($em[1] as $i => $bare_expression) { |
|
74 | - preg_match('/^([\+\;\?\/\.]{1})?(.*)$/', $bare_expression, $lm); |
|
75 | - $exp = new StdClass(); |
|
76 | - $exp->expression = $em[0][$i]; |
|
77 | - $exp->operator = $lm[1]; |
|
78 | - $exp->variable_list = $lm[2]; |
|
79 | - $exp->varspecs = explode(',', $exp->variable_list); |
|
80 | - $exp->vars = array(); |
|
81 | - foreach ($exp->varspecs as $varspec) { |
|
82 | - preg_match('/^([a-zA-Z0-9_]+)([\*\+]{1})?([\:\^][0-9-]+)?(\=[^,]+)?$/', $varspec, $vm); |
|
83 | - $var = new StdClass(); |
|
84 | - $var->name = $vm[1]; |
|
85 | - $var->modifier = isset($vm[2]) && $vm[2] ? $vm[2] : null; |
|
86 | - $var->modifier = isset($vm[3]) && $vm[3] ? $vm[3] : $var->modifier; |
|
87 | - $var->default = isset($vm[4]) ? substr($vm[4], 1) : null; |
|
88 | - $exp->vars[] = $var; |
|
89 | - } |
|
90 | - |
|
91 | - // Add processing flags |
|
92 | - $exp->reserved = false; |
|
93 | - $exp->prefix = ''; |
|
94 | - $exp->delimiter = ','; |
|
95 | - switch ($exp->operator) { |
|
96 | - case '+': |
|
97 | - $exp->reserved = 'true'; |
|
98 | - break; |
|
99 | - case ';': |
|
100 | - $exp->prefix = ';'; |
|
101 | - $exp->delimiter = ';'; |
|
102 | - break; |
|
103 | - case '?': |
|
104 | - $exp->prefix = '?'; |
|
105 | - $exp->delimiter = '&'; |
|
106 | - break; |
|
107 | - case '/': |
|
108 | - $exp->prefix = '/'; |
|
109 | - $exp->delimiter = '/'; |
|
110 | - break; |
|
111 | - case '.': |
|
112 | - $exp->prefix = '.'; |
|
113 | - $exp->delimiter = '.'; |
|
114 | - break; |
|
115 | - } |
|
116 | - $expressions[] = $exp; |
|
117 | - } |
|
118 | - |
|
119 | - // Expansion |
|
120 | - $this->expansion = $this->template; |
|
121 | - |
|
122 | - foreach ($expressions as $exp) { |
|
123 | - $part = $exp->prefix; |
|
124 | - $exp->one_var_defined = false; |
|
125 | - foreach ($exp->vars as $var) { |
|
126 | - $val = ''; |
|
127 | - if ($exp->one_var_defined && isset($data[$var->name])) { |
|
128 | - $part .= $exp->delimiter; |
|
129 | - } |
|
130 | - // Variable present |
|
131 | - if (isset($data[$var->name])) { |
|
132 | - $exp->one_var_defined = true; |
|
133 | - $var->data = $data[$var->name]; |
|
134 | - |
|
135 | - $val = self::val_from_var($var, $exp); |
|
136 | - |
|
137 | - // Variable missing |
|
138 | - } else { |
|
139 | - if ($var->default) { |
|
140 | - $exp->one_var_defined = true; |
|
141 | - $val = $var->default; |
|
142 | - } |
|
143 | - } |
|
144 | - $part .= $val; |
|
145 | - } |
|
146 | - if (! $exp->one_var_defined) $part = ''; |
|
147 | - $this->expansion = str_replace($exp->expression, $part, $this->expansion); |
|
148 | - } |
|
149 | - |
|
150 | - return $this->expansion; |
|
151 | - } |
|
152 | - |
|
153 | - private function val_from_var($var, $exp) { |
|
154 | - $val = ''; |
|
155 | - if (is_array($var->data)) { |
|
156 | - $i = 0; |
|
157 | - if ($exp->operator == '?' && ! $var->modifier) { |
|
158 | - $val .= $var->name . '='; |
|
159 | - } |
|
160 | - foreach ($var->data as $k => $v) { |
|
161 | - $del = $var->modifier ? $exp->delimiter : ','; |
|
162 | - $ek = rawurlencode($k); |
|
163 | - $ev = rawurlencode($v); |
|
164 | - |
|
165 | - // Array |
|
166 | - if ($k !== $i) { |
|
167 | - if ($var->modifier == '+') { |
|
168 | - $val .= $var->name . '.'; |
|
169 | - } |
|
170 | - if ($exp->operator == '?' && $var->modifier || $exp->operator == ';' && $var->modifier == '*' || $exp->operator == ';' && $var->modifier == '+') { |
|
171 | - $val .= $ek . '='; |
|
172 | - } else { |
|
173 | - $val .= $ek . $del; |
|
174 | - } |
|
175 | - |
|
176 | - // List |
|
177 | - } else { |
|
178 | - if ($var->modifier == '+') { |
|
179 | - if ($exp->operator == ';' && $var->modifier == '*' || $exp->operator == ';' && $var->modifier == '+' || $exp->operator == '?' && $var->modifier == '+') { |
|
180 | - $val .= $var->name . '='; |
|
181 | - } else { |
|
182 | - $val .= $var->name . '.'; |
|
183 | - } |
|
184 | - } |
|
185 | - } |
|
186 | - $val .= $ev . $del; |
|
187 | - $i ++; |
|
188 | - } |
|
189 | - $val = trim($val, $del); |
|
190 | - |
|
191 | - // Strings, numbers, etc. |
|
192 | - } else { |
|
193 | - if ($exp->operator == '?') { |
|
194 | - $val = $var->name . (isset($var->data) ? '=' : ''); |
|
195 | - } else if ($exp->operator == ';') { |
|
196 | - $val = $var->name . ($var->data ? '=' : ''); |
|
197 | - } |
|
198 | - $val .= rawurlencode($var->data); |
|
199 | - if ($exp->operator == '+') { |
|
200 | - $val = str_replace(self::$reserved_pct, self::$reserved, $val); |
|
201 | - } |
|
202 | - } |
|
203 | - return $val; |
|
204 | - } |
|
205 | - |
|
206 | - public function match($uri) {} |
|
207 | - |
|
208 | - public function __toString() { |
|
209 | - return $this->template; |
|
210 | - } |
|
70 | + // Resolve template vars |
|
71 | + preg_match_all('/\{([^\}]*)\}/', $this->template, $em); |
|
72 | + |
|
73 | + foreach ($em[1] as $i => $bare_expression) { |
|
74 | + preg_match('/^([\+\;\?\/\.]{1})?(.*)$/', $bare_expression, $lm); |
|
75 | + $exp = new StdClass(); |
|
76 | + $exp->expression = $em[0][$i]; |
|
77 | + $exp->operator = $lm[1]; |
|
78 | + $exp->variable_list = $lm[2]; |
|
79 | + $exp->varspecs = explode(',', $exp->variable_list); |
|
80 | + $exp->vars = array(); |
|
81 | + foreach ($exp->varspecs as $varspec) { |
|
82 | + preg_match('/^([a-zA-Z0-9_]+)([\*\+]{1})?([\:\^][0-9-]+)?(\=[^,]+)?$/', $varspec, $vm); |
|
83 | + $var = new StdClass(); |
|
84 | + $var->name = $vm[1]; |
|
85 | + $var->modifier = isset($vm[2]) && $vm[2] ? $vm[2] : null; |
|
86 | + $var->modifier = isset($vm[3]) && $vm[3] ? $vm[3] : $var->modifier; |
|
87 | + $var->default = isset($vm[4]) ? substr($vm[4], 1) : null; |
|
88 | + $exp->vars[] = $var; |
|
89 | + } |
|
90 | + |
|
91 | + // Add processing flags |
|
92 | + $exp->reserved = false; |
|
93 | + $exp->prefix = ''; |
|
94 | + $exp->delimiter = ','; |
|
95 | + switch ($exp->operator) { |
|
96 | + case '+': |
|
97 | + $exp->reserved = 'true'; |
|
98 | + break; |
|
99 | + case ';': |
|
100 | + $exp->prefix = ';'; |
|
101 | + $exp->delimiter = ';'; |
|
102 | + break; |
|
103 | + case '?': |
|
104 | + $exp->prefix = '?'; |
|
105 | + $exp->delimiter = '&'; |
|
106 | + break; |
|
107 | + case '/': |
|
108 | + $exp->prefix = '/'; |
|
109 | + $exp->delimiter = '/'; |
|
110 | + break; |
|
111 | + case '.': |
|
112 | + $exp->prefix = '.'; |
|
113 | + $exp->delimiter = '.'; |
|
114 | + break; |
|
115 | + } |
|
116 | + $expressions[] = $exp; |
|
117 | + } |
|
118 | + |
|
119 | + // Expansion |
|
120 | + $this->expansion = $this->template; |
|
121 | + |
|
122 | + foreach ($expressions as $exp) { |
|
123 | + $part = $exp->prefix; |
|
124 | + $exp->one_var_defined = false; |
|
125 | + foreach ($exp->vars as $var) { |
|
126 | + $val = ''; |
|
127 | + if ($exp->one_var_defined && isset($data[$var->name])) { |
|
128 | + $part .= $exp->delimiter; |
|
129 | + } |
|
130 | + // Variable present |
|
131 | + if (isset($data[$var->name])) { |
|
132 | + $exp->one_var_defined = true; |
|
133 | + $var->data = $data[$var->name]; |
|
134 | + |
|
135 | + $val = self::val_from_var($var, $exp); |
|
136 | + |
|
137 | + // Variable missing |
|
138 | + } else { |
|
139 | + if ($var->default) { |
|
140 | + $exp->one_var_defined = true; |
|
141 | + $val = $var->default; |
|
142 | + } |
|
143 | + } |
|
144 | + $part .= $val; |
|
145 | + } |
|
146 | + if (! $exp->one_var_defined) $part = ''; |
|
147 | + $this->expansion = str_replace($exp->expression, $part, $this->expansion); |
|
148 | + } |
|
149 | + |
|
150 | + return $this->expansion; |
|
151 | + } |
|
152 | + |
|
153 | + private function val_from_var($var, $exp) { |
|
154 | + $val = ''; |
|
155 | + if (is_array($var->data)) { |
|
156 | + $i = 0; |
|
157 | + if ($exp->operator == '?' && ! $var->modifier) { |
|
158 | + $val .= $var->name . '='; |
|
159 | + } |
|
160 | + foreach ($var->data as $k => $v) { |
|
161 | + $del = $var->modifier ? $exp->delimiter : ','; |
|
162 | + $ek = rawurlencode($k); |
|
163 | + $ev = rawurlencode($v); |
|
164 | + |
|
165 | + // Array |
|
166 | + if ($k !== $i) { |
|
167 | + if ($var->modifier == '+') { |
|
168 | + $val .= $var->name . '.'; |
|
169 | + } |
|
170 | + if ($exp->operator == '?' && $var->modifier || $exp->operator == ';' && $var->modifier == '*' || $exp->operator == ';' && $var->modifier == '+') { |
|
171 | + $val .= $ek . '='; |
|
172 | + } else { |
|
173 | + $val .= $ek . $del; |
|
174 | + } |
|
175 | + |
|
176 | + // List |
|
177 | + } else { |
|
178 | + if ($var->modifier == '+') { |
|
179 | + if ($exp->operator == ';' && $var->modifier == '*' || $exp->operator == ';' && $var->modifier == '+' || $exp->operator == '?' && $var->modifier == '+') { |
|
180 | + $val .= $var->name . '='; |
|
181 | + } else { |
|
182 | + $val .= $var->name . '.'; |
|
183 | + } |
|
184 | + } |
|
185 | + } |
|
186 | + $val .= $ev . $del; |
|
187 | + $i ++; |
|
188 | + } |
|
189 | + $val = trim($val, $del); |
|
190 | + |
|
191 | + // Strings, numbers, etc. |
|
192 | + } else { |
|
193 | + if ($exp->operator == '?') { |
|
194 | + $val = $var->name . (isset($var->data) ? '=' : ''); |
|
195 | + } else if ($exp->operator == ';') { |
|
196 | + $val = $var->name . ($var->data ? '=' : ''); |
|
197 | + } |
|
198 | + $val .= rawurlencode($var->data); |
|
199 | + if ($exp->operator == '+') { |
|
200 | + $val = str_replace(self::$reserved_pct, self::$reserved, $val); |
|
201 | + } |
|
202 | + } |
|
203 | + return $val; |
|
204 | + } |
|
205 | + |
|
206 | + public function match($uri) {} |
|
207 | + |
|
208 | + public function __toString() { |
|
209 | + return $this->template; |
|
210 | + } |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | \ No newline at end of file |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * Source: http://github.com/KevBurnsJr/php-uri-template-parser |
29 | 29 | */ |
30 | 30 | |
31 | -if( ! class_exists( 'URI_Template_Parser' ) ) { |
|
31 | +if (!class_exists('URI_Template_Parser')) { |
|
32 | 32 | class URI_Template_Parser { |
33 | 33 | |
34 | 34 | public static $operators = array('+', ';', '?', '/', '.'); |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | |
52 | 52 | public function expand($data) { |
53 | 53 | // Modification to make this a bit more performant (since gettype is very slow) |
54 | - if (! is_array($data)) { |
|
55 | - $data = (array)$data; |
|
54 | + if (!is_array($data)) { |
|
55 | + $data = (array) $data; |
|
56 | 56 | } |
57 | 57 | /* |
58 | 58 | // Original code, which uses a slow gettype() statement, kept in place for if the assumption that is_array always works here is incorrect |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | } |
144 | 144 | $part .= $val; |
145 | 145 | } |
146 | - if (! $exp->one_var_defined) $part = ''; |
|
146 | + if (!$exp->one_var_defined) $part = ''; |
|
147 | 147 | $this->expansion = str_replace($exp->expression, $part, $this->expansion); |
148 | 148 | } |
149 | 149 | |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | $val = ''; |
155 | 155 | if (is_array($var->data)) { |
156 | 156 | $i = 0; |
157 | - if ($exp->operator == '?' && ! $var->modifier) { |
|
158 | - $val .= $var->name . '='; |
|
157 | + if ($exp->operator == '?' && !$var->modifier) { |
|
158 | + $val .= $var->name.'='; |
|
159 | 159 | } |
160 | 160 | foreach ($var->data as $k => $v) { |
161 | 161 | $del = $var->modifier ? $exp->delimiter : ','; |
@@ -165,35 +165,35 @@ discard block |
||
165 | 165 | // Array |
166 | 166 | if ($k !== $i) { |
167 | 167 | if ($var->modifier == '+') { |
168 | - $val .= $var->name . '.'; |
|
168 | + $val .= $var->name.'.'; |
|
169 | 169 | } |
170 | 170 | if ($exp->operator == '?' && $var->modifier || $exp->operator == ';' && $var->modifier == '*' || $exp->operator == ';' && $var->modifier == '+') { |
171 | - $val .= $ek . '='; |
|
171 | + $val .= $ek.'='; |
|
172 | 172 | } else { |
173 | - $val .= $ek . $del; |
|
173 | + $val .= $ek.$del; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | // List |
177 | 177 | } else { |
178 | 178 | if ($var->modifier == '+') { |
179 | 179 | if ($exp->operator == ';' && $var->modifier == '*' || $exp->operator == ';' && $var->modifier == '+' || $exp->operator == '?' && $var->modifier == '+') { |
180 | - $val .= $var->name . '='; |
|
180 | + $val .= $var->name.'='; |
|
181 | 181 | } else { |
182 | - $val .= $var->name . '.'; |
|
182 | + $val .= $var->name.'.'; |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | } |
186 | - $val .= $ev . $del; |
|
187 | - $i ++; |
|
186 | + $val .= $ev.$del; |
|
187 | + $i++; |
|
188 | 188 | } |
189 | 189 | $val = trim($val, $del); |
190 | 190 | |
191 | 191 | // Strings, numbers, etc. |
192 | 192 | } else { |
193 | 193 | if ($exp->operator == '?') { |
194 | - $val = $var->name . (isset($var->data) ? '=' : ''); |
|
194 | + $val = $var->name.(isset($var->data) ? '=' : ''); |
|
195 | 195 | } else if ($exp->operator == ';') { |
196 | - $val = $var->name . ($var->data ? '=' : ''); |
|
196 | + $val = $var->name.($var->data ? '=' : ''); |
|
197 | 197 | } |
198 | 198 | $val .= rawurlencode($var->data); |
199 | 199 | if ($exp->operator == '+') { |
@@ -143,7 +143,9 @@ |
||
143 | 143 | } |
144 | 144 | $part .= $val; |
145 | 145 | } |
146 | - if (! $exp->one_var_defined) $part = ''; |
|
146 | + if (! $exp->one_var_defined) { |
|
147 | + $part = ''; |
|
148 | + } |
|
147 | 149 | $this->expansion = str_replace($exp->expression, $part, $this->expansion); |
148 | 150 | } |
149 | 151 |
@@ -108,6 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Add a service |
111 | + * @param string $service |
|
111 | 112 | */ |
112 | 113 | public function addService($service, $version = false) { |
113 | 114 | global $apiConfig; |
@@ -316,7 +317,7 @@ discard block |
||
316 | 317 | * token, if a token isn't provided. |
317 | 318 | * @throws Google_AuthException |
318 | 319 | * @param string|null $token The token (access token or a refresh token) that should be revoked. |
319 | - * @return boolean Returns True if the revocation was successful, otherwise False. |
|
320 | + * @return boolean|null Returns True if the revocation was successful, otherwise False. |
|
320 | 321 | */ |
321 | 322 | public function revokeToken($token = null) { |
322 | 323 | self::$auth->revokeToken($token); |
@@ -347,6 +348,7 @@ discard block |
||
347 | 348 | * so that you can ask for more or less permission in the auth flow |
348 | 349 | * Set this before you call authenticate() though! |
349 | 350 | * @param array $scopes, ie: array('https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/moderator') |
351 | + * @param string[] $scopes |
|
350 | 352 | */ |
351 | 353 | public function setScopes($scopes) { |
352 | 354 | $this->scopes = is_string($scopes) ? explode(" ", $scopes) : $scopes; |
@@ -99,32 +99,32 @@ discard block |
||
99 | 99 | private $authenticated = false; |
100 | 100 | |
101 | 101 | public function __construct($config = array()) { |
102 | - global $apiConfig; |
|
103 | - $apiConfig = array_merge($apiConfig, $config); |
|
104 | - self::$cache = new $apiConfig['cacheClass'](); |
|
105 | - self::$auth = new $apiConfig['authClass'](); |
|
106 | - self::$io = new $apiConfig['ioClass'](); |
|
102 | + global $apiConfig; |
|
103 | + $apiConfig = array_merge($apiConfig, $config); |
|
104 | + self::$cache = new $apiConfig['cacheClass'](); |
|
105 | + self::$auth = new $apiConfig['authClass'](); |
|
106 | + self::$io = new $apiConfig['ioClass'](); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Add a service |
111 | 111 | */ |
112 | 112 | public function addService($service, $version = false) { |
113 | - global $apiConfig; |
|
114 | - if ($this->authenticated) { |
|
115 | - throw new Google_Exception('Cant add services after having authenticated'); |
|
116 | - } |
|
117 | - $this->services[$service] = array(); |
|
118 | - if (isset($apiConfig['services'][$service])) { |
|
119 | - // Merge the service descriptor with the default values |
|
120 | - $this->services[$service] = array_merge($this->services[$service], $apiConfig['services'][$service]); |
|
121 | - } |
|
113 | + global $apiConfig; |
|
114 | + if ($this->authenticated) { |
|
115 | + throw new Google_Exception('Cant add services after having authenticated'); |
|
116 | + } |
|
117 | + $this->services[$service] = array(); |
|
118 | + if (isset($apiConfig['services'][$service])) { |
|
119 | + // Merge the service descriptor with the default values |
|
120 | + $this->services[$service] = array_merge($this->services[$service], $apiConfig['services'][$service]); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | public function authenticate($code = null) { |
125 | - $service = $this->prepareService(); |
|
126 | - $this->authenticated = true; |
|
127 | - return self::$auth->authenticate($service, $code); |
|
125 | + $service = $this->prepareService(); |
|
126 | + $this->authenticated = true; |
|
127 | + return self::$auth->authenticate($service, $code); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -132,28 +132,28 @@ discard block |
||
132 | 132 | * @visible For Testing |
133 | 133 | */ |
134 | 134 | public function prepareService() { |
135 | - $service = array(); |
|
136 | - $scopes = array(); |
|
137 | - if ($this->scopes) { |
|
138 | - $scopes = $this->scopes; |
|
139 | - } else { |
|
140 | - foreach ($this->services as $key => $val) { |
|
141 | - if (isset($val['scope'])) { |
|
142 | - if (is_array($val['scope'])) { |
|
143 | - $scopes = array_merge($val['scope'], $scopes); |
|
144 | - } else { |
|
145 | - $scopes[] = $val['scope']; |
|
146 | - } |
|
147 | - } else { |
|
148 | - $scopes[] = 'https://www.googleapis.com/auth/' . $key; |
|
149 | - } |
|
150 | - unset($val['discoveryURI']); |
|
151 | - unset($val['scope']); |
|
152 | - $service = array_merge($service, $val); |
|
153 | - } |
|
154 | - } |
|
155 | - $service['scope'] = implode(' ', $scopes); |
|
156 | - return $service; |
|
135 | + $service = array(); |
|
136 | + $scopes = array(); |
|
137 | + if ($this->scopes) { |
|
138 | + $scopes = $this->scopes; |
|
139 | + } else { |
|
140 | + foreach ($this->services as $key => $val) { |
|
141 | + if (isset($val['scope'])) { |
|
142 | + if (is_array($val['scope'])) { |
|
143 | + $scopes = array_merge($val['scope'], $scopes); |
|
144 | + } else { |
|
145 | + $scopes[] = $val['scope']; |
|
146 | + } |
|
147 | + } else { |
|
148 | + $scopes[] = 'https://www.googleapis.com/auth/' . $key; |
|
149 | + } |
|
150 | + unset($val['discoveryURI']); |
|
151 | + unset($val['scope']); |
|
152 | + $service = array_merge($service, $val); |
|
153 | + } |
|
154 | + } |
|
155 | + $service['scope'] = implode(' ', $scopes); |
|
156 | + return $service; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | * "expires_in":3600, "id_token":"TOKEN", "created":1320790426} |
165 | 165 | */ |
166 | 166 | public function setAccessToken($accessToken) { |
167 | - if ($accessToken == null || 'null' == $accessToken) { |
|
168 | - $accessToken = null; |
|
169 | - } |
|
170 | - self::$auth->setAccessToken($accessToken); |
|
167 | + if ($accessToken == null || 'null' == $accessToken) { |
|
168 | + $accessToken = null; |
|
169 | + } |
|
170 | + self::$auth->setAccessToken($accessToken); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @param string $authClassName |
176 | 176 | */ |
177 | 177 | public function setAuthClass($authClassName) { |
178 | - self::$auth = new $authClassName(); |
|
178 | + self::$auth = new $authClassName(); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | * @return string |
184 | 184 | */ |
185 | 185 | public function createAuthUrl() { |
186 | - $service = $this->prepareService(); |
|
187 | - return self::$auth->createAuthUrl($service['scope']); |
|
186 | + $service = $this->prepareService(); |
|
187 | + return self::$auth->createAuthUrl($service['scope']); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | * "expires_in":3600,"id_token":"TOKEN", "created":1320790426} |
195 | 195 | */ |
196 | 196 | public function getAccessToken() { |
197 | - $token = self::$auth->getAccessToken(); |
|
198 | - return (null == $token || 'null' == $token) ? null : $token; |
|
197 | + $token = self::$auth->getAccessToken(); |
|
198 | + return (null == $token || 'null' == $token) ? null : $token; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return bool Returns True if the access_token is expired. |
204 | 204 | */ |
205 | 205 | public function isAccessTokenExpired() { |
206 | - return self::$auth->isAccessTokenExpired(); |
|
206 | + return self::$auth->isAccessTokenExpired(); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @param string $developerKey |
213 | 213 | */ |
214 | 214 | public function setDeveloperKey($developerKey) { |
215 | - self::$auth->setDeveloperKey($developerKey); |
|
215 | + self::$auth->setDeveloperKey($developerKey); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @param string $state |
222 | 222 | */ |
223 | 223 | public function setState($state) { |
224 | - self::$auth->setState($state); |
|
224 | + self::$auth->setState($state); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * {@code "online"} to request online access from the user. |
231 | 231 | */ |
232 | 232 | public function setAccessType($accessType) { |
233 | - self::$auth->setAccessType($accessType); |
|
233 | + self::$auth->setAccessType($accessType); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * {@code "auto"} to request auto-approval when possible. |
240 | 240 | */ |
241 | 241 | public function setApprovalPrompt($approvalPrompt) { |
242 | - self::$auth->setApprovalPrompt($approvalPrompt); |
|
242 | + self::$auth->setApprovalPrompt($approvalPrompt); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | * @param string $applicationName |
248 | 248 | */ |
249 | 249 | public function setApplicationName($applicationName) { |
250 | - global $apiConfig; |
|
251 | - $apiConfig['application_name'] = $applicationName; |
|
250 | + global $apiConfig; |
|
251 | + $apiConfig['application_name'] = $applicationName; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -256,16 +256,16 @@ discard block |
||
256 | 256 | * @param string $clientId |
257 | 257 | */ |
258 | 258 | public function setClientId($clientId) { |
259 | - global $apiConfig; |
|
260 | - $apiConfig['oauth2_client_id'] = $clientId; |
|
261 | - self::$auth->clientId = $clientId; |
|
259 | + global $apiConfig; |
|
260 | + $apiConfig['oauth2_client_id'] = $clientId; |
|
261 | + self::$auth->clientId = $clientId; |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
265 | 265 | * Get the OAuth 2.0 Client ID. |
266 | 266 | */ |
267 | 267 | public function getClientId() { |
268 | - return self::$auth->clientId; |
|
268 | + return self::$auth->clientId; |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -273,16 +273,16 @@ discard block |
||
273 | 273 | * @param string $clientSecret |
274 | 274 | */ |
275 | 275 | public function setClientSecret($clientSecret) { |
276 | - global $apiConfig; |
|
277 | - $apiConfig['oauth2_client_secret'] = $clientSecret; |
|
278 | - self::$auth->clientSecret = $clientSecret; |
|
276 | + global $apiConfig; |
|
277 | + $apiConfig['oauth2_client_secret'] = $clientSecret; |
|
278 | + self::$auth->clientSecret = $clientSecret; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | 282 | * Get the OAuth 2.0 Client Secret. |
283 | 283 | */ |
284 | 284 | public function getClientSecret() { |
285 | - return self::$auth->clientSecret; |
|
285 | + return self::$auth->clientSecret; |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -290,16 +290,16 @@ discard block |
||
290 | 290 | * @param string $redirectUri |
291 | 291 | */ |
292 | 292 | public function setRedirectUri($redirectUri) { |
293 | - global $apiConfig; |
|
294 | - $apiConfig['oauth2_redirect_uri'] = $redirectUri; |
|
295 | - self::$auth->redirectUri = $redirectUri; |
|
293 | + global $apiConfig; |
|
294 | + $apiConfig['oauth2_redirect_uri'] = $redirectUri; |
|
295 | + self::$auth->redirectUri = $redirectUri; |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
299 | 299 | * Get the OAuth 2.0 Redirect URI. |
300 | 300 | */ |
301 | 301 | public function getRedirectUri() { |
302 | - return self::$auth->redirectUri; |
|
302 | + return self::$auth->redirectUri; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @return void |
309 | 309 | */ |
310 | 310 | public function refreshToken($refreshToken) { |
311 | - self::$auth->refreshToken($refreshToken); |
|
311 | + self::$auth->refreshToken($refreshToken); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @return boolean Returns True if the revocation was successful, otherwise False. |
320 | 320 | */ |
321 | 321 | public function revokeToken($token = null) { |
322 | - self::$auth->revokeToken($token); |
|
322 | + self::$auth->revokeToken($token); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | * successful. |
332 | 332 | */ |
333 | 333 | public function verifyIdToken($token = null) { |
334 | - return self::$auth->verifyIdToken($token); |
|
334 | + return self::$auth->verifyIdToken($token); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @return void |
340 | 340 | */ |
341 | 341 | public function setAssertionCredentials(Google_AssertionCredentials $creds) { |
342 | - self::$auth->setAssertionCredentials($creds); |
|
342 | + self::$auth->setAssertionCredentials($creds); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | * @param array $scopes, ie: array('https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/moderator') |
350 | 350 | */ |
351 | 351 | public function setScopes($scopes) { |
352 | - $this->scopes = is_string($scopes) ? explode(" ", $scopes) : $scopes; |
|
352 | + $this->scopes = is_string($scopes) ? explode(" ", $scopes) : $scopes; |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | /** |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | * |
359 | 359 | */ |
360 | 360 | public function getScopes() { |
361 | - return $this->scopes; |
|
361 | + return $this->scopes; |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | * @param array $requestVisibleActions Array of app activity types |
371 | 371 | */ |
372 | 372 | public function setRequestVisibleActions($requestVisibleActions) { |
373 | - self::$auth->requestVisibleActions = |
|
374 | - join(" ", $requestVisibleActions); |
|
373 | + self::$auth->requestVisibleActions = |
|
374 | + join(" ", $requestVisibleActions); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * @experimental |
383 | 383 | */ |
384 | 384 | public function setUseObjects($useObjects) { |
385 | - global $apiConfig; |
|
386 | - $apiConfig['use_objects'] = $useObjects; |
|
385 | + global $apiConfig; |
|
386 | + $apiConfig['use_objects'] = $useObjects; |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | * @experimental |
395 | 395 | */ |
396 | 396 | public function setUseBatch($useBatch) { |
397 | - self::$useBatch = $useBatch; |
|
397 | + self::$useBatch = $useBatch; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | * @return Google_Auth the implementation of apiAuth. |
403 | 403 | */ |
404 | 404 | public static function getAuth() { |
405 | - return Google_Client::$auth; |
|
405 | + return Google_Client::$auth; |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
@@ -410,14 +410,14 @@ discard block |
||
410 | 410 | * @return Google_IO the implementation of apiIo. |
411 | 411 | */ |
412 | 412 | public static function getIo() { |
413 | - return Google_Client::$io; |
|
413 | + return Google_Client::$io; |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
417 | 417 | * @return Google_Cache the implementation of apiCache. |
418 | 418 | */ |
419 | 419 | public function getCache() { |
420 | - return Google_Client::$cache; |
|
420 | + return Google_Client::$cache; |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | |
@@ -442,14 +442,14 @@ discard block |
||
442 | 442 | * response. Defaults to []. |
443 | 443 | */ |
444 | 444 | public function __construct($message, $code = 0, Exception $previous = null, |
445 | - $errors = array()) { |
|
446 | - if(version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
447 | - parent::__construct($message, $code, $previous); |
|
448 | - } else { |
|
449 | - parent::__construct($message, $code); |
|
450 | - } |
|
445 | + $errors = array()) { |
|
446 | + if(version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
447 | + parent::__construct($message, $code, $previous); |
|
448 | + } else { |
|
449 | + parent::__construct($message, $code); |
|
450 | + } |
|
451 | 451 | |
452 | - $this->errors = $errors; |
|
452 | + $this->errors = $errors; |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -466,6 +466,6 @@ discard block |
||
466 | 466 | * @return [{string, string}] List of errors return in an HTTP response or []. |
467 | 467 | */ |
468 | 468 | public function getErrors() { |
469 | - return $this->errors; |
|
469 | + return $this->errors; |
|
470 | 470 | } |
471 | 471 | } |
@@ -17,42 +17,42 @@ discard block |
||
17 | 17 | |
18 | 18 | // Check for the json extension, the Google APIs PHP Client won't function |
19 | 19 | // without it. |
20 | -if (! function_exists('json_decode')) { |
|
20 | +if (!function_exists('json_decode')) { |
|
21 | 21 | throw new Exception('Google PHP API Client requires the JSON PHP extension'); |
22 | 22 | } |
23 | 23 | |
24 | -if (! function_exists('http_build_query')) { |
|
24 | +if (!function_exists('http_build_query')) { |
|
25 | 25 | throw new Exception('Google PHP API Client requires http_build_query()'); |
26 | 26 | } |
27 | 27 | |
28 | -if (! ini_get('date.timezone') && function_exists('date_default_timezone_set')) { |
|
28 | +if (!ini_get('date.timezone') && function_exists('date_default_timezone_set')) { |
|
29 | 29 | date_default_timezone_set('UTC'); |
30 | 30 | } |
31 | -define("GA_API_Path", dirname(__FILE__) .'/'); |
|
31 | +define("GA_API_Path", dirname(__FILE__).'/'); |
|
32 | 32 | // hack around with the include paths a bit so the library 'just works' |
33 | 33 | //set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path()); |
34 | 34 | |
35 | -require_once (dirname(__FILE__) . "/config.php"); |
|
35 | +require_once (dirname(__FILE__)."/config.php"); |
|
36 | 36 | // If a local configuration file is found, merge it's values with the default configuration |
37 | -if (file_exists(dirname(__FILE__) . '/local_config.php')) { |
|
37 | +if (file_exists(dirname(__FILE__).'/local_config.php')) { |
|
38 | 38 | $defaultConfig = $apiConfig; |
39 | - require_once (dirname(__FILE__) . '/local_config.php'); |
|
39 | + require_once (dirname(__FILE__).'/local_config.php'); |
|
40 | 40 | $apiConfig = array_merge($defaultConfig, $apiConfig); |
41 | 41 | } |
42 | 42 | |
43 | 43 | // Include the top level classes, they each include their own dependencies |
44 | -require_once GA_API_Path. 'service/Google_Model.php'; |
|
45 | -require_once GA_API_Path. 'service/Google_Service.php'; |
|
46 | -require_once GA_API_Path. 'service/Google_ServiceResource.php'; |
|
47 | -require_once GA_API_Path. 'auth/Google_AssertionCredentials.php'; |
|
48 | -require_once GA_API_Path. 'auth/Google_Signer.php'; |
|
49 | -require_once GA_API_Path. 'auth/Google_P12Signer.php'; |
|
50 | -require_once GA_API_Path. 'service/Google_BatchRequest.php'; |
|
51 | -require_once GA_API_Path. 'external/URITemplateParser.php'; |
|
52 | -require_once GA_API_Path. 'auth/Google_Auth.php'; |
|
53 | -require_once GA_API_Path. 'cache/Google_Cache.php'; |
|
54 | -require_once GA_API_Path. 'io/Google_IO.php'; |
|
55 | -require_once(GA_API_Path. 'service/Google_MediaFileUpload.php'); |
|
44 | +require_once GA_API_Path.'service/Google_Model.php'; |
|
45 | +require_once GA_API_Path.'service/Google_Service.php'; |
|
46 | +require_once GA_API_Path.'service/Google_ServiceResource.php'; |
|
47 | +require_once GA_API_Path.'auth/Google_AssertionCredentials.php'; |
|
48 | +require_once GA_API_Path.'auth/Google_Signer.php'; |
|
49 | +require_once GA_API_Path.'auth/Google_P12Signer.php'; |
|
50 | +require_once GA_API_Path.'service/Google_BatchRequest.php'; |
|
51 | +require_once GA_API_Path.'external/URITemplateParser.php'; |
|
52 | +require_once GA_API_Path.'auth/Google_Auth.php'; |
|
53 | +require_once GA_API_Path.'cache/Google_Cache.php'; |
|
54 | +require_once GA_API_Path.'io/Google_IO.php'; |
|
55 | +require_once(GA_API_Path.'service/Google_MediaFileUpload.php'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * The Google API Client |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $scopes[] = $val['scope']; |
146 | 146 | } |
147 | 147 | } else { |
148 | - $scopes[] = 'https://www.googleapis.com/auth/' . $key; |
|
148 | + $scopes[] = 'https://www.googleapis.com/auth/'.$key; |
|
149 | 149 | } |
150 | 150 | unset($val['discoveryURI']); |
151 | 151 | unset($val['scope']); |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | */ |
444 | 444 | public function __construct($message, $code = 0, Exception $previous = null, |
445 | 445 | $errors = array()) { |
446 | - if(version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
446 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
447 | 447 | parent::__construct($message, $code, $previous); |
448 | 448 | } else { |
449 | 449 | parent::__construct($message, $code); |
@@ -44,6 +44,9 @@ discard block |
||
44 | 44 | |
45 | 45 | public $accessKey; |
46 | 46 | |
47 | + /** |
|
48 | + * @param string|boolean $url |
|
49 | + */ |
|
47 | 50 | public function __construct($url, $method = 'GET', $headers = array(), $postBody = null) { |
48 | 51 | $this->setUrl($url); |
49 | 52 | $this->setRequestMethod($method); |
@@ -87,7 +90,7 @@ discard block |
||
87 | 90 | } |
88 | 91 | |
89 | 92 | /** |
90 | - * @return string HTTP Response Code. |
|
93 | + * @return integer HTTP Response Code. |
|
91 | 94 | */ |
92 | 95 | public function getResponseHttpCode() { |
93 | 96 | return (int) $this->responseHttpCode; |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | class Google_HttpRequest { |
27 | 27 | const USER_AGENT_SUFFIX = "google-api-php-client/0.6.5"; |
28 | 28 | private $batchHeaders = array( |
29 | - 'Content-Type' => 'application/http', |
|
30 | - 'Content-Transfer-Encoding' => 'binary', |
|
31 | - 'MIME-Version' => '1.0', |
|
32 | - 'Content-Length' => '' |
|
29 | + 'Content-Type' => 'application/http', |
|
30 | + 'Content-Transfer-Encoding' => 'binary', |
|
31 | + 'MIME-Version' => '1.0', |
|
32 | + 'Content-Length' => '' |
|
33 | 33 | ); |
34 | 34 | |
35 | 35 | protected $url; |
@@ -45,17 +45,17 @@ discard block |
||
45 | 45 | public $accessKey; |
46 | 46 | |
47 | 47 | public function __construct($url, $method = 'GET', $headers = array(), $postBody = null) { |
48 | - $this->setUrl($url); |
|
49 | - $this->setRequestMethod($method); |
|
50 | - $this->setRequestHeaders($headers); |
|
51 | - $this->setPostBody($postBody); |
|
52 | - |
|
53 | - global $apiConfig; |
|
54 | - if (empty($apiConfig['application_name'])) { |
|
55 | - $this->userAgent = self::USER_AGENT_SUFFIX; |
|
56 | - } else { |
|
57 | - $this->userAgent = $apiConfig['application_name'] . " " . self::USER_AGENT_SUFFIX; |
|
58 | - } |
|
48 | + $this->setUrl($url); |
|
49 | + $this->setRequestMethod($method); |
|
50 | + $this->setRequestHeaders($headers); |
|
51 | + $this->setPostBody($postBody); |
|
52 | + |
|
53 | + global $apiConfig; |
|
54 | + if (empty($apiConfig['application_name'])) { |
|
55 | + $this->userAgent = self::USER_AGENT_SUFFIX; |
|
56 | + } else { |
|
57 | + $this->userAgent = $apiConfig['application_name'] . " " . self::USER_AGENT_SUFFIX; |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | * @see http://oauth.net/core/1.0a/#anchor13 |
66 | 66 | */ |
67 | 67 | public function getBaseUrl() { |
68 | - if ($pos = strpos($this->url, '?')) { |
|
69 | - return substr($this->url, 0, $pos); |
|
70 | - } |
|
71 | - return $this->url; |
|
68 | + if ($pos = strpos($this->url, '?')) { |
|
69 | + return substr($this->url, 0, $pos); |
|
70 | + } |
|
71 | + return $this->url; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,41 +77,41 @@ discard block |
||
77 | 77 | * @return array Query parameters in the query string. |
78 | 78 | */ |
79 | 79 | public function getQueryParams() { |
80 | - if ($pos = strpos($this->url, '?')) { |
|
81 | - $queryStr = substr($this->url, $pos + 1); |
|
82 | - $params = array(); |
|
83 | - parse_str($queryStr, $params); |
|
84 | - return $params; |
|
85 | - } |
|
86 | - return array(); |
|
80 | + if ($pos = strpos($this->url, '?')) { |
|
81 | + $queryStr = substr($this->url, $pos + 1); |
|
82 | + $params = array(); |
|
83 | + parse_str($queryStr, $params); |
|
84 | + return $params; |
|
85 | + } |
|
86 | + return array(); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | 90 | * @return string HTTP Response Code. |
91 | 91 | */ |
92 | 92 | public function getResponseHttpCode() { |
93 | - return (int) $this->responseHttpCode; |
|
93 | + return (int) $this->responseHttpCode; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | 97 | * @param int $responseHttpCode HTTP Response Code. |
98 | 98 | */ |
99 | 99 | public function setResponseHttpCode($responseHttpCode) { |
100 | - $this->responseHttpCode = $responseHttpCode; |
|
100 | + $this->responseHttpCode = $responseHttpCode; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * @return $responseHeaders (array) HTTP Response Headers. |
105 | 105 | */ |
106 | 106 | public function getResponseHeaders() { |
107 | - return $this->responseHeaders; |
|
107 | + return $this->responseHeaders; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * @return string HTTP Response Body |
112 | 112 | */ |
113 | 113 | public function getResponseBody() { |
114 | - return $this->responseBody; |
|
114 | + return $this->responseBody; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | * to be normalized. |
120 | 120 | */ |
121 | 121 | public function setResponseHeaders($headers) { |
122 | - $headers = Google_Utils::normalize($headers); |
|
123 | - if ($this->responseHeaders) { |
|
124 | - $headers = array_merge($this->responseHeaders, $headers); |
|
125 | - } |
|
122 | + $headers = Google_Utils::normalize($headers); |
|
123 | + if ($this->responseHeaders) { |
|
124 | + $headers = array_merge($this->responseHeaders, $headers); |
|
125 | + } |
|
126 | 126 | |
127 | - $this->responseHeaders = $headers; |
|
127 | + $this->responseHeaders = $headers; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -133,16 +133,16 @@ discard block |
||
133 | 133 | * false if unavailable. |
134 | 134 | */ |
135 | 135 | public function getResponseHeader($key) { |
136 | - return isset($this->responseHeaders[$key]) |
|
137 | - ? $this->responseHeaders[$key] |
|
138 | - : false; |
|
136 | + return isset($this->responseHeaders[$key]) |
|
137 | + ? $this->responseHeaders[$key] |
|
138 | + : false; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @param string $responseBody The HTTP response body. |
143 | 143 | */ |
144 | 144 | public function setResponseBody($responseBody) { |
145 | - $this->responseBody = $responseBody; |
|
145 | + $this->responseBody = $responseBody; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,21 +150,21 @@ discard block |
||
150 | 150 | */ |
151 | 151 | |
152 | 152 | public function getUrl() { |
153 | - return $this->url; |
|
153 | + return $this->url; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * @return string $method HTTP Request Method. |
158 | 158 | */ |
159 | 159 | public function getRequestMethod() { |
160 | - return $this->requestMethod; |
|
160 | + return $this->requestMethod; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
164 | 164 | * @return array $headers HTTP Request Headers. |
165 | 165 | */ |
166 | 166 | public function getRequestHeaders() { |
167 | - return $this->requestHeaders; |
|
167 | + return $this->requestHeaders; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,32 +173,32 @@ discard block |
||
173 | 173 | * false if unavailable. |
174 | 174 | */ |
175 | 175 | public function getRequestHeader($key) { |
176 | - return isset($this->requestHeaders[$key]) |
|
177 | - ? $this->requestHeaders[$key] |
|
178 | - : false; |
|
176 | + return isset($this->requestHeaders[$key]) |
|
177 | + ? $this->requestHeaders[$key] |
|
178 | + : false; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | 182 | * @return string $postBody HTTP Request Body. |
183 | 183 | */ |
184 | 184 | public function getPostBody() { |
185 | - return $this->postBody; |
|
185 | + return $this->postBody; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | 189 | * @param string $url the url to set |
190 | 190 | */ |
191 | 191 | public function setUrl($url) { |
192 | - if (substr($url, 0, 4) == 'http') { |
|
193 | - $this->url = $url; |
|
194 | - } else { |
|
195 | - // Force the path become relative. |
|
196 | - if (substr($url, 0, 1) !== '/') { |
|
197 | - $url = '/' . $url; |
|
198 | - } |
|
199 | - global $apiConfig; |
|
200 | - $this->url = $apiConfig['basePath'] . $url; |
|
201 | - } |
|
192 | + if (substr($url, 0, 4) == 'http') { |
|
193 | + $this->url = $url; |
|
194 | + } else { |
|
195 | + // Force the path become relative. |
|
196 | + if (substr($url, 0, 1) !== '/') { |
|
197 | + $url = '/' . $url; |
|
198 | + } |
|
199 | + global $apiConfig; |
|
200 | + $this->url = $apiConfig['basePath'] . $url; |
|
201 | + } |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | */ |
209 | 209 | public function setRequestMethod($method) { |
210 | - $this->requestMethod = strtoupper($method); |
|
210 | + $this->requestMethod = strtoupper($method); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -215,18 +215,18 @@ discard block |
||
215 | 215 | * to be set and normalized. |
216 | 216 | */ |
217 | 217 | public function setRequestHeaders($headers) { |
218 | - $headers = Google_Utils::normalize($headers); |
|
219 | - if ($this->requestHeaders) { |
|
220 | - $headers = array_merge($this->requestHeaders, $headers); |
|
221 | - } |
|
222 | - $this->requestHeaders = $headers; |
|
218 | + $headers = Google_Utils::normalize($headers); |
|
219 | + if ($this->requestHeaders) { |
|
220 | + $headers = array_merge($this->requestHeaders, $headers); |
|
221 | + } |
|
222 | + $this->requestHeaders = $headers; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
226 | 226 | * @param string $postBody the postBody to set |
227 | 227 | */ |
228 | 228 | public function setPostBody($postBody) { |
229 | - $this->postBody = $postBody; |
|
229 | + $this->postBody = $postBody; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -234,14 +234,14 @@ discard block |
||
234 | 234 | * @param string $userAgent The User-Agent. |
235 | 235 | */ |
236 | 236 | public function setUserAgent($userAgent) { |
237 | - $this->userAgent = $userAgent; |
|
237 | + $this->userAgent = $userAgent; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
241 | 241 | * @return string The User-Agent. |
242 | 242 | */ |
243 | 243 | public function getUserAgent() { |
244 | - return $this->userAgent; |
|
244 | + return $this->userAgent; |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -251,28 +251,28 @@ discard block |
||
251 | 251 | * @return string The md5 hash of the request cache key. |
252 | 252 | */ |
253 | 253 | public function getCacheKey() { |
254 | - $key = $this->getUrl(); |
|
254 | + $key = $this->getUrl(); |
|
255 | 255 | |
256 | - if (isset($this->accessKey)) { |
|
257 | - $key .= $this->accessKey; |
|
258 | - } |
|
256 | + if (isset($this->accessKey)) { |
|
257 | + $key .= $this->accessKey; |
|
258 | + } |
|
259 | 259 | |
260 | - if (isset($this->requestHeaders['authorization'])) { |
|
261 | - $key .= $this->requestHeaders['authorization']; |
|
262 | - } |
|
260 | + if (isset($this->requestHeaders['authorization'])) { |
|
261 | + $key .= $this->requestHeaders['authorization']; |
|
262 | + } |
|
263 | 263 | |
264 | - return md5($key); |
|
264 | + return md5($key); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | public function getParsedCacheControl() { |
268 | - $parsed = array(); |
|
269 | - $rawCacheControl = $this->getResponseHeader('cache-control'); |
|
270 | - if ($rawCacheControl) { |
|
271 | - $rawCacheControl = str_replace(', ', '&', $rawCacheControl); |
|
272 | - parse_str($rawCacheControl, $parsed); |
|
273 | - } |
|
274 | - |
|
275 | - return $parsed; |
|
268 | + $parsed = array(); |
|
269 | + $rawCacheControl = $this->getResponseHeader('cache-control'); |
|
270 | + if ($rawCacheControl) { |
|
271 | + $rawCacheControl = str_replace(', ', '&', $rawCacheControl); |
|
272 | + parse_str($rawCacheControl, $parsed); |
|
273 | + } |
|
274 | + |
|
275 | + return $parsed; |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -280,25 +280,25 @@ discard block |
||
280 | 280 | * @return string A string representation of the HTTP Request. |
281 | 281 | */ |
282 | 282 | public function toBatchString($id) { |
283 | - $str = ''; |
|
284 | - foreach($this->batchHeaders as $key => $val) { |
|
285 | - $str .= $key . ': ' . $val . "\n"; |
|
286 | - } |
|
287 | - |
|
288 | - $str .= "Content-ID: $id\n"; |
|
289 | - $str .= "\n"; |
|
290 | - |
|
291 | - $path = parse_url($this->getUrl(), PHP_URL_PATH); |
|
292 | - $str .= $this->getRequestMethod() . ' ' . $path . " HTTP/1.1\n"; |
|
293 | - foreach($this->getRequestHeaders() as $key => $val) { |
|
294 | - $str .= $key . ': ' . $val . "\n"; |
|
295 | - } |
|
296 | - |
|
297 | - if ($this->getPostBody()) { |
|
298 | - $str .= "\n"; |
|
299 | - $str .= $this->getPostBody(); |
|
300 | - } |
|
301 | - |
|
302 | - return $str; |
|
283 | + $str = ''; |
|
284 | + foreach($this->batchHeaders as $key => $val) { |
|
285 | + $str .= $key . ': ' . $val . "\n"; |
|
286 | + } |
|
287 | + |
|
288 | + $str .= "Content-ID: $id\n"; |
|
289 | + $str .= "\n"; |
|
290 | + |
|
291 | + $path = parse_url($this->getUrl(), PHP_URL_PATH); |
|
292 | + $str .= $this->getRequestMethod() . ' ' . $path . " HTTP/1.1\n"; |
|
293 | + foreach($this->getRequestHeaders() as $key => $val) { |
|
294 | + $str .= $key . ': ' . $val . "\n"; |
|
295 | + } |
|
296 | + |
|
297 | + if ($this->getPostBody()) { |
|
298 | + $str .= "\n"; |
|
299 | + $str .= $this->getPostBody(); |
|
300 | + } |
|
301 | + |
|
302 | + return $str; |
|
303 | 303 | } |
304 | 304 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | if (empty($apiConfig['application_name'])) { |
55 | 55 | $this->userAgent = self::USER_AGENT_SUFFIX; |
56 | 56 | } else { |
57 | - $this->userAgent = $apiConfig['application_name'] . " " . self::USER_AGENT_SUFFIX; |
|
57 | + $this->userAgent = $apiConfig['application_name']." ".self::USER_AGENT_SUFFIX; |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -194,10 +194,10 @@ discard block |
||
194 | 194 | } else { |
195 | 195 | // Force the path become relative. |
196 | 196 | if (substr($url, 0, 1) !== '/') { |
197 | - $url = '/' . $url; |
|
197 | + $url = '/'.$url; |
|
198 | 198 | } |
199 | 199 | global $apiConfig; |
200 | - $this->url = $apiConfig['basePath'] . $url; |
|
200 | + $this->url = $apiConfig['basePath'].$url; |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
@@ -281,17 +281,17 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function toBatchString($id) { |
283 | 283 | $str = ''; |
284 | - foreach($this->batchHeaders as $key => $val) { |
|
285 | - $str .= $key . ': ' . $val . "\n"; |
|
284 | + foreach ($this->batchHeaders as $key => $val) { |
|
285 | + $str .= $key.': '.$val."\n"; |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | $str .= "Content-ID: $id\n"; |
289 | 289 | $str .= "\n"; |
290 | 290 | |
291 | 291 | $path = parse_url($this->getUrl(), PHP_URL_PATH); |
292 | - $str .= $this->getRequestMethod() . ' ' . $path . " HTTP/1.1\n"; |
|
293 | - foreach($this->getRequestHeaders() as $key => $val) { |
|
294 | - $str .= $key . ': ' . $val . "\n"; |
|
292 | + $str .= $this->getRequestMethod().' '.$path." HTTP/1.1\n"; |
|
293 | + foreach ($this->getRequestHeaders() as $key => $val) { |
|
294 | + $str .= $key.': '.$val."\n"; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | if ($this->getPostBody()) { |
@@ -140,6 +140,9 @@ |
||
140 | 140 | public function setOptions($options) { |
141 | 141 | } |
142 | 142 | |
143 | + /** |
|
144 | + * @return integer |
|
145 | + */ |
|
143 | 146 | private function getHttpResponseCode($response_headers) { |
144 | 147 | $header_count = count($response_headers); |
145 | 148 |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | private static $ENTITY_HTTP_METHODS = array("POST" => null, "PUT" => null); |
29 | 29 | |
30 | 30 | private static $DEFAULT_HTTP_CONTEXT = array( |
31 | - "follow_location" => 0, |
|
32 | - "ignore_errors" => 1, |
|
31 | + "follow_location" => 0, |
|
32 | + "ignore_errors" => 1, |
|
33 | 33 | ); |
34 | 34 | |
35 | 35 | private static $DEFAULT_SSL_CONTEXT = array( |
36 | - "verify_peer" => true, |
|
36 | + "verify_peer" => true, |
|
37 | 37 | ); |
38 | 38 | |
39 | 39 | /** |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | * responseHttpCode, responseHeaders and responseBody. |
48 | 48 | */ |
49 | 49 | public function authenticatedRequest(Google_HttpRequest $request) { |
50 | - $request = Google_Client::$auth->sign($request); |
|
51 | - return $this->makeRequest($request); |
|
50 | + $request = Google_Client::$auth->sign($request); |
|
51 | + return $this->makeRequest($request); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -60,77 +60,77 @@ discard block |
||
60 | 60 | * @throws Google_IOException on curl or IO error |
61 | 61 | */ |
62 | 62 | public function makeRequest(Google_HttpRequest $request) { |
63 | - // First, check to see if we have a valid cached version. |
|
64 | - $cached = $this->getCachedRequest($request); |
|
65 | - if ($cached !== false) { |
|
66 | - if (!$this->checkMustRevaliadateCachedRequest($cached, $request)) { |
|
67 | - return $cached; |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - $default_options = stream_context_get_options(stream_context_get_default()); |
|
72 | - |
|
73 | - $requestHttpContext = array_key_exists('http', $default_options) ? |
|
74 | - $default_options['http'] : array(); |
|
75 | - if (array_key_exists($request->getRequestMethod(), |
|
76 | - self::$ENTITY_HTTP_METHODS)) { |
|
77 | - $request = $this->processEntityRequest($request); |
|
78 | - } |
|
79 | - |
|
80 | - if ($request->getPostBody()) { |
|
81 | - $requestHttpContext["content"] = $request->getPostBody(); |
|
82 | - } |
|
83 | - |
|
84 | - $requestHeaders = $request->getRequestHeaders(); |
|
85 | - if ($requestHeaders && is_array($requestHeaders)) { |
|
86 | - $headers = ""; |
|
87 | - foreach($requestHeaders as $k => $v) { |
|
88 | - $headers .= "$k: $v\n"; |
|
89 | - } |
|
90 | - $requestHttpContext["header"] = $headers; |
|
91 | - } |
|
92 | - |
|
93 | - $requestHttpContext["method"] = $request->getRequestMethod(); |
|
94 | - $requestHttpContext["user_agent"] = $request->getUserAgent(); |
|
95 | - |
|
96 | - $requestSslContext = array_key_exists('ssl', $default_options) ? |
|
97 | - $default_options['ssl'] : array(); |
|
98 | - |
|
99 | - if (!array_key_exists("cafile", $requestSslContext)) { |
|
100 | - $requestSslContext["cafile"] = dirname(__FILE__) . '/cacerts.pem'; |
|
101 | - } |
|
102 | - |
|
103 | - $options = array("http" => array_merge(self::$DEFAULT_HTTP_CONTEXT, |
|
104 | - $requestHttpContext), |
|
105 | - "ssl" => array_merge(self::$DEFAULT_SSL_CONTEXT, |
|
106 | - $requestSslContext)); |
|
107 | - |
|
108 | - $context = stream_context_create($options); |
|
109 | - |
|
110 | - $response_data = file_get_contents($request->getUrl(), |
|
111 | - false, |
|
112 | - $context); |
|
113 | - |
|
114 | - if (false === $response_data) { |
|
115 | - throw new Google_IOException("HTTP Error: Unable to connect"); |
|
116 | - } |
|
117 | - |
|
118 | - $respHttpCode = $this->getHttpResponseCode($http_response_header); |
|
119 | - $responseHeaders = $this->getHttpResponseHeaders($http_response_header); |
|
120 | - |
|
121 | - if ($respHttpCode == 304 && $cached) { |
|
122 | - // If the server responded NOT_MODIFIED, return the cached request. |
|
123 | - $this->updateCachedRequest($cached, $responseHeaders); |
|
124 | - return $cached; |
|
125 | - } |
|
126 | - |
|
127 | - $request->setResponseHttpCode($respHttpCode); |
|
128 | - $request->setResponseHeaders($responseHeaders); |
|
129 | - $request->setResponseBody($response_data); |
|
130 | - // Store the request in cache (the function checks to see if the request |
|
131 | - // can actually be cached) |
|
132 | - $this->setCachedRequest($request); |
|
133 | - return $request; |
|
63 | + // First, check to see if we have a valid cached version. |
|
64 | + $cached = $this->getCachedRequest($request); |
|
65 | + if ($cached !== false) { |
|
66 | + if (!$this->checkMustRevaliadateCachedRequest($cached, $request)) { |
|
67 | + return $cached; |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + $default_options = stream_context_get_options(stream_context_get_default()); |
|
72 | + |
|
73 | + $requestHttpContext = array_key_exists('http', $default_options) ? |
|
74 | + $default_options['http'] : array(); |
|
75 | + if (array_key_exists($request->getRequestMethod(), |
|
76 | + self::$ENTITY_HTTP_METHODS)) { |
|
77 | + $request = $this->processEntityRequest($request); |
|
78 | + } |
|
79 | + |
|
80 | + if ($request->getPostBody()) { |
|
81 | + $requestHttpContext["content"] = $request->getPostBody(); |
|
82 | + } |
|
83 | + |
|
84 | + $requestHeaders = $request->getRequestHeaders(); |
|
85 | + if ($requestHeaders && is_array($requestHeaders)) { |
|
86 | + $headers = ""; |
|
87 | + foreach($requestHeaders as $k => $v) { |
|
88 | + $headers .= "$k: $v\n"; |
|
89 | + } |
|
90 | + $requestHttpContext["header"] = $headers; |
|
91 | + } |
|
92 | + |
|
93 | + $requestHttpContext["method"] = $request->getRequestMethod(); |
|
94 | + $requestHttpContext["user_agent"] = $request->getUserAgent(); |
|
95 | + |
|
96 | + $requestSslContext = array_key_exists('ssl', $default_options) ? |
|
97 | + $default_options['ssl'] : array(); |
|
98 | + |
|
99 | + if (!array_key_exists("cafile", $requestSslContext)) { |
|
100 | + $requestSslContext["cafile"] = dirname(__FILE__) . '/cacerts.pem'; |
|
101 | + } |
|
102 | + |
|
103 | + $options = array("http" => array_merge(self::$DEFAULT_HTTP_CONTEXT, |
|
104 | + $requestHttpContext), |
|
105 | + "ssl" => array_merge(self::$DEFAULT_SSL_CONTEXT, |
|
106 | + $requestSslContext)); |
|
107 | + |
|
108 | + $context = stream_context_create($options); |
|
109 | + |
|
110 | + $response_data = file_get_contents($request->getUrl(), |
|
111 | + false, |
|
112 | + $context); |
|
113 | + |
|
114 | + if (false === $response_data) { |
|
115 | + throw new Google_IOException("HTTP Error: Unable to connect"); |
|
116 | + } |
|
117 | + |
|
118 | + $respHttpCode = $this->getHttpResponseCode($http_response_header); |
|
119 | + $responseHeaders = $this->getHttpResponseHeaders($http_response_header); |
|
120 | + |
|
121 | + if ($respHttpCode == 304 && $cached) { |
|
122 | + // If the server responded NOT_MODIFIED, return the cached request. |
|
123 | + $this->updateCachedRequest($cached, $responseHeaders); |
|
124 | + return $cached; |
|
125 | + } |
|
126 | + |
|
127 | + $request->setResponseHttpCode($respHttpCode); |
|
128 | + $request->setResponseHeaders($responseHeaders); |
|
129 | + $request->setResponseBody($response_data); |
|
130 | + // Store the request in cache (the function checks to see if the request |
|
131 | + // can actually be cached) |
|
132 | + $this->setCachedRequest($request); |
|
133 | + return $request; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -141,30 +141,30 @@ discard block |
||
141 | 141 | } |
142 | 142 | |
143 | 143 | private function getHttpResponseCode($response_headers) { |
144 | - $header_count = count($response_headers); |
|
145 | - |
|
146 | - for ($i = 0; $i < $header_count; $i++) { |
|
147 | - $header = $response_headers[$i]; |
|
148 | - if (strncasecmp("HTTP", $header, strlen("HTTP")) == 0) { |
|
149 | - $response = explode(' ', $header); |
|
150 | - return $response[1]; |
|
151 | - } |
|
152 | - } |
|
153 | - return 'UNKNOWN'; |
|
144 | + $header_count = count($response_headers); |
|
145 | + |
|
146 | + for ($i = 0; $i < $header_count; $i++) { |
|
147 | + $header = $response_headers[$i]; |
|
148 | + if (strncasecmp("HTTP", $header, strlen("HTTP")) == 0) { |
|
149 | + $response = explode(' ', $header); |
|
150 | + return $response[1]; |
|
151 | + } |
|
152 | + } |
|
153 | + return 'UNKNOWN'; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | private function getHttpResponseHeaders($response_headers) { |
157 | - $header_count = count($response_headers); |
|
158 | - $headers = array(); |
|
159 | - |
|
160 | - for ($i = 0; $i < $header_count; $i++) { |
|
161 | - $header = $response_headers[$i]; |
|
162 | - $header_parts = explode(':', $header); |
|
163 | - if (count($header_parts) == 2) { |
|
164 | - $headers[$header_parts[0]] = $header_parts[1]; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - return $headers; |
|
157 | + $header_count = count($response_headers); |
|
158 | + $headers = array(); |
|
159 | + |
|
160 | + for ($i = 0; $i < $header_count; $i++) { |
|
161 | + $header = $response_headers[$i]; |
|
162 | + $header_parts = explode(':', $header); |
|
163 | + if (count($header_parts) == 2) { |
|
164 | + $headers[$header_parts[0]] = $header_parts[1]; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + return $headers; |
|
169 | 169 | } |
170 | 170 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $requestHeaders = $request->getRequestHeaders(); |
85 | 85 | if ($requestHeaders && is_array($requestHeaders)) { |
86 | 86 | $headers = ""; |
87 | - foreach($requestHeaders as $k => $v) { |
|
87 | + foreach ($requestHeaders as $k => $v) { |
|
88 | 88 | $headers .= "$k: $v\n"; |
89 | 89 | } |
90 | 90 | $requestHttpContext["header"] = $headers; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $default_options['ssl'] : array(); |
98 | 98 | |
99 | 99 | if (!array_key_exists("cafile", $requestSslContext)) { |
100 | - $requestSslContext["cafile"] = dirname(__FILE__) . '/cacerts.pem'; |
|
100 | + $requestSslContext["cafile"] = dirname(__FILE__).'/cacerts.pem'; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $options = array("http" => array_merge(self::$DEFAULT_HTTP_CONTEXT, |
@@ -142,7 +142,7 @@ |
||
142 | 142 | |
143 | 143 | /** |
144 | 144 | * Prepares a standard file upload via cURL. |
145 | - * @param $file |
|
145 | + * @param boolean|string $file |
|
146 | 146 | * @param $mime |
147 | 147 | * @return array Includes the processed file name. |
148 | 148 | * @visible For testing. |
@@ -53,19 +53,19 @@ discard block |
||
53 | 53 | * only used if resumable=True |
54 | 54 | */ |
55 | 55 | public function __construct($mimeType, $data, $resumable=false, $chunkSize=false) { |
56 | - $this->mimeType = $mimeType; |
|
57 | - $this->data = $data; |
|
58 | - $this->size = strlen($this->data); |
|
59 | - $this->resumable = $resumable; |
|
60 | - if(!$chunkSize) { |
|
61 | - $chunkSize = 256 * 1024; |
|
62 | - } |
|
63 | - $this->chunkSize = $chunkSize; |
|
64 | - $this->progress = 0; |
|
56 | + $this->mimeType = $mimeType; |
|
57 | + $this->data = $data; |
|
58 | + $this->size = strlen($this->data); |
|
59 | + $this->resumable = $resumable; |
|
60 | + if(!$chunkSize) { |
|
61 | + $chunkSize = 256 * 1024; |
|
62 | + } |
|
63 | + $this->chunkSize = $chunkSize; |
|
64 | + $this->progress = 0; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function setFileSize($size) { |
68 | - $this->size = $size; |
|
68 | + $this->size = $size; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -75,69 +75,69 @@ discard block |
||
75 | 75 | * @return array|bool |
76 | 76 | */ |
77 | 77 | public static function process($meta, &$params) { |
78 | - $payload = array(); |
|
79 | - $meta = is_string($meta) ? json_decode($meta, true) : $meta; |
|
80 | - $uploadType = self::getUploadType($meta, $payload, $params); |
|
81 | - if (!$uploadType) { |
|
82 | - // Process as a normal API request. |
|
83 | - return false; |
|
84 | - } |
|
85 | - |
|
86 | - // Process as a media upload request. |
|
87 | - $params['uploadType'] = array( |
|
88 | - 'type' => 'string', |
|
89 | - 'location' => 'query', |
|
90 | - 'value' => $uploadType, |
|
91 | - ); |
|
92 | - |
|
93 | - $mimeType = isset($params['mimeType']) |
|
94 | - ? $params['mimeType']['value'] |
|
95 | - : false; |
|
96 | - unset($params['mimeType']); |
|
97 | - |
|
98 | - if (!$mimeType) { |
|
99 | - $mimeType = $payload['content-type']; |
|
100 | - } |
|
101 | - |
|
102 | - if (isset($params['file'])) { |
|
103 | - // This is a standard file upload with curl. |
|
104 | - $file = $params['file']['value']; |
|
105 | - unset($params['file']); |
|
106 | - return self::processFileUpload($file, $mimeType); |
|
107 | - } |
|
108 | - |
|
109 | - $data = isset($params['data']) |
|
110 | - ? $params['data']['value'] |
|
111 | - : false; |
|
112 | - unset($params['data']); |
|
113 | - |
|
114 | - if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) { |
|
115 | - $payload['content-type'] = $mimeType; |
|
116 | - $payload['postBody'] = is_string($meta) ? $meta : json_encode($meta); |
|
117 | - |
|
118 | - } elseif (self::UPLOAD_MEDIA_TYPE == $uploadType) { |
|
119 | - // This is a simple media upload. |
|
120 | - $payload['content-type'] = $mimeType; |
|
121 | - $payload['postBody'] = $data; |
|
122 | - } |
|
123 | - |
|
124 | - elseif (self::UPLOAD_MULTIPART_TYPE == $uploadType) { |
|
125 | - // This is a multipart/related upload. |
|
126 | - $boundary = isset($params['boundary']['value']) ? $params['boundary']['value'] : mt_rand(); |
|
127 | - $boundary = str_replace('"', '', $boundary); |
|
128 | - $payload['content-type'] = 'multipart/related; boundary=' . $boundary; |
|
129 | - $related = "--$boundary\r\n"; |
|
130 | - $related .= "Content-Type: application/json; charset=UTF-8\r\n"; |
|
131 | - $related .= "\r\n" . json_encode($meta) . "\r\n"; |
|
132 | - $related .= "--$boundary\r\n"; |
|
133 | - $related .= "Content-Type: $mimeType\r\n"; |
|
134 | - $related .= "Content-Transfer-Encoding: base64\r\n"; |
|
135 | - $related .= "\r\n" . base64_encode($data) . "\r\n"; |
|
136 | - $related .= "--$boundary--"; |
|
137 | - $payload['postBody'] = $related; |
|
138 | - } |
|
139 | - |
|
140 | - return $payload; |
|
78 | + $payload = array(); |
|
79 | + $meta = is_string($meta) ? json_decode($meta, true) : $meta; |
|
80 | + $uploadType = self::getUploadType($meta, $payload, $params); |
|
81 | + if (!$uploadType) { |
|
82 | + // Process as a normal API request. |
|
83 | + return false; |
|
84 | + } |
|
85 | + |
|
86 | + // Process as a media upload request. |
|
87 | + $params['uploadType'] = array( |
|
88 | + 'type' => 'string', |
|
89 | + 'location' => 'query', |
|
90 | + 'value' => $uploadType, |
|
91 | + ); |
|
92 | + |
|
93 | + $mimeType = isset($params['mimeType']) |
|
94 | + ? $params['mimeType']['value'] |
|
95 | + : false; |
|
96 | + unset($params['mimeType']); |
|
97 | + |
|
98 | + if (!$mimeType) { |
|
99 | + $mimeType = $payload['content-type']; |
|
100 | + } |
|
101 | + |
|
102 | + if (isset($params['file'])) { |
|
103 | + // This is a standard file upload with curl. |
|
104 | + $file = $params['file']['value']; |
|
105 | + unset($params['file']); |
|
106 | + return self::processFileUpload($file, $mimeType); |
|
107 | + } |
|
108 | + |
|
109 | + $data = isset($params['data']) |
|
110 | + ? $params['data']['value'] |
|
111 | + : false; |
|
112 | + unset($params['data']); |
|
113 | + |
|
114 | + if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) { |
|
115 | + $payload['content-type'] = $mimeType; |
|
116 | + $payload['postBody'] = is_string($meta) ? $meta : json_encode($meta); |
|
117 | + |
|
118 | + } elseif (self::UPLOAD_MEDIA_TYPE == $uploadType) { |
|
119 | + // This is a simple media upload. |
|
120 | + $payload['content-type'] = $mimeType; |
|
121 | + $payload['postBody'] = $data; |
|
122 | + } |
|
123 | + |
|
124 | + elseif (self::UPLOAD_MULTIPART_TYPE == $uploadType) { |
|
125 | + // This is a multipart/related upload. |
|
126 | + $boundary = isset($params['boundary']['value']) ? $params['boundary']['value'] : mt_rand(); |
|
127 | + $boundary = str_replace('"', '', $boundary); |
|
128 | + $payload['content-type'] = 'multipart/related; boundary=' . $boundary; |
|
129 | + $related = "--$boundary\r\n"; |
|
130 | + $related .= "Content-Type: application/json; charset=UTF-8\r\n"; |
|
131 | + $related .= "\r\n" . json_encode($meta) . "\r\n"; |
|
132 | + $related .= "--$boundary\r\n"; |
|
133 | + $related .= "Content-Type: $mimeType\r\n"; |
|
134 | + $related .= "Content-Transfer-Encoding: base64\r\n"; |
|
135 | + $related .= "\r\n" . base64_encode($data) . "\r\n"; |
|
136 | + $related .= "--$boundary--"; |
|
137 | + $payload['postBody'] = $related; |
|
138 | + } |
|
139 | + |
|
140 | + return $payload; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -148,18 +148,18 @@ discard block |
||
148 | 148 | * @visible For testing. |
149 | 149 | */ |
150 | 150 | public static function processFileUpload($file, $mime) { |
151 | - if (!$file) return array(); |
|
152 | - if (substr($file, 0, 1) != '@') { |
|
153 | - $file = '@' . $file; |
|
154 | - } |
|
155 | - |
|
156 | - // This is a standard file upload with curl. |
|
157 | - $params = array('postBody' => array('file' => $file)); |
|
158 | - if ($mime) { |
|
159 | - $params['content-type'] = $mime; |
|
160 | - } |
|
161 | - |
|
162 | - return $params; |
|
151 | + if (!$file) return array(); |
|
152 | + if (substr($file, 0, 1) != '@') { |
|
153 | + $file = '@' . $file; |
|
154 | + } |
|
155 | + |
|
156 | + // This is a standard file upload with curl. |
|
157 | + $params = array('postBody' => array('file' => $file)); |
|
158 | + if ($mime) { |
|
159 | + $params['content-type'] = $mime; |
|
160 | + } |
|
161 | + |
|
162 | + return $params; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -174,89 +174,89 @@ discard block |
||
174 | 174 | * @return bool|string |
175 | 175 | */ |
176 | 176 | public static function getUploadType($meta, &$payload, &$params) { |
177 | - if (isset($params['mediaUpload']) |
|
178 | - && get_class($params['mediaUpload']['value']) == 'Google_MediaFileUpload') { |
|
179 | - $upload = $params['mediaUpload']['value']; |
|
180 | - unset($params['mediaUpload']); |
|
181 | - $payload['content-type'] = $upload->mimeType; |
|
182 | - if (isset($upload->resumable) && $upload->resumable) { |
|
183 | - return self::UPLOAD_RESUMABLE_TYPE; |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - // Allow the developer to override the upload type. |
|
188 | - if (isset($params['uploadType'])) { |
|
189 | - return $params['uploadType']['value']; |
|
190 | - } |
|
191 | - |
|
192 | - $data = isset($params['data']['value']) |
|
193 | - ? $params['data']['value'] : false; |
|
194 | - |
|
195 | - if (false == $data && false == isset($params['file'])) { |
|
196 | - // No upload data available. |
|
197 | - return false; |
|
198 | - } |
|
199 | - |
|
200 | - if (isset($params['file'])) { |
|
201 | - return self::UPLOAD_MEDIA_TYPE; |
|
202 | - } |
|
203 | - |
|
204 | - if (false == $meta) { |
|
205 | - return self::UPLOAD_MEDIA_TYPE; |
|
206 | - } |
|
207 | - |
|
208 | - return self::UPLOAD_MULTIPART_TYPE; |
|
177 | + if (isset($params['mediaUpload']) |
|
178 | + && get_class($params['mediaUpload']['value']) == 'Google_MediaFileUpload') { |
|
179 | + $upload = $params['mediaUpload']['value']; |
|
180 | + unset($params['mediaUpload']); |
|
181 | + $payload['content-type'] = $upload->mimeType; |
|
182 | + if (isset($upload->resumable) && $upload->resumable) { |
|
183 | + return self::UPLOAD_RESUMABLE_TYPE; |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + // Allow the developer to override the upload type. |
|
188 | + if (isset($params['uploadType'])) { |
|
189 | + return $params['uploadType']['value']; |
|
190 | + } |
|
191 | + |
|
192 | + $data = isset($params['data']['value']) |
|
193 | + ? $params['data']['value'] : false; |
|
194 | + |
|
195 | + if (false == $data && false == isset($params['file'])) { |
|
196 | + // No upload data available. |
|
197 | + return false; |
|
198 | + } |
|
199 | + |
|
200 | + if (isset($params['file'])) { |
|
201 | + return self::UPLOAD_MEDIA_TYPE; |
|
202 | + } |
|
203 | + |
|
204 | + if (false == $meta) { |
|
205 | + return self::UPLOAD_MEDIA_TYPE; |
|
206 | + } |
|
207 | + |
|
208 | + return self::UPLOAD_MULTIPART_TYPE; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
212 | 212 | public function nextChunk(Google_HttpRequest $req, $chunk=false) { |
213 | - if (false == $this->resumeUri) { |
|
214 | - $this->resumeUri = $this->getResumeUri($req); |
|
215 | - } |
|
216 | - |
|
217 | - if (false == $chunk) { |
|
218 | - $chunk = substr($this->data, $this->progress, $this->chunkSize); |
|
219 | - } |
|
220 | - |
|
221 | - $lastBytePos = $this->progress + strlen($chunk) - 1; |
|
222 | - $headers = array( |
|
223 | - 'content-range' => "bytes $this->progress-$lastBytePos/$this->size", |
|
224 | - 'content-type' => $req->getRequestHeader('content-type'), |
|
225 | - 'content-length' => $this->chunkSize, |
|
226 | - 'expect' => '', |
|
227 | - ); |
|
228 | - |
|
229 | - $httpRequest = new Google_HttpRequest($this->resumeUri, 'PUT', $headers, $chunk); |
|
230 | - $response = Google_Client::$io->authenticatedRequest($httpRequest); |
|
231 | - $code = $response->getResponseHttpCode(); |
|
232 | - if (308 == $code) { |
|
233 | - $range = explode('-', $response->getResponseHeader('range')); |
|
234 | - $this->progress = $range[1] + 1; |
|
235 | - return false; |
|
236 | - } else { |
|
237 | - return Google_REST::decodeHttpResponse($response); |
|
238 | - } |
|
213 | + if (false == $this->resumeUri) { |
|
214 | + $this->resumeUri = $this->getResumeUri($req); |
|
215 | + } |
|
216 | + |
|
217 | + if (false == $chunk) { |
|
218 | + $chunk = substr($this->data, $this->progress, $this->chunkSize); |
|
219 | + } |
|
220 | + |
|
221 | + $lastBytePos = $this->progress + strlen($chunk) - 1; |
|
222 | + $headers = array( |
|
223 | + 'content-range' => "bytes $this->progress-$lastBytePos/$this->size", |
|
224 | + 'content-type' => $req->getRequestHeader('content-type'), |
|
225 | + 'content-length' => $this->chunkSize, |
|
226 | + 'expect' => '', |
|
227 | + ); |
|
228 | + |
|
229 | + $httpRequest = new Google_HttpRequest($this->resumeUri, 'PUT', $headers, $chunk); |
|
230 | + $response = Google_Client::$io->authenticatedRequest($httpRequest); |
|
231 | + $code = $response->getResponseHttpCode(); |
|
232 | + if (308 == $code) { |
|
233 | + $range = explode('-', $response->getResponseHeader('range')); |
|
234 | + $this->progress = $range[1] + 1; |
|
235 | + return false; |
|
236 | + } else { |
|
237 | + return Google_REST::decodeHttpResponse($response); |
|
238 | + } |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | private function getResumeUri(Google_HttpRequest $httpRequest) { |
242 | - $result = null; |
|
243 | - $body = $httpRequest->getPostBody(); |
|
244 | - if ($body) { |
|
245 | - $httpRequest->setRequestHeaders(array( |
|
246 | - 'content-type' => 'application/json; charset=UTF-8', |
|
247 | - 'content-length' => Google_Utils::getStrLen($body), |
|
248 | - 'x-upload-content-type' => $this->mimeType, |
|
249 | - 'x-upload-content-length' => $this->size, |
|
250 | - 'expect' => '', |
|
251 | - )); |
|
252 | - } |
|
253 | - |
|
254 | - $response = Google_Client::$io->makeRequest($httpRequest); |
|
255 | - $location = $response->getResponseHeader('location'); |
|
256 | - $code = $response->getResponseHttpCode(); |
|
257 | - if (200 == $code && true == $location) { |
|
258 | - return $location; |
|
259 | - } |
|
260 | - throw new Google_Exception("Failed to start the resumable upload"); |
|
242 | + $result = null; |
|
243 | + $body = $httpRequest->getPostBody(); |
|
244 | + if ($body) { |
|
245 | + $httpRequest->setRequestHeaders(array( |
|
246 | + 'content-type' => 'application/json; charset=UTF-8', |
|
247 | + 'content-length' => Google_Utils::getStrLen($body), |
|
248 | + 'x-upload-content-type' => $this->mimeType, |
|
249 | + 'x-upload-content-length' => $this->size, |
|
250 | + 'expect' => '', |
|
251 | + )); |
|
252 | + } |
|
253 | + |
|
254 | + $response = Google_Client::$io->makeRequest($httpRequest); |
|
255 | + $location = $response->getResponseHeader('location'); |
|
256 | + $code = $response->getResponseHttpCode(); |
|
257 | + if (200 == $code && true == $location) { |
|
258 | + return $location; |
|
259 | + } |
|
260 | + throw new Google_Exception("Failed to start the resumable upload"); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | \ No newline at end of file |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | * @param bool $chunkSize File will be uploaded in chunks of this many bytes. |
53 | 53 | * only used if resumable=True |
54 | 54 | */ |
55 | - public function __construct($mimeType, $data, $resumable=false, $chunkSize=false) { |
|
55 | + public function __construct($mimeType, $data, $resumable = false, $chunkSize = false) { |
|
56 | 56 | $this->mimeType = $mimeType; |
57 | 57 | $this->data = $data; |
58 | 58 | $this->size = strlen($this->data); |
59 | 59 | $this->resumable = $resumable; |
60 | - if(!$chunkSize) { |
|
60 | + if (!$chunkSize) { |
|
61 | 61 | $chunkSize = 256 * 1024; |
62 | 62 | } |
63 | 63 | $this->chunkSize = $chunkSize; |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | // This is a multipart/related upload. |
126 | 126 | $boundary = isset($params['boundary']['value']) ? $params['boundary']['value'] : mt_rand(); |
127 | 127 | $boundary = str_replace('"', '', $boundary); |
128 | - $payload['content-type'] = 'multipart/related; boundary=' . $boundary; |
|
128 | + $payload['content-type'] = 'multipart/related; boundary='.$boundary; |
|
129 | 129 | $related = "--$boundary\r\n"; |
130 | 130 | $related .= "Content-Type: application/json; charset=UTF-8\r\n"; |
131 | - $related .= "\r\n" . json_encode($meta) . "\r\n"; |
|
131 | + $related .= "\r\n".json_encode($meta)."\r\n"; |
|
132 | 132 | $related .= "--$boundary\r\n"; |
133 | 133 | $related .= "Content-Type: $mimeType\r\n"; |
134 | 134 | $related .= "Content-Transfer-Encoding: base64\r\n"; |
135 | - $related .= "\r\n" . base64_encode($data) . "\r\n"; |
|
135 | + $related .= "\r\n".base64_encode($data)."\r\n"; |
|
136 | 136 | $related .= "--$boundary--"; |
137 | 137 | $payload['postBody'] = $related; |
138 | 138 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | public static function processFileUpload($file, $mime) { |
151 | 151 | if (!$file) return array(); |
152 | 152 | if (substr($file, 0, 1) != '@') { |
153 | - $file = '@' . $file; |
|
153 | + $file = '@'.$file; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // This is a standard file upload with curl. |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | |
212 | - public function nextChunk(Google_HttpRequest $req, $chunk=false) { |
|
212 | + public function nextChunk(Google_HttpRequest $req, $chunk = false) { |
|
213 | 213 | if (false == $this->resumeUri) { |
214 | 214 | $this->resumeUri = $this->getResumeUri($req); |
215 | 215 | } |
@@ -119,9 +119,7 @@ discard block |
||
119 | 119 | // This is a simple media upload. |
120 | 120 | $payload['content-type'] = $mimeType; |
121 | 121 | $payload['postBody'] = $data; |
122 | - } |
|
123 | - |
|
124 | - elseif (self::UPLOAD_MULTIPART_TYPE == $uploadType) { |
|
122 | + } elseif (self::UPLOAD_MULTIPART_TYPE == $uploadType) { |
|
125 | 123 | // This is a multipart/related upload. |
126 | 124 | $boundary = isset($params['boundary']['value']) ? $params['boundary']['value'] : mt_rand(); |
127 | 125 | $boundary = str_replace('"', '', $boundary); |
@@ -148,7 +146,9 @@ discard block |
||
148 | 146 | * @visible For testing. |
149 | 147 | */ |
150 | 148 | public static function processFileUpload($file, $mime) { |
151 | - if (!$file) return array(); |
|
149 | + if (!$file) { |
|
150 | + return array(); |
|
151 | + } |
|
152 | 152 | if (substr($file, 0, 1) != '@') { |
153 | 153 | $file = '@' . $file; |
154 | 154 | } |
@@ -85,7 +85,7 @@ |
||
85 | 85 | /** |
86 | 86 | * Given a variable name, discover its type. |
87 | 87 | * |
88 | - * @param $name |
|
88 | + * @param string $name |
|
89 | 89 | * @param $item |
90 | 90 | * @return object The object from the item. |
91 | 91 | */ |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class Google_Model { |
26 | 26 | public function __construct( /* polymorphic */ ) { |
27 | - if (func_num_args() == 1 && is_array(func_get_arg(0))) { |
|
28 | - // Initialize the model with the array's contents. |
|
29 | - $array = func_get_arg(0); |
|
30 | - $this->mapTypes($array); |
|
31 | - } |
|
27 | + if (func_num_args() == 1 && is_array(func_get_arg(0))) { |
|
28 | + // Initialize the model with the array's contents. |
|
29 | + $array = func_get_arg(0); |
|
30 | + $this->mapTypes($array); |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -38,30 +38,30 @@ discard block |
||
38 | 38 | * @return void |
39 | 39 | */ |
40 | 40 | protected function mapTypes($array) { |
41 | - foreach ($array as $key => $val) { |
|
42 | - $this->$key = $val; |
|
41 | + foreach ($array as $key => $val) { |
|
42 | + $this->$key = $val; |
|
43 | 43 | |
44 | - $keyTypeName = "__$key" . 'Type'; |
|
45 | - $keyDataType = "__$key" . 'DataType'; |
|
46 | - if ($this->useObjects() && property_exists($this, $keyTypeName)) { |
|
47 | - if ($this->isAssociativeArray($val)) { |
|
48 | - if (isset($this->$keyDataType) && 'map' == $this->$keyDataType) { |
|
49 | - foreach($val as $arrayKey => $arrayItem) { |
|
50 | - $val[$arrayKey] = $this->createObjectFromName($keyTypeName, $arrayItem); |
|
51 | - } |
|
52 | - $this->$key = $val; |
|
53 | - } else { |
|
54 | - $this->$key = $this->createObjectFromName($keyTypeName, $val); |
|
55 | - } |
|
56 | - } else if (is_array($val)) { |
|
57 | - $arrayObject = array(); |
|
58 | - foreach ($val as $arrayIndex => $arrayItem) { |
|
59 | - $arrayObject[$arrayIndex] = $this->createObjectFromName($keyTypeName, $arrayItem); |
|
60 | - } |
|
61 | - $this->$key = $arrayObject; |
|
62 | - } |
|
63 | - } |
|
64 | - } |
|
44 | + $keyTypeName = "__$key" . 'Type'; |
|
45 | + $keyDataType = "__$key" . 'DataType'; |
|
46 | + if ($this->useObjects() && property_exists($this, $keyTypeName)) { |
|
47 | + if ($this->isAssociativeArray($val)) { |
|
48 | + if (isset($this->$keyDataType) && 'map' == $this->$keyDataType) { |
|
49 | + foreach($val as $arrayKey => $arrayItem) { |
|
50 | + $val[$arrayKey] = $this->createObjectFromName($keyTypeName, $arrayItem); |
|
51 | + } |
|
52 | + $this->$key = $val; |
|
53 | + } else { |
|
54 | + $this->$key = $this->createObjectFromName($keyTypeName, $val); |
|
55 | + } |
|
56 | + } else if (is_array($val)) { |
|
57 | + $arrayObject = array(); |
|
58 | + foreach ($val as $arrayIndex => $arrayItem) { |
|
59 | + $arrayObject[$arrayIndex] = $this->createObjectFromName($keyTypeName, $arrayItem); |
|
60 | + } |
|
61 | + $this->$key = $arrayObject; |
|
62 | + } |
|
63 | + } |
|
64 | + } |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -70,16 +70,16 @@ discard block |
||
70 | 70 | * @return bool True if the array is associative. |
71 | 71 | */ |
72 | 72 | protected function isAssociativeArray($array) { |
73 | - if (!is_array($array)) { |
|
74 | - return false; |
|
75 | - } |
|
76 | - $keys = array_keys($array); |
|
77 | - foreach($keys as $key) { |
|
78 | - if (is_string($key)) { |
|
79 | - return true; |
|
80 | - } |
|
81 | - } |
|
82 | - return false; |
|
73 | + if (!is_array($array)) { |
|
74 | + return false; |
|
75 | + } |
|
76 | + $keys = array_keys($array); |
|
77 | + foreach($keys as $key) { |
|
78 | + if (is_string($key)) { |
|
79 | + return true; |
|
80 | + } |
|
81 | + } |
|
82 | + return false; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | * @return object The object from the item. |
91 | 91 | */ |
92 | 92 | private function createObjectFromName($name, $item) { |
93 | - $type = $this->$name; |
|
94 | - return new $type($item); |
|
93 | + $type = $this->$name; |
|
94 | + return new $type($item); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | protected function useObjects() { |
98 | - global $apiConfig; |
|
99 | - return (isset($apiConfig['use_objects']) && $apiConfig['use_objects']); |
|
98 | + global $apiConfig; |
|
99 | + return (isset($apiConfig['use_objects']) && $apiConfig['use_objects']); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | * @param string $method Method expecting an array as an argument. |
108 | 108 | */ |
109 | 109 | public function assertIsArray($obj, $type, $method) { |
110 | - if ($obj && !is_array($obj)) { |
|
111 | - throw new Google_Exception("Incorrect parameter type passed to $method(), expected an" |
|
112 | - . " array containing items of type $type."); |
|
113 | - } |
|
110 | + if ($obj && !is_array($obj)) { |
|
111 | + throw new Google_Exception("Incorrect parameter type passed to $method(), expected an" |
|
112 | + . " array containing items of type $type."); |
|
113 | + } |
|
114 | 114 | } |
115 | 115 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class Google_Model { |
26 | 26 | public function __construct( /* polymorphic */ ) { |
27 | - if (func_num_args() == 1 && is_array(func_get_arg(0))) { |
|
27 | + if (func_num_args() == 1 && is_array(func_get_arg(0))) { |
|
28 | 28 | // Initialize the model with the array's contents. |
29 | 29 | $array = func_get_arg(0); |
30 | 30 | $this->mapTypes($array); |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | foreach ($array as $key => $val) { |
42 | 42 | $this->$key = $val; |
43 | 43 | |
44 | - $keyTypeName = "__$key" . 'Type'; |
|
45 | - $keyDataType = "__$key" . 'DataType'; |
|
44 | + $keyTypeName = "__$key".'Type'; |
|
45 | + $keyDataType = "__$key".'DataType'; |
|
46 | 46 | if ($this->useObjects() && property_exists($this, $keyTypeName)) { |
47 | 47 | if ($this->isAssociativeArray($val)) { |
48 | 48 | if (isset($this->$keyDataType) && 'map' == $this->$keyDataType) { |
49 | - foreach($val as $arrayKey => $arrayItem) { |
|
49 | + foreach ($val as $arrayKey => $arrayItem) { |
|
50 | 50 | $val[$arrayKey] = $this->createObjectFromName($keyTypeName, $arrayItem); |
51 | 51 | } |
52 | 52 | $this->$key = $val; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | return false; |
75 | 75 | } |
76 | 76 | $keys = array_keys($array); |
77 | - foreach($keys as $key) { |
|
77 | + foreach ($keys as $key) { |
|
78 | 78 | if (is_string($key)) { |
79 | 79 | return true; |
80 | 80 | } |
@@ -53,6 +53,11 @@ discard block |
||
53 | 53 | /** @var array $methods */ |
54 | 54 | private $methods; |
55 | 55 | |
56 | + /** |
|
57 | + * @param Google_AnalyticsService $service |
|
58 | + * @param string $serviceName |
|
59 | + * @param string $resourceName |
|
60 | + */ |
|
56 | 61 | public function __construct($service, $serviceName, $resourceName, $resource) { |
57 | 62 | $this->service = $service; |
58 | 63 | $this->serviceName = $serviceName; |
@@ -61,7 +66,7 @@ discard block |
||
61 | 66 | } |
62 | 67 | |
63 | 68 | /** |
64 | - * @param $name |
|
69 | + * @param string $name |
|
65 | 70 | * @param $arguments |
66 | 71 | * @return Google_HttpRequest|array |
67 | 72 | * @throws Google_Exception |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | class Google_ServiceResource { |
28 | 28 | // Valid query parameters that work, but don't appear in discovery. |
29 | 29 | private $stackParameters = array( |
30 | - 'alt' => array('type' => 'string', 'location' => 'query'), |
|
31 | - 'boundary' => array('type' => 'string', 'location' => 'query'), |
|
32 | - 'fields' => array('type' => 'string', 'location' => 'query'), |
|
33 | - 'trace' => array('type' => 'string', 'location' => 'query'), |
|
34 | - 'userIp' => array('type' => 'string', 'location' => 'query'), |
|
35 | - 'userip' => array('type' => 'string', 'location' => 'query'), |
|
36 | - 'quotaUser' => array('type' => 'string', 'location' => 'query'), |
|
37 | - 'file' => array('type' => 'complex', 'location' => 'body'), |
|
38 | - 'data' => array('type' => 'string', 'location' => 'body'), |
|
39 | - 'mimeType' => array('type' => 'string', 'location' => 'header'), |
|
40 | - 'uploadType' => array('type' => 'string', 'location' => 'query'), |
|
41 | - 'mediaUpload' => array('type' => 'complex', 'location' => 'query'), |
|
30 | + 'alt' => array('type' => 'string', 'location' => 'query'), |
|
31 | + 'boundary' => array('type' => 'string', 'location' => 'query'), |
|
32 | + 'fields' => array('type' => 'string', 'location' => 'query'), |
|
33 | + 'trace' => array('type' => 'string', 'location' => 'query'), |
|
34 | + 'userIp' => array('type' => 'string', 'location' => 'query'), |
|
35 | + 'userip' => array('type' => 'string', 'location' => 'query'), |
|
36 | + 'quotaUser' => array('type' => 'string', 'location' => 'query'), |
|
37 | + 'file' => array('type' => 'complex', 'location' => 'body'), |
|
38 | + 'data' => array('type' => 'string', 'location' => 'body'), |
|
39 | + 'mimeType' => array('type' => 'string', 'location' => 'header'), |
|
40 | + 'uploadType' => array('type' => 'string', 'location' => 'query'), |
|
41 | + 'mediaUpload' => array('type' => 'complex', 'location' => 'query'), |
|
42 | 42 | ); |
43 | 43 | |
44 | 44 | /** @var Google_Service $service */ |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | private $methods; |
55 | 55 | |
56 | 56 | public function __construct($service, $serviceName, $resourceName, $resource) { |
57 | - $this->service = $service; |
|
58 | - $this->serviceName = $serviceName; |
|
59 | - $this->resourceName = $resourceName; |
|
60 | - $this->methods = isset($resource['methods']) ? $resource['methods'] : array($resourceName => $resource); |
|
57 | + $this->service = $service; |
|
58 | + $this->serviceName = $serviceName; |
|
59 | + $this->resourceName = $resourceName; |
|
60 | + $this->methods = isset($resource['methods']) ? $resource['methods'] : array($resourceName => $resource); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,139 +67,139 @@ discard block |
||
67 | 67 | * @throws Google_Exception |
68 | 68 | */ |
69 | 69 | public function __call($name, $arguments) { |
70 | - if (! isset($this->methods[$name])) { |
|
71 | - throw new Google_Exception("Unknown function: {$this->serviceName}->{$this->resourceName}->{$name}()"); |
|
72 | - } |
|
73 | - $method = $this->methods[$name]; |
|
74 | - $parameters = $arguments[0]; |
|
75 | - |
|
76 | - // postBody is a special case since it's not defined in the discovery document as parameter, but we abuse the param entry for storing it |
|
77 | - $postBody = null; |
|
78 | - if (isset($parameters['postBody'])) { |
|
79 | - if (is_object($parameters['postBody'])) { |
|
80 | - $this->stripNull($parameters['postBody']); |
|
81 | - } |
|
82 | - |
|
83 | - // Some APIs require the postBody to be set under the data key. |
|
84 | - if (is_array($parameters['postBody']) && 'latitude' == $this->serviceName) { |
|
85 | - if (!isset($parameters['postBody']['data'])) { |
|
86 | - $rawBody = $parameters['postBody']; |
|
87 | - unset($parameters['postBody']); |
|
88 | - $parameters['postBody']['data'] = $rawBody; |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - $postBody = is_array($parameters['postBody']) || is_object($parameters['postBody']) |
|
93 | - ? json_encode($parameters['postBody']) |
|
94 | - : $parameters['postBody']; |
|
95 | - unset($parameters['postBody']); |
|
96 | - |
|
97 | - if (isset($parameters['optParams'])) { |
|
98 | - $optParams = $parameters['optParams']; |
|
99 | - unset($parameters['optParams']); |
|
100 | - $parameters = array_merge($parameters, $optParams); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - if (!isset($method['parameters'])) { |
|
105 | - $method['parameters'] = array(); |
|
106 | - } |
|
70 | + if (! isset($this->methods[$name])) { |
|
71 | + throw new Google_Exception("Unknown function: {$this->serviceName}->{$this->resourceName}->{$name}()"); |
|
72 | + } |
|
73 | + $method = $this->methods[$name]; |
|
74 | + $parameters = $arguments[0]; |
|
75 | + |
|
76 | + // postBody is a special case since it's not defined in the discovery document as parameter, but we abuse the param entry for storing it |
|
77 | + $postBody = null; |
|
78 | + if (isset($parameters['postBody'])) { |
|
79 | + if (is_object($parameters['postBody'])) { |
|
80 | + $this->stripNull($parameters['postBody']); |
|
81 | + } |
|
82 | + |
|
83 | + // Some APIs require the postBody to be set under the data key. |
|
84 | + if (is_array($parameters['postBody']) && 'latitude' == $this->serviceName) { |
|
85 | + if (!isset($parameters['postBody']['data'])) { |
|
86 | + $rawBody = $parameters['postBody']; |
|
87 | + unset($parameters['postBody']); |
|
88 | + $parameters['postBody']['data'] = $rawBody; |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + $postBody = is_array($parameters['postBody']) || is_object($parameters['postBody']) |
|
93 | + ? json_encode($parameters['postBody']) |
|
94 | + : $parameters['postBody']; |
|
95 | + unset($parameters['postBody']); |
|
96 | + |
|
97 | + if (isset($parameters['optParams'])) { |
|
98 | + $optParams = $parameters['optParams']; |
|
99 | + unset($parameters['optParams']); |
|
100 | + $parameters = array_merge($parameters, $optParams); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + if (!isset($method['parameters'])) { |
|
105 | + $method['parameters'] = array(); |
|
106 | + } |
|
107 | 107 | |
108 | - $method['parameters'] = array_merge($method['parameters'], $this->stackParameters); |
|
109 | - foreach ($parameters as $key => $val) { |
|
110 | - if ($key != 'postBody' && ! isset($method['parameters'][$key])) { |
|
111 | - throw new Google_Exception("($name) unknown parameter: '$key'"); |
|
112 | - } |
|
113 | - } |
|
114 | - if (isset($method['parameters'])) { |
|
115 | - foreach ($method['parameters'] as $paramName => $paramSpec) { |
|
116 | - if (isset($paramSpec['required']) && $paramSpec['required'] && ! isset($parameters[$paramName])) { |
|
117 | - throw new Google_Exception("($name) missing required param: '$paramName'"); |
|
118 | - } |
|
119 | - if (isset($parameters[$paramName])) { |
|
120 | - $value = $parameters[$paramName]; |
|
121 | - $parameters[$paramName] = $paramSpec; |
|
122 | - $parameters[$paramName]['value'] = $value; |
|
123 | - unset($parameters[$paramName]['required']); |
|
124 | - } else { |
|
125 | - unset($parameters[$paramName]); |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - // Discovery v1.0 puts the canonical method id under the 'id' field. |
|
131 | - if (! isset($method['id'])) { |
|
132 | - $method['id'] = $method['rpcMethod']; |
|
133 | - } |
|
134 | - |
|
135 | - // Discovery v1.0 puts the canonical path under the 'path' field. |
|
136 | - if (! isset($method['path'])) { |
|
137 | - $method['path'] = $method['restPath']; |
|
138 | - } |
|
139 | - |
|
140 | - $servicePath = $this->service->servicePath; |
|
141 | - |
|
142 | - // Process Media Request |
|
143 | - $contentType = false; |
|
144 | - if (isset($method['mediaUpload'])) { |
|
145 | - $media = Google_MediaFileUpload::process($postBody, $parameters); |
|
146 | - if ($media) { |
|
147 | - $contentType = isset($media['content-type']) ? $media['content-type']: null; |
|
148 | - $postBody = isset($media['postBody']) ? $media['postBody'] : null; |
|
149 | - $servicePath = $method['mediaUpload']['protocols']['simple']['path']; |
|
150 | - $method['path'] = ''; |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - $url = Google_REST::createRequestUri($servicePath, $method['path'], $parameters); |
|
155 | - $httpRequest = new Google_HttpRequest($url, $method['httpMethod'], null, $postBody); |
|
156 | - if ($postBody) { |
|
157 | - $contentTypeHeader = array(); |
|
158 | - if (isset($contentType) && $contentType) { |
|
159 | - $contentTypeHeader['content-type'] = $contentType; |
|
160 | - } else { |
|
161 | - $contentTypeHeader['content-type'] = 'application/json; charset=UTF-8'; |
|
162 | - $contentTypeHeader['content-length'] = Google_Utils::getStrLen($postBody); |
|
163 | - } |
|
164 | - $httpRequest->setRequestHeaders($contentTypeHeader); |
|
165 | - } |
|
166 | - |
|
167 | - $httpRequest = Google_Client::$auth->sign($httpRequest); |
|
168 | - if (Google_Client::$useBatch) { |
|
169 | - return $httpRequest; |
|
170 | - } |
|
171 | - |
|
172 | - // Terminate immediately if this is a resumable request. |
|
173 | - if (isset($parameters['uploadType']['value']) |
|
174 | - && Google_MediaFileUpload::UPLOAD_RESUMABLE_TYPE == $parameters['uploadType']['value']) { |
|
175 | - $contentTypeHeader = array(); |
|
176 | - if (isset($contentType) && $contentType) { |
|
177 | - $contentTypeHeader['content-type'] = $contentType; |
|
178 | - } |
|
179 | - $httpRequest->setRequestHeaders($contentTypeHeader); |
|
180 | - if ($postBody) { |
|
181 | - $httpRequest->setPostBody($postBody); |
|
182 | - } |
|
183 | - return $httpRequest; |
|
184 | - } |
|
185 | - |
|
186 | - return Google_REST::execute($httpRequest); |
|
108 | + $method['parameters'] = array_merge($method['parameters'], $this->stackParameters); |
|
109 | + foreach ($parameters as $key => $val) { |
|
110 | + if ($key != 'postBody' && ! isset($method['parameters'][$key])) { |
|
111 | + throw new Google_Exception("($name) unknown parameter: '$key'"); |
|
112 | + } |
|
113 | + } |
|
114 | + if (isset($method['parameters'])) { |
|
115 | + foreach ($method['parameters'] as $paramName => $paramSpec) { |
|
116 | + if (isset($paramSpec['required']) && $paramSpec['required'] && ! isset($parameters[$paramName])) { |
|
117 | + throw new Google_Exception("($name) missing required param: '$paramName'"); |
|
118 | + } |
|
119 | + if (isset($parameters[$paramName])) { |
|
120 | + $value = $parameters[$paramName]; |
|
121 | + $parameters[$paramName] = $paramSpec; |
|
122 | + $parameters[$paramName]['value'] = $value; |
|
123 | + unset($parameters[$paramName]['required']); |
|
124 | + } else { |
|
125 | + unset($parameters[$paramName]); |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + // Discovery v1.0 puts the canonical method id under the 'id' field. |
|
131 | + if (! isset($method['id'])) { |
|
132 | + $method['id'] = $method['rpcMethod']; |
|
133 | + } |
|
134 | + |
|
135 | + // Discovery v1.0 puts the canonical path under the 'path' field. |
|
136 | + if (! isset($method['path'])) { |
|
137 | + $method['path'] = $method['restPath']; |
|
138 | + } |
|
139 | + |
|
140 | + $servicePath = $this->service->servicePath; |
|
141 | + |
|
142 | + // Process Media Request |
|
143 | + $contentType = false; |
|
144 | + if (isset($method['mediaUpload'])) { |
|
145 | + $media = Google_MediaFileUpload::process($postBody, $parameters); |
|
146 | + if ($media) { |
|
147 | + $contentType = isset($media['content-type']) ? $media['content-type']: null; |
|
148 | + $postBody = isset($media['postBody']) ? $media['postBody'] : null; |
|
149 | + $servicePath = $method['mediaUpload']['protocols']['simple']['path']; |
|
150 | + $method['path'] = ''; |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + $url = Google_REST::createRequestUri($servicePath, $method['path'], $parameters); |
|
155 | + $httpRequest = new Google_HttpRequest($url, $method['httpMethod'], null, $postBody); |
|
156 | + if ($postBody) { |
|
157 | + $contentTypeHeader = array(); |
|
158 | + if (isset($contentType) && $contentType) { |
|
159 | + $contentTypeHeader['content-type'] = $contentType; |
|
160 | + } else { |
|
161 | + $contentTypeHeader['content-type'] = 'application/json; charset=UTF-8'; |
|
162 | + $contentTypeHeader['content-length'] = Google_Utils::getStrLen($postBody); |
|
163 | + } |
|
164 | + $httpRequest->setRequestHeaders($contentTypeHeader); |
|
165 | + } |
|
166 | + |
|
167 | + $httpRequest = Google_Client::$auth->sign($httpRequest); |
|
168 | + if (Google_Client::$useBatch) { |
|
169 | + return $httpRequest; |
|
170 | + } |
|
171 | + |
|
172 | + // Terminate immediately if this is a resumable request. |
|
173 | + if (isset($parameters['uploadType']['value']) |
|
174 | + && Google_MediaFileUpload::UPLOAD_RESUMABLE_TYPE == $parameters['uploadType']['value']) { |
|
175 | + $contentTypeHeader = array(); |
|
176 | + if (isset($contentType) && $contentType) { |
|
177 | + $contentTypeHeader['content-type'] = $contentType; |
|
178 | + } |
|
179 | + $httpRequest->setRequestHeaders($contentTypeHeader); |
|
180 | + if ($postBody) { |
|
181 | + $httpRequest->setPostBody($postBody); |
|
182 | + } |
|
183 | + return $httpRequest; |
|
184 | + } |
|
185 | + |
|
186 | + return Google_REST::execute($httpRequest); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | public function useObjects() { |
190 | - global $apiConfig; |
|
191 | - return (isset($apiConfig['use_objects']) && $apiConfig['use_objects']); |
|
190 | + global $apiConfig; |
|
191 | + return (isset($apiConfig['use_objects']) && $apiConfig['use_objects']); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | protected function stripNull(&$o) { |
195 | - $o = (array) $o; |
|
196 | - foreach ($o as $k => $v) { |
|
197 | - if ($v === null || strstr($k, "\0*\0__")) { |
|
198 | - unset($o[$k]); |
|
199 | - } |
|
200 | - elseif (is_object($v) || is_array($v)) { |
|
201 | - $this->stripNull($o[$k]); |
|
202 | - } |
|
203 | - } |
|
195 | + $o = (array) $o; |
|
196 | + foreach ($o as $k => $v) { |
|
197 | + if ($v === null || strstr($k, "\0*\0__")) { |
|
198 | + unset($o[$k]); |
|
199 | + } |
|
200 | + elseif (is_object($v) || is_array($v)) { |
|
201 | + $this->stripNull($o[$k]); |
|
202 | + } |
|
203 | + } |
|
204 | 204 | } |
205 | 205 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @throws Google_Exception |
68 | 68 | */ |
69 | 69 | public function __call($name, $arguments) { |
70 | - if (! isset($this->methods[$name])) { |
|
70 | + if (!isset($this->methods[$name])) { |
|
71 | 71 | throw new Google_Exception("Unknown function: {$this->serviceName}->{$this->resourceName}->{$name}()"); |
72 | 72 | } |
73 | 73 | $method = $this->methods[$name]; |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | |
108 | 108 | $method['parameters'] = array_merge($method['parameters'], $this->stackParameters); |
109 | 109 | foreach ($parameters as $key => $val) { |
110 | - if ($key != 'postBody' && ! isset($method['parameters'][$key])) { |
|
110 | + if ($key != 'postBody' && !isset($method['parameters'][$key])) { |
|
111 | 111 | throw new Google_Exception("($name) unknown parameter: '$key'"); |
112 | 112 | } |
113 | 113 | } |
114 | 114 | if (isset($method['parameters'])) { |
115 | 115 | foreach ($method['parameters'] as $paramName => $paramSpec) { |
116 | - if (isset($paramSpec['required']) && $paramSpec['required'] && ! isset($parameters[$paramName])) { |
|
116 | + if (isset($paramSpec['required']) && $paramSpec['required'] && !isset($parameters[$paramName])) { |
|
117 | 117 | throw new Google_Exception("($name) missing required param: '$paramName'"); |
118 | 118 | } |
119 | 119 | if (isset($parameters[$paramName])) { |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | // Discovery v1.0 puts the canonical method id under the 'id' field. |
131 | - if (! isset($method['id'])) { |
|
131 | + if (!isset($method['id'])) { |
|
132 | 132 | $method['id'] = $method['rpcMethod']; |
133 | 133 | } |
134 | 134 | |
135 | 135 | // Discovery v1.0 puts the canonical path under the 'path' field. |
136 | - if (! isset($method['path'])) { |
|
136 | + if (!isset($method['path'])) { |
|
137 | 137 | $method['path'] = $method['restPath']; |
138 | 138 | } |
139 | 139 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | if (isset($method['mediaUpload'])) { |
145 | 145 | $media = Google_MediaFileUpload::process($postBody, $parameters); |
146 | 146 | if ($media) { |
147 | - $contentType = isset($media['content-type']) ? $media['content-type']: null; |
|
147 | + $contentType = isset($media['content-type']) ? $media['content-type'] : null; |
|
148 | 148 | $postBody = isset($media['postBody']) ? $media['postBody'] : null; |
149 | 149 | $servicePath = $method['mediaUpload']['protocols']['simple']['path']; |
150 | 150 | $method['path'] = ''; |
@@ -196,8 +196,7 @@ |
||
196 | 196 | foreach ($o as $k => $v) { |
197 | 197 | if ($v === null || strstr($k, "\0*\0__")) { |
198 | 198 | unset($o[$k]); |
199 | - } |
|
200 | - elseif (is_object($v) || is_array($v)) { |
|
199 | + } elseif (is_object($v) || is_array($v)) { |
|
201 | 200 | $this->stripNull($o[$k]); |
202 | 201 | } |
203 | 202 | } |