@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | class unlink_directory { |
3 | 3 | |
4 | - function remove_directory( $directory ) { |
|
5 | - if ( isset( $directory ) ) { |
|
6 | - foreach ( glob( "{$directory}/*" ) as $file ) { |
|
7 | - if ( is_dir( $file ) ) { |
|
8 | - $this->remove_directory( $file ); |
|
4 | + function remove_directory($directory) { |
|
5 | + if (isset($directory)) { |
|
6 | + foreach (glob("{$directory}/*") as $file) { |
|
7 | + if (is_dir($file)) { |
|
8 | + $this->remove_directory($file); |
|
9 | 9 | } else { |
10 | - unlink( $file ); |
|
10 | + unlink($file); |
|
11 | 11 | } |
12 | 12 | } |
13 | - rmdir( $directory ); |
|
13 | + rmdir($directory); |
|
14 | 14 | } |
15 | 15 | } |
16 | 16 | } |
17 | 17 | \ No newline at end of file |
@@ -6,195 +6,195 @@ |
||
6 | 6 | |
7 | 7 | class zipper { |
8 | 8 | |
9 | - public function LoadZipFiles($source) { |
|
9 | + public function LoadZipFiles($source) { |
|
10 | 10 | |
11 | - if (!file_exists($source)) { |
|
12 | - return false; |
|
13 | - } |
|
11 | + if (!file_exists($source)) { |
|
12 | + return false; |
|
13 | + } |
|
14 | 14 | |
15 | - $source = str_replace('\\', '/', realpath($source)); |
|
15 | + $source = str_replace('\\', '/', realpath($source)); |
|
16 | 16 | |
17 | - $a = array(); |
|
17 | + $a = array(); |
|
18 | 18 | |
19 | - if (is_dir($source) === true) { |
|
20 | - $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); |
|
19 | + if (is_dir($source) === true) { |
|
20 | + $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); |
|
21 | 21 | |
22 | - foreach ($files as $file) { |
|
23 | - $file = str_replace('\\', '/', $file); |
|
22 | + foreach ($files as $file) { |
|
23 | + $file = str_replace('\\', '/', $file); |
|
24 | 24 | |
25 | - // Ignore "." and ".." folders |
|
26 | - if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) |
|
27 | - continue; |
|
25 | + // Ignore "." and ".." folders |
|
26 | + if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) |
|
27 | + continue; |
|
28 | 28 | |
29 | - $file = realpath($file); |
|
29 | + $file = realpath($file); |
|
30 | 30 | |
31 | - if (is_dir($file) === true) { |
|
32 | - $a[] = array( |
|
33 | - 'type' => 'dir', |
|
34 | - 'source' => str_replace($source . '/', '', $file . '/'), |
|
35 | - 'file' => $file, |
|
36 | - 'size' => 0 |
|
37 | - ); |
|
38 | - } else if (is_file($file) === true) { |
|
39 | - $src = str_replace($source . '/', '', $file); |
|
40 | - $size = filesize($file); |
|
31 | + if (is_dir($file) === true) { |
|
32 | + $a[] = array( |
|
33 | + 'type' => 'dir', |
|
34 | + 'source' => str_replace($source . '/', '', $file . '/'), |
|
35 | + 'file' => $file, |
|
36 | + 'size' => 0 |
|
37 | + ); |
|
38 | + } else if (is_file($file) === true) { |
|
39 | + $src = str_replace($source . '/', '', $file); |
|
40 | + $size = filesize($file); |
|
41 | 41 | |
42 | - $a[] = array( |
|
43 | - 'type' => 'file', |
|
44 | - 'source' => $src, |
|
45 | - 'file' => $file, |
|
46 | - 'size' => false != $size ? $size : 16000 // this is fallback in case no size |
|
47 | - ); |
|
48 | - } |
|
49 | - } |
|
50 | - } |
|
42 | + $a[] = array( |
|
43 | + 'type' => 'file', |
|
44 | + 'source' => $src, |
|
45 | + 'file' => $file, |
|
46 | + 'size' => false != $size ? $size : 16000 // this is fallback in case no size |
|
47 | + ); |
|
48 | + } |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - return $a; |
|
53 | - } |
|
52 | + return $a; |
|
53 | + } |
|
54 | 54 | |
55 | - public function ProcessZip($foldercontent, $folder, $maxsize) { |
|
55 | + public function ProcessZip($foldercontent, $folder, $maxsize) { |
|
56 | 56 | |
57 | - $split = array(); |
|
57 | + $split = array(); |
|
58 | 58 | |
59 | - $splits = 1; |
|
60 | - $t = 0; |
|
59 | + $splits = 1; |
|
60 | + $t = 0; |
|
61 | 61 | |
62 | - // Determine how many zip files to create |
|
63 | - if ( isset( $foldercontent ) ) { |
|
64 | - foreach ($foldercontent as $entry) { |
|
62 | + // Determine how many zip files to create |
|
63 | + if ( isset( $foldercontent ) ) { |
|
64 | + foreach ($foldercontent as $entry) { |
|
65 | 65 | |
66 | - $t = $t + $entry['size']; |
|
66 | + $t = $t + $entry['size']; |
|
67 | 67 | |
68 | - if ($entry['type'] == 'dir') { |
|
69 | - $lastdir = $entry; |
|
70 | - } |
|
68 | + if ($entry['type'] == 'dir') { |
|
69 | + $lastdir = $entry; |
|
70 | + } |
|
71 | 71 | |
72 | - if ($t >= $maxsize) { |
|
73 | - $splits++; |
|
74 | - $t = 0; |
|
75 | - // create lastdir in next archive, in case files still exist |
|
76 | - // even if the next file is not in this archive it doesn't hurt |
|
77 | - if ($lastdir !== '') { |
|
78 | - $split[$splits][] = $lastdir; |
|
79 | - } |
|
80 | - } |
|
72 | + if ($t >= $maxsize) { |
|
73 | + $splits++; |
|
74 | + $t = 0; |
|
75 | + // create lastdir in next archive, in case files still exist |
|
76 | + // even if the next file is not in this archive it doesn't hurt |
|
77 | + if ($lastdir !== '') { |
|
78 | + $split[$splits][] = $lastdir; |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - $split[$splits][] = $entry; |
|
83 | - } |
|
82 | + $split[$splits][] = $entry; |
|
83 | + } |
|
84 | 84 | |
85 | - // delete the $foldercontent array |
|
86 | - unset($foldercontent); |
|
85 | + // delete the $foldercontent array |
|
86 | + unset($foldercontent); |
|
87 | 87 | |
88 | - // Create the folder to put the zip files in |
|
89 | - $date = new DateTime(); |
|
90 | - $tS = $date->format('YmdHis'); |
|
88 | + // Create the folder to put the zip files in |
|
89 | + $date = new DateTime(); |
|
90 | + $tS = $date->format('YmdHis'); |
|
91 | 91 | |
92 | - // Process the splits |
|
93 | - foreach ($split as $idx => $sp) { |
|
92 | + // Process the splits |
|
93 | + foreach ($split as $idx => $sp) { |
|
94 | 94 | |
95 | - // create the zip file |
|
96 | - |
|
97 | - $zip = new ZipArchive(); |
|
98 | - |
|
99 | - $destination = $folder . '.zip'; |
|
100 | - |
|
101 | - if (!$zip->open($destination, ZIPARCHIVE::CREATE)) { |
|
102 | - return false; |
|
103 | - } |
|
104 | - |
|
105 | - $i = 1; |
|
106 | - $dir = ""; |
|
107 | - foreach ($sp as $entry) { |
|
108 | - if ($entry['type'] === 'dir') { |
|
109 | - $dir = explode('\\', $entry['file']); |
|
110 | - $zip->addEmptyDir(end($dir)); |
|
111 | - } else { |
|
112 | - $zip->addFromString(end($dir).'/'.$i.'.jpg', file_get_contents($entry['file'])); |
|
113 | - $i++; |
|
114 | - } |
|
115 | - } |
|
116 | - $zip->close(); |
|
117 | - } |
|
118 | - return array( |
|
119 | - 'splits' => count($split), |
|
120 | - 'foldername' => '' |
|
121 | - ); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - public function getMemoryLimit() { |
|
126 | - $memory_limit = ini_get('memory_limit'); |
|
127 | - |
|
128 | - if (preg_match('/^(\d+)(.)$/', $memory_limit, $matches)) { |
|
129 | - if ($matches[2] == 'M') { |
|
130 | - $memory_limit = $matches[1] * 1024 * 1024; // nnnM -> nnn MB |
|
131 | - } else if ($matches[2] == 'K') { |
|
132 | - $memory_limit = $matches[1] * 1024; // nnnK -> nnn KB |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - return $memory_limit; |
|
137 | - } |
|
138 | - |
|
139 | - public function make_zip($album_download_directory) { |
|
140 | - $zipfilename = ""; |
|
141 | - if ( isset( $album_download_directory) ) { |
|
142 | - //$zipfilename = 'libs/resources'.DIRECTORY_SEPARATOR.'albums'.DIRECTORY_SEPARATOR.'fb-album_'.date("Y-m-d").'_'.date("H-i-s"); |
|
143 | - $zipfilename = 'lib/resources/albums/fb-album_'.date("Y-m-d").'_'.date("H-i-s"); |
|
144 | - |
|
145 | - // name of folder starting from the root of the webserver |
|
146 | - // as in Wordpress /wp-content/themes/ (end on backslash) |
|
147 | - |
|
148 | - |
|
149 | - $folder = dirname($_SERVER['PHP_SELF']).'/'.$album_download_directory; |
|
150 | - |
|
151 | - // Server Root |
|
152 | - $root = $_SERVER["DOCUMENT_ROOT"]; |
|
153 | - |
|
154 | - // source of the folder to unpack |
|
155 | - $sourcedir = $root . $folder; // target directory |
|
156 | - |
|
157 | - // Don't use more than half the memory limit |
|
158 | - $memory_limit = $this->getMemoryLimit(); |
|
159 | - $maxsize = $memory_limit / 2; |
|
160 | - |
|
161 | - // Is zipping possible on the server ? |
|
162 | - if (!extension_loaded('zip')) { |
|
163 | - echo 'Zipping not possible on this server'; |
|
164 | - exit; |
|
165 | - } |
|
166 | - |
|
167 | - // Get the files to zip |
|
168 | - $foldercontent = $this->LoadZipFiles($sourcedir); |
|
169 | - if ($foldercontent === false) { |
|
170 | - echo 'Something went wrong gathering the file entries'; |
|
171 | - exit; |
|
172 | - } |
|
173 | - |
|
174 | - // Process the files to zip |
|
175 | - $zip = $this->ProcessZip($foldercontent, $zipfilename, $maxsize); |
|
176 | - if ($zip === false) { |
|
177 | - echo 'Something went wrong zipping the files'; |
|
178 | - } |
|
95 | + // create the zip file |
|
96 | + |
|
97 | + $zip = new ZipArchive(); |
|
98 | + |
|
99 | + $destination = $folder . '.zip'; |
|
100 | + |
|
101 | + if (!$zip->open($destination, ZIPARCHIVE::CREATE)) { |
|
102 | + return false; |
|
103 | + } |
|
104 | + |
|
105 | + $i = 1; |
|
106 | + $dir = ""; |
|
107 | + foreach ($sp as $entry) { |
|
108 | + if ($entry['type'] === 'dir') { |
|
109 | + $dir = explode('\\', $entry['file']); |
|
110 | + $zip->addEmptyDir(end($dir)); |
|
111 | + } else { |
|
112 | + $zip->addFromString(end($dir).'/'.$i.'.jpg', file_get_contents($entry['file'])); |
|
113 | + $i++; |
|
114 | + } |
|
115 | + } |
|
116 | + $zip->close(); |
|
117 | + } |
|
118 | + return array( |
|
119 | + 'splits' => count($split), |
|
120 | + 'foldername' => '' |
|
121 | + ); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + public function getMemoryLimit() { |
|
126 | + $memory_limit = ini_get('memory_limit'); |
|
127 | + |
|
128 | + if (preg_match('/^(\d+)(.)$/', $memory_limit, $matches)) { |
|
129 | + if ($matches[2] == 'M') { |
|
130 | + $memory_limit = $matches[1] * 1024 * 1024; // nnnM -> nnn MB |
|
131 | + } else if ($matches[2] == 'K') { |
|
132 | + $memory_limit = $matches[1] * 1024; // nnnK -> nnn KB |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + return $memory_limit; |
|
137 | + } |
|
138 | + |
|
139 | + public function make_zip($album_download_directory) { |
|
140 | + $zipfilename = ""; |
|
141 | + if ( isset( $album_download_directory) ) { |
|
142 | + //$zipfilename = 'libs/resources'.DIRECTORY_SEPARATOR.'albums'.DIRECTORY_SEPARATOR.'fb-album_'.date("Y-m-d").'_'.date("H-i-s"); |
|
143 | + $zipfilename = 'lib/resources/albums/fb-album_'.date("Y-m-d").'_'.date("H-i-s"); |
|
144 | + |
|
145 | + // name of folder starting from the root of the webserver |
|
146 | + // as in Wordpress /wp-content/themes/ (end on backslash) |
|
147 | + |
|
148 | + |
|
149 | + $folder = dirname($_SERVER['PHP_SELF']).'/'.$album_download_directory; |
|
150 | + |
|
151 | + // Server Root |
|
152 | + $root = $_SERVER["DOCUMENT_ROOT"]; |
|
153 | + |
|
154 | + // source of the folder to unpack |
|
155 | + $sourcedir = $root . $folder; // target directory |
|
156 | + |
|
157 | + // Don't use more than half the memory limit |
|
158 | + $memory_limit = $this->getMemoryLimit(); |
|
159 | + $maxsize = $memory_limit / 2; |
|
160 | + |
|
161 | + // Is zipping possible on the server ? |
|
162 | + if (!extension_loaded('zip')) { |
|
163 | + echo 'Zipping not possible on this server'; |
|
164 | + exit; |
|
165 | + } |
|
166 | + |
|
167 | + // Get the files to zip |
|
168 | + $foldercontent = $this->LoadZipFiles($sourcedir); |
|
169 | + if ($foldercontent === false) { |
|
170 | + echo 'Something went wrong gathering the file entries'; |
|
171 | + exit; |
|
172 | + } |
|
173 | + |
|
174 | + // Process the files to zip |
|
175 | + $zip = $this->ProcessZip($foldercontent, $zipfilename, $maxsize); |
|
176 | + if ($zip === false) { |
|
177 | + echo 'Something went wrong zipping the files'; |
|
178 | + } |
|
179 | 179 | |
180 | - // clear the stat cache (created by filesize command) |
|
181 | - clearstatcache(); |
|
180 | + // clear the stat cache (created by filesize command) |
|
181 | + clearstatcache(); |
|
182 | 182 | |
183 | - require_once( 'unlink_directory.php' ); |
|
184 | - $unlink_directory = new unlink_directory(); |
|
185 | - $unlink_directory->remove_directory( $album_download_directory ); |
|
186 | - } |
|
187 | - return $zipfilename; |
|
188 | - } |
|
189 | - |
|
190 | - public function get_zip( $album_download_directory ) { |
|
191 | - $response = '<span style="color: #ffffff;">Sorry due to some reasons albums cannot be downloaded.</span>'; |
|
192 | - if ( isset( $album_download_directory ) ) { |
|
193 | - $zip_folder = $this->make_zip( $album_download_directory ); |
|
194 | - if ( !empty( $zip_folder ) ) { |
|
195 | - $response = '<a href="' . $zip_folder . '.zip" id="download-link" class="btn btn-success link-buttons-border-color" >Download Zip Folder</a>'; |
|
196 | - } |
|
197 | - } |
|
198 | - return $response; |
|
199 | - } |
|
183 | + require_once( 'unlink_directory.php' ); |
|
184 | + $unlink_directory = new unlink_directory(); |
|
185 | + $unlink_directory->remove_directory( $album_download_directory ); |
|
186 | + } |
|
187 | + return $zipfilename; |
|
188 | + } |
|
189 | + |
|
190 | + public function get_zip( $album_download_directory ) { |
|
191 | + $response = '<span style="color: #ffffff;">Sorry due to some reasons albums cannot be downloaded.</span>'; |
|
192 | + if ( isset( $album_download_directory ) ) { |
|
193 | + $zip_folder = $this->make_zip( $album_download_directory ); |
|
194 | + if ( !empty( $zip_folder ) ) { |
|
195 | + $response = '<a href="' . $zip_folder . '.zip" id="download-link" class="btn btn-success link-buttons-border-color" >Download Zip Folder</a>'; |
|
196 | + } |
|
197 | + } |
|
198 | + return $response; |
|
199 | + } |
|
200 | 200 | } |
201 | 201 | \ No newline at end of file |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $t = 0; |
61 | 61 | |
62 | 62 | // Determine how many zip files to create |
63 | - if ( isset( $foldercontent ) ) { |
|
63 | + if (isset($foldercontent)) { |
|
64 | 64 | foreach ($foldercontent as $entry) { |
65 | 65 | |
66 | 66 | $t = $t + $entry['size']; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $dir = explode('\\', $entry['file']); |
110 | 110 | $zip->addEmptyDir(end($dir)); |
111 | 111 | } else { |
112 | - $zip->addFromString(end($dir).'/'.$i.'.jpg', file_get_contents($entry['file'])); |
|
112 | + $zip->addFromString(end($dir) . '/' . $i . '.jpg', file_get_contents($entry['file'])); |
|
113 | 113 | $i++; |
114 | 114 | } |
115 | 115 | } |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | |
139 | 139 | public function make_zip($album_download_directory) { |
140 | 140 | $zipfilename = ""; |
141 | - if ( isset( $album_download_directory) ) { |
|
141 | + if (isset($album_download_directory)) { |
|
142 | 142 | //$zipfilename = 'libs/resources'.DIRECTORY_SEPARATOR.'albums'.DIRECTORY_SEPARATOR.'fb-album_'.date("Y-m-d").'_'.date("H-i-s"); |
143 | - $zipfilename = 'lib/resources/albums/fb-album_'.date("Y-m-d").'_'.date("H-i-s"); |
|
143 | + $zipfilename = 'lib/resources/albums/fb-album_' . date("Y-m-d") . '_' . date("H-i-s"); |
|
144 | 144 | |
145 | 145 | // name of folder starting from the root of the webserver |
146 | 146 | // as in Wordpress /wp-content/themes/ (end on backslash) |
147 | 147 | |
148 | 148 | |
149 | - $folder = dirname($_SERVER['PHP_SELF']).'/'.$album_download_directory; |
|
149 | + $folder = dirname($_SERVER['PHP_SELF']) . '/' . $album_download_directory; |
|
150 | 150 | |
151 | 151 | // Server Root |
152 | 152 | $root = $_SERVER["DOCUMENT_ROOT"]; |
@@ -180,18 +180,18 @@ discard block |
||
180 | 180 | // clear the stat cache (created by filesize command) |
181 | 181 | clearstatcache(); |
182 | 182 | |
183 | - require_once( 'unlink_directory.php' ); |
|
183 | + require_once('unlink_directory.php'); |
|
184 | 184 | $unlink_directory = new unlink_directory(); |
185 | - $unlink_directory->remove_directory( $album_download_directory ); |
|
185 | + $unlink_directory->remove_directory($album_download_directory); |
|
186 | 186 | } |
187 | 187 | return $zipfilename; |
188 | 188 | } |
189 | 189 | |
190 | - public function get_zip( $album_download_directory ) { |
|
190 | + public function get_zip($album_download_directory) { |
|
191 | 191 | $response = '<span style="color: #ffffff;">Sorry due to some reasons albums cannot be downloaded.</span>'; |
192 | - if ( isset( $album_download_directory ) ) { |
|
193 | - $zip_folder = $this->make_zip( $album_download_directory ); |
|
194 | - if ( !empty( $zip_folder ) ) { |
|
192 | + if (isset($album_download_directory)) { |
|
193 | + $zip_folder = $this->make_zip($album_download_directory); |
|
194 | + if (!empty($zip_folder)) { |
|
195 | 195 | $response = '<a href="' . $zip_folder . '.zip" id="download-link" class="btn btn-success link-buttons-border-color" >Download Zip Folder</a>'; |
196 | 196 | } |
197 | 197 | } |
@@ -23,8 +23,9 @@ |
||
23 | 23 | $file = str_replace('\\', '/', $file); |
24 | 24 | |
25 | 25 | // Ignore "." and ".." folders |
26 | - if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) |
|
27 | - continue; |
|
26 | + if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) { |
|
27 | + continue; |
|
28 | + } |
|
28 | 29 | |
29 | 30 | $file = realpath($file); |
30 | 31 |
@@ -3,13 +3,13 @@ |
||
3 | 3 | require_once 'appconfig.php'; |
4 | 4 | |
5 | 5 | $fb = new Facebook\Facebook([ |
6 | - 'app_id' => $appId, // variable with Facebook App ID |
|
7 | - 'app_secret' => $appSecret, |
|
8 | - 'default_graph_version' => 'v3.3', |
|
9 | - ]); |
|
10 | - $helper = $fb->getRedirectLoginHelper(); |
|
11 | - $permissions = ['email','user_photos','user_videos','user_posts','user_link','user_status','user_link']; // Optional permissions |
|
12 | - $loginUrl = $helper->getLoginUrl($CallbackUrl,$permissions); |
|
6 | + 'app_id' => $appId, // variable with Facebook App ID |
|
7 | + 'app_secret' => $appSecret, |
|
8 | + 'default_graph_version' => 'v3.3', |
|
9 | + ]); |
|
10 | + $helper = $fb->getRedirectLoginHelper(); |
|
11 | + $permissions = ['email','user_photos','user_videos','user_posts','user_link','user_status','user_link']; // Optional permissions |
|
12 | + $loginUrl = $helper->getLoginUrl($CallbackUrl,$permissions); |
|
13 | 13 | |
14 | - echo "<h3> Connect Clicking Below Facebook Icon Using Your Facebook Account.<h3>"; |
|
15 | - echo '<a href="' .htmlspecialchars($loginUrl).'"><img alt="Login With Facebook" src="images/fb_icon.png"></a>'; |
|
16 | 14 | \ No newline at end of file |
15 | + echo "<h3> Connect Clicking Below Facebook Icon Using Your Facebook Account.<h3>"; |
|
16 | + echo '<a href="' .htmlspecialchars($loginUrl).'"><img alt="Login With Facebook" src="images/fb_icon.png"></a>'; |
|
17 | 17 | \ No newline at end of file |
@@ -8,8 +8,8 @@ |
||
8 | 8 | 'default_graph_version' => 'v3.3', |
9 | 9 | ]); |
10 | 10 | $helper = $fb->getRedirectLoginHelper(); |
11 | - $permissions = ['email','user_photos','user_videos','user_posts','user_link','user_status','user_link']; // Optional permissions |
|
12 | - $loginUrl = $helper->getLoginUrl($CallbackUrl,$permissions); |
|
11 | + $permissions = ['email', 'user_photos', 'user_videos', 'user_posts', 'user_link', 'user_status', 'user_link']; // Optional permissions |
|
12 | + $loginUrl = $helper->getLoginUrl($CallbackUrl, $permissions); |
|
13 | 13 | |
14 | 14 | echo "<h3> Connect Clicking Below Facebook Icon Using Your Facebook Account.<h3>"; |
15 | - echo '<a href="' .htmlspecialchars($loginUrl).'"><img alt="Login With Facebook" src="images/fb_icon.png"></a>'; |
|
16 | 15 | \ No newline at end of file |
16 | + echo '<a href="' . htmlspecialchars($loginUrl) . '"><img alt="Login With Facebook" src="images/fb_icon.png"></a>'; |
|
17 | 17 | \ No newline at end of file |
@@ -9,10 +9,10 @@ |
||
9 | 9 | session_start(); |
10 | 10 | require_once 'appconfig.php'; |
11 | 11 | $fb = new Facebook\Facebook([ |
12 | - 'app_id' => $appId, // variable with Facebook App ID |
|
13 | - 'app_secret' => $appSecret, |
|
14 | - 'default_graph_version' => 'v3.3', |
|
15 | - ]); |
|
12 | + 'app_id' => $appId, // variable with Facebook App ID |
|
13 | + 'app_secret' => $appSecret, |
|
14 | + 'default_graph_version' => 'v3.3', |
|
15 | + ]); |
|
16 | 16 | $helper = $fb->getRedirectLoginHelper(); |
17 | 17 | try { |
18 | 18 | $accessToken = $helper->getAccessToken(); |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | $helper = $fb->getRedirectLoginHelper(); |
17 | 17 | try { |
18 | 18 | $accessToken = $helper->getAccessToken(); |
19 | -} catch(Facebook\Exceptions\FacebookResponseException $e) { |
|
19 | +} catch (Facebook\Exceptions\FacebookResponseException $e) { |
|
20 | 20 | // When Graph returns an error |
21 | 21 | echo 'Graph returned an error: ' . $e->getMessage(); |
22 | 22 | exit; |
23 | -} catch(Facebook\Exceptions\FacebookSDKException $e) { |
|
23 | +} catch (Facebook\Exceptions\FacebookSDKException $e) { |
|
24 | 24 | // When validation fails or other local issues |
25 | 25 | echo 'Facebook SDK returned an error: ' . $e->getMessage(); |
26 | 26 | exit; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | // If you know the user ID this access token belongs to, you can validate it here |
53 | 53 | //$tokenMetadata->validateUserId('123'); |
54 | 54 | $tokenMetadata->validateExpiration(); |
55 | -if (! $accessToken->isLongLived()) { |
|
55 | +if (!$accessToken->isLongLived()) { |
|
56 | 56 | // Exchanges a short-lived access token for a long-lived one |
57 | 57 | try { |
58 | 58 | $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); |
@@ -21,176 +21,176 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class Google_Utils_UriTemplate |
23 | 23 | { |
24 | - const TYPE_MAP = "1"; |
|
25 | - const TYPE_LIST = "2"; |
|
26 | - const TYPE_SCALAR = "4"; |
|
24 | + const TYPE_MAP = "1"; |
|
25 | + const TYPE_LIST = "2"; |
|
26 | + const TYPE_SCALAR = "4"; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var $operators array |
|
30 | - * These are valid at the start of a template block to |
|
31 | - * modify the way in which the variables inside are |
|
32 | - * processed. |
|
33 | - */ |
|
34 | - private $operators = array( |
|
35 | - "+" => "reserved", |
|
36 | - "/" => "segments", |
|
37 | - "." => "dotprefix", |
|
38 | - "#" => "fragment", |
|
39 | - ";" => "semicolon", |
|
40 | - "?" => "form", |
|
41 | - "&" => "continuation" |
|
42 | - ); |
|
28 | + /** |
|
29 | + * @var $operators array |
|
30 | + * These are valid at the start of a template block to |
|
31 | + * modify the way in which the variables inside are |
|
32 | + * processed. |
|
33 | + */ |
|
34 | + private $operators = array( |
|
35 | + "+" => "reserved", |
|
36 | + "/" => "segments", |
|
37 | + "." => "dotprefix", |
|
38 | + "#" => "fragment", |
|
39 | + ";" => "semicolon", |
|
40 | + "?" => "form", |
|
41 | + "&" => "continuation" |
|
42 | + ); |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var reserved array |
|
46 | - * These are the characters which should not be URL encoded in reserved |
|
47 | - * strings. |
|
48 | - */ |
|
49 | - private $reserved = array( |
|
50 | - "=", ",", "!", "@", "|", ":", "/", "?", "#", |
|
51 | - "[", "]",'$', "&", "'", "(", ")", "*", "+", ";" |
|
52 | - ); |
|
53 | - private $reservedEncoded = array( |
|
44 | + /** |
|
45 | + * @var reserved array |
|
46 | + * These are the characters which should not be URL encoded in reserved |
|
47 | + * strings. |
|
48 | + */ |
|
49 | + private $reserved = array( |
|
50 | + "=", ",", "!", "@", "|", ":", "/", "?", "#", |
|
51 | + "[", "]",'$', "&", "'", "(", ")", "*", "+", ";" |
|
52 | + ); |
|
53 | + private $reservedEncoded = array( |
|
54 | 54 | "%3D", "%2C", "%21", "%40", "%7C", "%3A", "%2F", "%3F", |
55 | 55 | "%23", "%5B", "%5D", "%24", "%26", "%27", "%28", "%29", |
56 | 56 | "%2A", "%2B", "%3B" |
57 | - ); |
|
57 | + ); |
|
58 | 58 | |
59 | - public function parse($string, array $parameters) |
|
60 | - { |
|
59 | + public function parse($string, array $parameters) |
|
60 | + { |
|
61 | 61 | return $this->resolveNextSection($string, $parameters); |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * This function finds the first matching {...} block and |
|
66 | - * executes the replacement. It then calls itself to find |
|
67 | - * subsequent blocks, if any. |
|
68 | - */ |
|
69 | - private function resolveNextSection($string, $parameters) |
|
70 | - { |
|
64 | + /** |
|
65 | + * This function finds the first matching {...} block and |
|
66 | + * executes the replacement. It then calls itself to find |
|
67 | + * subsequent blocks, if any. |
|
68 | + */ |
|
69 | + private function resolveNextSection($string, $parameters) |
|
70 | + { |
|
71 | 71 | $start = strpos($string, "{"); |
72 | 72 | if ($start === false) { |
73 | - return $string; |
|
73 | + return $string; |
|
74 | 74 | } |
75 | 75 | $end = strpos($string, "}"); |
76 | 76 | if ($end === false) { |
77 | - return $string; |
|
77 | + return $string; |
|
78 | 78 | } |
79 | 79 | $string = $this->replace($string, $start, $end, $parameters); |
80 | 80 | return $this->resolveNextSection($string, $parameters); |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - private function replace($string, $start, $end, $parameters) |
|
84 | - { |
|
83 | + private function replace($string, $start, $end, $parameters) |
|
84 | + { |
|
85 | 85 | // We know a data block will have {} round it, so we can strip that. |
86 | 86 | $data = substr($string, $start + 1, $end - $start - 1); |
87 | 87 | |
88 | 88 | // If the first character is one of the reserved operators, it effects |
89 | 89 | // the processing of the stream. |
90 | 90 | if (isset($this->operators[$data[0]])) { |
91 | - $op = $this->operators[$data[0]]; |
|
92 | - $data = substr($data, 1); |
|
93 | - $prefix = ""; |
|
94 | - $prefix_on_missing = false; |
|
91 | + $op = $this->operators[$data[0]]; |
|
92 | + $data = substr($data, 1); |
|
93 | + $prefix = ""; |
|
94 | + $prefix_on_missing = false; |
|
95 | 95 | |
96 | - switch ($op) { |
|
96 | + switch ($op) { |
|
97 | 97 | case "reserved": |
98 | 98 | // Reserved means certain characters should not be URL encoded |
99 | 99 | $data = $this->replaceVars($data, $parameters, ",", null, true); |
100 | - break; |
|
100 | + break; |
|
101 | 101 | case "fragment": |
102 | 102 | // Comma separated with fragment prefix. Bare values only. |
103 | 103 | $prefix = "#"; |
104 | - $prefix_on_missing = true; |
|
105 | - $data = $this->replaceVars($data, $parameters, ",", null, true); |
|
106 | - break; |
|
104 | + $prefix_on_missing = true; |
|
105 | + $data = $this->replaceVars($data, $parameters, ",", null, true); |
|
106 | + break; |
|
107 | 107 | case "segments": |
108 | 108 | // Slash separated data. Bare values only. |
109 | 109 | $prefix = "/"; |
110 | - $data =$this->replaceVars($data, $parameters, "/"); |
|
111 | - break; |
|
110 | + $data =$this->replaceVars($data, $parameters, "/"); |
|
111 | + break; |
|
112 | 112 | case "dotprefix": |
113 | 113 | // Dot separated data. Bare values only. |
114 | 114 | $prefix = "."; |
115 | - $prefix_on_missing = true; |
|
116 | - $data = $this->replaceVars($data, $parameters, "."); |
|
117 | - break; |
|
115 | + $prefix_on_missing = true; |
|
116 | + $data = $this->replaceVars($data, $parameters, "."); |
|
117 | + break; |
|
118 | 118 | case "semicolon": |
119 | 119 | // Semicolon prefixed and separated. Uses the key name |
120 | 120 | $prefix = ";"; |
121 | - $data = $this->replaceVars($data, $parameters, ";", "=", false, true, false); |
|
122 | - break; |
|
121 | + $data = $this->replaceVars($data, $parameters, ";", "=", false, true, false); |
|
122 | + break; |
|
123 | 123 | case "form": |
124 | 124 | // Standard URL format. Uses the key name |
125 | 125 | $prefix = "?"; |
126 | - $data = $this->replaceVars($data, $parameters, "&", "="); |
|
127 | - break; |
|
126 | + $data = $this->replaceVars($data, $parameters, "&", "="); |
|
127 | + break; |
|
128 | 128 | case "continuation": |
129 | 129 | // Standard URL, but with leading ampersand. Uses key name. |
130 | 130 | $prefix = "&"; |
131 | - $data = $this->replaceVars($data, $parameters, "&", "="); |
|
132 | - break; |
|
133 | - } |
|
131 | + $data = $this->replaceVars($data, $parameters, "&", "="); |
|
132 | + break; |
|
133 | + } |
|
134 | 134 | |
135 | - // Add the initial prefix character if data is valid. |
|
136 | - if ($data || ($data !== false && $prefix_on_missing)) { |
|
135 | + // Add the initial prefix character if data is valid. |
|
136 | + if ($data || ($data !== false && $prefix_on_missing)) { |
|
137 | 137 | $data = $prefix . $data; |
138 | - } |
|
138 | + } |
|
139 | 139 | |
140 | 140 | } else { |
141 | - // If no operator we replace with the defaults. |
|
142 | - $data = $this->replaceVars($data, $parameters); |
|
141 | + // If no operator we replace with the defaults. |
|
142 | + $data = $this->replaceVars($data, $parameters); |
|
143 | 143 | } |
144 | 144 | // This is chops out the {...} and replaces with the new section. |
145 | 145 | return substr($string, 0, $start) . $data . substr($string, $end + 1); |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | - private function replaceVars( |
|
149 | - $section, |
|
150 | - $parameters, |
|
151 | - $sep = ",", |
|
152 | - $combine = null, |
|
153 | - $reserved = false, |
|
154 | - $tag_empty = false, |
|
155 | - $combine_on_empty = true |
|
156 | - ) { |
|
148 | + private function replaceVars( |
|
149 | + $section, |
|
150 | + $parameters, |
|
151 | + $sep = ",", |
|
152 | + $combine = null, |
|
153 | + $reserved = false, |
|
154 | + $tag_empty = false, |
|
155 | + $combine_on_empty = true |
|
156 | + ) { |
|
157 | 157 | if (strpos($section, ",") === false) { |
158 | - // If we only have a single value, we can immediately process. |
|
159 | - return $this->combine( |
|
160 | - $section, |
|
161 | - $parameters, |
|
162 | - $sep, |
|
163 | - $combine, |
|
164 | - $reserved, |
|
165 | - $tag_empty, |
|
166 | - $combine_on_empty |
|
167 | - ); |
|
158 | + // If we only have a single value, we can immediately process. |
|
159 | + return $this->combine( |
|
160 | + $section, |
|
161 | + $parameters, |
|
162 | + $sep, |
|
163 | + $combine, |
|
164 | + $reserved, |
|
165 | + $tag_empty, |
|
166 | + $combine_on_empty |
|
167 | + ); |
|
168 | 168 | } else { |
169 | - // If we have multiple values, we need to split and loop over them. |
|
170 | - // Each is treated individually, then glued together with the |
|
171 | - // separator character. |
|
172 | - $vars = explode(",", $section); |
|
173 | - return $this->combineList( |
|
174 | - $vars, |
|
175 | - $sep, |
|
176 | - $parameters, |
|
177 | - $combine, |
|
178 | - $reserved, |
|
179 | - false, // Never emit empty strings in multi-param replacements |
|
180 | - $combine_on_empty |
|
181 | - ); |
|
169 | + // If we have multiple values, we need to split and loop over them. |
|
170 | + // Each is treated individually, then glued together with the |
|
171 | + // separator character. |
|
172 | + $vars = explode(",", $section); |
|
173 | + return $this->combineList( |
|
174 | + $vars, |
|
175 | + $sep, |
|
176 | + $parameters, |
|
177 | + $combine, |
|
178 | + $reserved, |
|
179 | + false, // Never emit empty strings in multi-param replacements |
|
180 | + $combine_on_empty |
|
181 | + ); |
|
182 | + } |
|
182 | 183 | } |
183 | - } |
|
184 | 184 | |
185 | - public function combine( |
|
186 | - $key, |
|
187 | - $parameters, |
|
188 | - $sep, |
|
189 | - $combine, |
|
190 | - $reserved, |
|
191 | - $tag_empty, |
|
192 | - $combine_on_empty |
|
193 | - ) { |
|
185 | + public function combine( |
|
186 | + $key, |
|
187 | + $parameters, |
|
188 | + $sep, |
|
189 | + $combine, |
|
190 | + $reserved, |
|
191 | + $tag_empty, |
|
192 | + $combine_on_empty |
|
193 | + ) { |
|
194 | 194 | $length = false; |
195 | 195 | $explode = false; |
196 | 196 | $skip_final_combine = false; |
@@ -198,136 +198,136 @@ discard block |
||
198 | 198 | |
199 | 199 | // Check for length restriction. |
200 | 200 | if (strpos($key, ":") !== false) { |
201 | - list($key, $length) = explode(":", $key); |
|
201 | + list($key, $length) = explode(":", $key); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | // Check for explode parameter. |
205 | 205 | if ($key[strlen($key) - 1] == "*") { |
206 | - $explode = true; |
|
207 | - $key = substr($key, 0, -1); |
|
208 | - $skip_final_combine = true; |
|
206 | + $explode = true; |
|
207 | + $key = substr($key, 0, -1); |
|
208 | + $skip_final_combine = true; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | // Define the list separator. |
212 | 212 | $list_sep = $explode ? $sep : ","; |
213 | 213 | |
214 | 214 | if (isset($parameters[$key])) { |
215 | - $data_type = $this->getDataType($parameters[$key]); |
|
216 | - switch ($data_type) { |
|
215 | + $data_type = $this->getDataType($parameters[$key]); |
|
216 | + switch ($data_type) { |
|
217 | 217 | case self::TYPE_SCALAR: |
218 | 218 | $value = $this->getValue($parameters[$key], $length); |
219 | - break; |
|
219 | + break; |
|
220 | 220 | case self::TYPE_LIST: |
221 | 221 | $values = array(); |
222 | - foreach ($parameters[$key] as $pkey => $pvalue) { |
|
222 | + foreach ($parameters[$key] as $pkey => $pvalue) { |
|
223 | 223 | $pvalue = $this->getValue($pvalue, $length); |
224 | 224 | if ($combine && $explode) { |
225 | - $values[$pkey] = $key . $combine . $pvalue; |
|
225 | + $values[$pkey] = $key . $combine . $pvalue; |
|
226 | 226 | } else { |
227 | - $values[$pkey] = $pvalue; |
|
227 | + $values[$pkey] = $pvalue; |
|
228 | + } |
|
228 | 229 | } |
229 | - } |
|
230 | - $value = implode($list_sep, $values); |
|
231 | - if ($value == '') { |
|
230 | + $value = implode($list_sep, $values); |
|
231 | + if ($value == '') { |
|
232 | 232 | return ''; |
233 | - } |
|
234 | - break; |
|
233 | + } |
|
234 | + break; |
|
235 | 235 | case self::TYPE_MAP: |
236 | 236 | $values = array(); |
237 | - foreach ($parameters[$key] as $pkey => $pvalue) { |
|
237 | + foreach ($parameters[$key] as $pkey => $pvalue) { |
|
238 | 238 | $pvalue = $this->getValue($pvalue, $length); |
239 | 239 | if ($explode) { |
240 | - $pkey = $this->getValue($pkey, $length); |
|
241 | - $values[] = $pkey . "=" . $pvalue; // Explode triggers = combine. |
|
240 | + $pkey = $this->getValue($pkey, $length); |
|
241 | + $values[] = $pkey . "=" . $pvalue; // Explode triggers = combine. |
|
242 | 242 | } else { |
243 | - $values[] = $pkey; |
|
244 | - $values[] = $pvalue; |
|
243 | + $values[] = $pkey; |
|
244 | + $values[] = $pvalue; |
|
245 | 245 | } |
246 | - } |
|
247 | - $value = implode($list_sep, $values); |
|
248 | - if ($value == '') { |
|
246 | + } |
|
247 | + $value = implode($list_sep, $values); |
|
248 | + if ($value == '') { |
|
249 | 249 | return false; |
250 | - } |
|
251 | - break; |
|
252 | - } |
|
250 | + } |
|
251 | + break; |
|
252 | + } |
|
253 | 253 | } else if ($tag_empty) { |
254 | - // If we are just indicating empty values with their key name, return that. |
|
255 | - return $key; |
|
254 | + // If we are just indicating empty values with their key name, return that. |
|
255 | + return $key; |
|
256 | 256 | } else { |
257 | - // Otherwise we can skip this variable due to not being defined. |
|
258 | - return false; |
|
257 | + // Otherwise we can skip this variable due to not being defined. |
|
258 | + return false; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | if ($reserved) { |
262 | - $value = str_replace($this->reservedEncoded, $this->reserved, $value); |
|
262 | + $value = str_replace($this->reservedEncoded, $this->reserved, $value); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | // If we do not need to include the key name, we just return the raw |
266 | 266 | // value. |
267 | 267 | if (!$combine || $skip_final_combine) { |
268 | - return $value; |
|
268 | + return $value; |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | // Else we combine the key name: foo=bar, if value is not the empty string. |
272 | 272 | return $key . ($value != '' || $combine_on_empty ? $combine . $value : ''); |
273 | - } |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * Return the type of a passed in value |
|
277 | - */ |
|
278 | - private function getDataType($data) |
|
279 | - { |
|
275 | + /** |
|
276 | + * Return the type of a passed in value |
|
277 | + */ |
|
278 | + private function getDataType($data) |
|
279 | + { |
|
280 | 280 | if (is_array($data)) { |
281 | - reset($data); |
|
282 | - if (key($data) !== 0) { |
|
281 | + reset($data); |
|
282 | + if (key($data) !== 0) { |
|
283 | 283 | return self::TYPE_MAP; |
284 | - } |
|
285 | - return self::TYPE_LIST; |
|
284 | + } |
|
285 | + return self::TYPE_LIST; |
|
286 | 286 | } |
287 | 287 | return self::TYPE_SCALAR; |
288 | - } |
|
288 | + } |
|
289 | 289 | |
290 | - /** |
|
291 | - * Utility function that merges multiple combine calls |
|
292 | - * for multi-key templates. |
|
293 | - */ |
|
294 | - private function combineList( |
|
295 | - $vars, |
|
296 | - $sep, |
|
297 | - $parameters, |
|
298 | - $combine, |
|
299 | - $reserved, |
|
300 | - $tag_empty, |
|
301 | - $combine_on_empty |
|
302 | - ) { |
|
290 | + /** |
|
291 | + * Utility function that merges multiple combine calls |
|
292 | + * for multi-key templates. |
|
293 | + */ |
|
294 | + private function combineList( |
|
295 | + $vars, |
|
296 | + $sep, |
|
297 | + $parameters, |
|
298 | + $combine, |
|
299 | + $reserved, |
|
300 | + $tag_empty, |
|
301 | + $combine_on_empty |
|
302 | + ) { |
|
303 | 303 | $ret = array(); |
304 | 304 | foreach ($vars as $var) { |
305 | - $response = $this->combine( |
|
306 | - $var, |
|
307 | - $parameters, |
|
308 | - $sep, |
|
309 | - $combine, |
|
310 | - $reserved, |
|
311 | - $tag_empty, |
|
312 | - $combine_on_empty |
|
313 | - ); |
|
314 | - if ($response === false) { |
|
305 | + $response = $this->combine( |
|
306 | + $var, |
|
307 | + $parameters, |
|
308 | + $sep, |
|
309 | + $combine, |
|
310 | + $reserved, |
|
311 | + $tag_empty, |
|
312 | + $combine_on_empty |
|
313 | + ); |
|
314 | + if ($response === false) { |
|
315 | 315 | continue; |
316 | - } |
|
317 | - $ret[] = $response; |
|
316 | + } |
|
317 | + $ret[] = $response; |
|
318 | 318 | } |
319 | 319 | return implode($sep, $ret); |
320 | - } |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Utility function to encode and trim values |
|
324 | - */ |
|
325 | - private function getValue($value, $length) |
|
326 | - { |
|
322 | + /** |
|
323 | + * Utility function to encode and trim values |
|
324 | + */ |
|
325 | + private function getValue($value, $length) |
|
326 | + { |
|
327 | 327 | if ($length) { |
328 | - $value = substr($value, 0, $length); |
|
328 | + $value = substr($value, 0, $length); |
|
329 | 329 | } |
330 | 330 | $value = rawurlencode($value); |
331 | 331 | return $value; |
332 | - } |
|
332 | + } |
|
333 | 333 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | private $reserved = array( |
50 | 50 | "=", ",", "!", "@", "|", ":", "/", "?", "#", |
51 | - "[", "]",'$', "&", "'", "(", ")", "*", "+", ";" |
|
51 | + "[", "]", '$', "&", "'", "(", ")", "*", "+", ";" |
|
52 | 52 | ); |
53 | 53 | private $reservedEncoded = array( |
54 | 54 | "%3D", "%2C", "%21", "%40", "%7C", "%3A", "%2F", "%3F", |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | case "segments": |
108 | 108 | // Slash separated data. Bare values only. |
109 | 109 | $prefix = "/"; |
110 | - $data =$this->replaceVars($data, $parameters, "/"); |
|
110 | + $data = $this->replaceVars($data, $parameters, "/"); |
|
111 | 111 | break; |
112 | 112 | case "dotprefix": |
113 | 113 | // Dot separated data. Bare values only. |
@@ -17,52 +17,52 @@ |
||
17 | 17 | |
18 | 18 | class Google_Service_Exception extends Google_Exception |
19 | 19 | { |
20 | - /** |
|
21 | - * Optional list of errors returned in a JSON body of an HTTP error response. |
|
22 | - */ |
|
23 | - protected $errors = array(); |
|
20 | + /** |
|
21 | + * Optional list of errors returned in a JSON body of an HTTP error response. |
|
22 | + */ |
|
23 | + protected $errors = array(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * Override default constructor to add the ability to set $errors and a retry |
|
27 | - * map. |
|
28 | - * |
|
29 | - * @param string $message |
|
30 | - * @param int $code |
|
31 | - * @param Exception|null $previous |
|
32 | - * @param [{string, string}] errors List of errors returned in an HTTP |
|
33 | - * response. Defaults to []. |
|
34 | - * @param array|null $retryMap Map of errors with retry counts. |
|
35 | - */ |
|
36 | - public function __construct( |
|
37 | - $message, |
|
38 | - $code = 0, |
|
39 | - Exception $previous = null, |
|
40 | - $errors = array() |
|
41 | - ) { |
|
25 | + /** |
|
26 | + * Override default constructor to add the ability to set $errors and a retry |
|
27 | + * map. |
|
28 | + * |
|
29 | + * @param string $message |
|
30 | + * @param int $code |
|
31 | + * @param Exception|null $previous |
|
32 | + * @param [{string, string}] errors List of errors returned in an HTTP |
|
33 | + * response. Defaults to []. |
|
34 | + * @param array|null $retryMap Map of errors with retry counts. |
|
35 | + */ |
|
36 | + public function __construct( |
|
37 | + $message, |
|
38 | + $code = 0, |
|
39 | + Exception $previous = null, |
|
40 | + $errors = array() |
|
41 | + ) { |
|
42 | 42 | if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
43 | - parent::__construct($message, $code, $previous); |
|
43 | + parent::__construct($message, $code, $previous); |
|
44 | 44 | } else { |
45 | - parent::__construct($message, $code); |
|
45 | + parent::__construct($message, $code); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $this->errors = $errors; |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * An example of the possible errors returned. |
|
53 | - * |
|
54 | - * { |
|
55 | - * "domain": "global", |
|
56 | - * "reason": "authError", |
|
57 | - * "message": "Invalid Credentials", |
|
58 | - * "locationType": "header", |
|
59 | - * "location": "Authorization", |
|
60 | - * } |
|
61 | - * |
|
62 | - * @return [{string, string}] List of errors return in an HTTP response or []. |
|
63 | - */ |
|
64 | - public function getErrors() |
|
65 | - { |
|
51 | + /** |
|
52 | + * An example of the possible errors returned. |
|
53 | + * |
|
54 | + * { |
|
55 | + * "domain": "global", |
|
56 | + * "reason": "authError", |
|
57 | + * "message": "Invalid Credentials", |
|
58 | + * "locationType": "header", |
|
59 | + * "location": "Authorization", |
|
60 | + * } |
|
61 | + * |
|
62 | + * @return [{string, string}] List of errors return in an HTTP response or []. |
|
63 | + */ |
|
64 | + public function getErrors() |
|
65 | + { |
|
66 | 66 | return $this->errors; |
67 | - } |
|
67 | + } |
|
68 | 68 | } |
@@ -25,40 +25,40 @@ discard block |
||
25 | 25 | */ |
26 | 26 | class Google_Service_Resource |
27 | 27 | { |
28 | - // Valid query parameters that work, but don't appear in discovery. |
|
29 | - private $stackParameters = array( |
|
30 | - 'alt' => array('type' => 'string', 'location' => 'query'), |
|
31 | - 'fields' => array('type' => 'string', 'location' => 'query'), |
|
32 | - 'trace' => array('type' => 'string', 'location' => 'query'), |
|
33 | - 'userIp' => array('type' => 'string', 'location' => 'query'), |
|
34 | - 'quotaUser' => array('type' => 'string', 'location' => 'query'), |
|
35 | - 'data' => array('type' => 'string', 'location' => 'body'), |
|
36 | - 'mimeType' => array('type' => 'string', 'location' => 'header'), |
|
37 | - 'uploadType' => array('type' => 'string', 'location' => 'query'), |
|
38 | - 'mediaUpload' => array('type' => 'complex', 'location' => 'query'), |
|
39 | - 'prettyPrint' => array('type' => 'string', 'location' => 'query'), |
|
40 | - ); |
|
41 | - |
|
42 | - /** @var string $rootUrl */ |
|
43 | - private $rootUrl; |
|
44 | - |
|
45 | - /** @var Google_Client $client */ |
|
46 | - private $client; |
|
47 | - |
|
48 | - /** @var string $serviceName */ |
|
49 | - private $serviceName; |
|
50 | - |
|
51 | - /** @var string $servicePath */ |
|
52 | - private $servicePath; |
|
53 | - |
|
54 | - /** @var string $resourceName */ |
|
55 | - private $resourceName; |
|
56 | - |
|
57 | - /** @var array $methods */ |
|
58 | - private $methods; |
|
59 | - |
|
60 | - public function __construct($service, $serviceName, $resourceName, $resource) |
|
61 | - { |
|
28 | + // Valid query parameters that work, but don't appear in discovery. |
|
29 | + private $stackParameters = array( |
|
30 | + 'alt' => array('type' => 'string', 'location' => 'query'), |
|
31 | + 'fields' => array('type' => 'string', 'location' => 'query'), |
|
32 | + 'trace' => array('type' => 'string', 'location' => 'query'), |
|
33 | + 'userIp' => array('type' => 'string', 'location' => 'query'), |
|
34 | + 'quotaUser' => array('type' => 'string', 'location' => 'query'), |
|
35 | + 'data' => array('type' => 'string', 'location' => 'body'), |
|
36 | + 'mimeType' => array('type' => 'string', 'location' => 'header'), |
|
37 | + 'uploadType' => array('type' => 'string', 'location' => 'query'), |
|
38 | + 'mediaUpload' => array('type' => 'complex', 'location' => 'query'), |
|
39 | + 'prettyPrint' => array('type' => 'string', 'location' => 'query'), |
|
40 | + ); |
|
41 | + |
|
42 | + /** @var string $rootUrl */ |
|
43 | + private $rootUrl; |
|
44 | + |
|
45 | + /** @var Google_Client $client */ |
|
46 | + private $client; |
|
47 | + |
|
48 | + /** @var string $serviceName */ |
|
49 | + private $serviceName; |
|
50 | + |
|
51 | + /** @var string $servicePath */ |
|
52 | + private $servicePath; |
|
53 | + |
|
54 | + /** @var string $resourceName */ |
|
55 | + private $resourceName; |
|
56 | + |
|
57 | + /** @var array $methods */ |
|
58 | + private $methods; |
|
59 | + |
|
60 | + public function __construct($service, $serviceName, $resourceName, $resource) |
|
61 | + { |
|
62 | 62 | $this->rootUrl = $service->rootUrl; |
63 | 63 | $this->client = $service->getClient(); |
64 | 64 | $this->servicePath = $service->servicePath; |
@@ -67,32 +67,32 @@ discard block |
||
67 | 67 | $this->methods = is_array($resource) && isset($resource['methods']) ? |
68 | 68 | $resource['methods'] : |
69 | 69 | array($resourceName => $resource); |
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * TODO: This function needs simplifying. |
|
74 | - * @param $name |
|
75 | - * @param $arguments |
|
76 | - * @param $expectedClass - optional, the expected class name |
|
77 | - * @return Google_Http_Request|expectedClass |
|
78 | - * @throws Google_Exception |
|
79 | - */ |
|
80 | - public function call($name, $arguments, $expectedClass = null) |
|
81 | - { |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * TODO: This function needs simplifying. |
|
74 | + * @param $name |
|
75 | + * @param $arguments |
|
76 | + * @param $expectedClass - optional, the expected class name |
|
77 | + * @return Google_Http_Request|expectedClass |
|
78 | + * @throws Google_Exception |
|
79 | + */ |
|
80 | + public function call($name, $arguments, $expectedClass = null) |
|
81 | + { |
|
82 | 82 | if (! isset($this->methods[$name])) { |
83 | - $this->client->getLogger()->error( |
|
84 | - 'Service method unknown', |
|
85 | - array( |
|
86 | - 'service' => $this->serviceName, |
|
87 | - 'resource' => $this->resourceName, |
|
88 | - 'method' => $name |
|
89 | - ) |
|
90 | - ); |
|
91 | - |
|
92 | - throw new Google_Exception( |
|
93 | - "Unknown function: " . |
|
94 | - "{$this->serviceName}->{$this->resourceName}->{$name}()" |
|
95 | - ); |
|
83 | + $this->client->getLogger()->error( |
|
84 | + 'Service method unknown', |
|
85 | + array( |
|
86 | + 'service' => $this->serviceName, |
|
87 | + 'resource' => $this->resourceName, |
|
88 | + 'method' => $name |
|
89 | + ) |
|
90 | + ); |
|
91 | + |
|
92 | + throw new Google_Exception( |
|
93 | + "Unknown function: " . |
|
94 | + "{$this->serviceName}->{$this->resourceName}->{$name}()" |
|
95 | + ); |
|
96 | 96 | } |
97 | 97 | $method = $this->methods[$name]; |
98 | 98 | $parameters = $arguments[0]; |
@@ -101,31 +101,31 @@ discard block |
||
101 | 101 | // document as parameter, but we abuse the param entry for storing it. |
102 | 102 | $postBody = null; |
103 | 103 | if (isset($parameters['postBody'])) { |
104 | - if ($parameters['postBody'] instanceof Google_Model) { |
|
104 | + if ($parameters['postBody'] instanceof Google_Model) { |
|
105 | 105 | // In the cases the post body is an existing object, we want |
106 | 106 | // to use the smart method to create a simple object for |
107 | 107 | // for JSONification. |
108 | 108 | $parameters['postBody'] = $parameters['postBody']->toSimpleObject(); |
109 | - } else if (is_object($parameters['postBody'])) { |
|
109 | + } else if (is_object($parameters['postBody'])) { |
|
110 | 110 | // If the post body is another kind of object, we will try and |
111 | 111 | // wrangle it into a sensible format. |
112 | 112 | $parameters['postBody'] = |
113 | 113 | $this->convertToArrayAndStripNulls($parameters['postBody']); |
114 | - } |
|
115 | - $postBody = (array) $parameters['postBody']; |
|
116 | - unset($parameters['postBody']); |
|
114 | + } |
|
115 | + $postBody = (array) $parameters['postBody']; |
|
116 | + unset($parameters['postBody']); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // TODO: optParams here probably should have been |
120 | 120 | // handled already - this may well be redundant code. |
121 | 121 | if (isset($parameters['optParams'])) { |
122 | - $optParams = $parameters['optParams']; |
|
123 | - unset($parameters['optParams']); |
|
124 | - $parameters = array_merge($parameters, $optParams); |
|
122 | + $optParams = $parameters['optParams']; |
|
123 | + unset($parameters['optParams']); |
|
124 | + $parameters = array_merge($parameters, $optParams); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | if (!isset($method['parameters'])) { |
128 | - $method['parameters'] = array(); |
|
128 | + $method['parameters'] = array(); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | $method['parameters'] = array_merge( |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | ); |
135 | 135 | |
136 | 136 | foreach ($parameters as $key => $val) { |
137 | - if ($key != 'postBody' && ! isset($method['parameters'][$key])) { |
|
137 | + if ($key != 'postBody' && ! isset($method['parameters'][$key])) { |
|
138 | 138 | $this->client->getLogger()->error( |
139 | 139 | 'Service parameter unknown', |
140 | 140 | array( |
@@ -145,14 +145,14 @@ discard block |
||
145 | 145 | ) |
146 | 146 | ); |
147 | 147 | throw new Google_Exception("($name) unknown parameter: '$key'"); |
148 | - } |
|
148 | + } |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | foreach ($method['parameters'] as $paramName => $paramSpec) { |
152 | - if (isset($paramSpec['required']) && |
|
152 | + if (isset($paramSpec['required']) && |
|
153 | 153 | $paramSpec['required'] && |
154 | 154 | ! isset($parameters[$paramName]) |
155 | - ) { |
|
155 | + ) { |
|
156 | 156 | $this->client->getLogger()->error( |
157 | 157 | 'Service parameter missing', |
158 | 158 | array( |
@@ -163,16 +163,16 @@ discard block |
||
163 | 163 | ) |
164 | 164 | ); |
165 | 165 | throw new Google_Exception("($name) missing required param: '$paramName'"); |
166 | - } |
|
167 | - if (isset($parameters[$paramName])) { |
|
166 | + } |
|
167 | + if (isset($parameters[$paramName])) { |
|
168 | 168 | $value = $parameters[$paramName]; |
169 | 169 | $parameters[$paramName] = $paramSpec; |
170 | 170 | $parameters[$paramName]['value'] = $value; |
171 | 171 | unset($parameters[$paramName]['required']); |
172 | - } else { |
|
172 | + } else { |
|
173 | 173 | // Ensure we don't pass nulls. |
174 | 174 | unset($parameters[$paramName]); |
175 | - } |
|
175 | + } |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $this->client->getLogger()->info( |
@@ -203,100 +203,100 @@ discard block |
||
203 | 203 | |
204 | 204 | // support uploads |
205 | 205 | if (isset($parameters['data'])) { |
206 | - $mimeType = isset($parameters['mimeType']) |
|
206 | + $mimeType = isset($parameters['mimeType']) |
|
207 | 207 | ? $parameters['mimeType']['value'] |
208 | 208 | : 'application/octet-stream'; |
209 | - $data = $parameters['data']['value']; |
|
210 | - $upload = new Google_Http_MediaFileUpload($this->client, $request, $mimeType, $data); |
|
209 | + $data = $parameters['data']['value']; |
|
210 | + $upload = new Google_Http_MediaFileUpload($this->client, $request, $mimeType, $data); |
|
211 | 211 | |
212 | - // pull down the modified request |
|
213 | - $request = $upload->getRequest(); |
|
212 | + // pull down the modified request |
|
213 | + $request = $upload->getRequest(); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | // if this is a media type, we will return the raw response |
217 | 217 | // rather than using an expected class |
218 | 218 | if (isset($parameters['alt']) && $parameters['alt']['value'] == 'media') { |
219 | - $expectedClass = null; |
|
219 | + $expectedClass = null; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // if the client is marked for deferring, rather than |
223 | 223 | // execute the request, return the response |
224 | 224 | if ($this->client->shouldDefer()) { |
225 | - // @TODO find a better way to do this |
|
226 | - $request = $request |
|
225 | + // @TODO find a better way to do this |
|
226 | + $request = $request |
|
227 | 227 | ->withHeader('X-Php-Expected-Class', $expectedClass); |
228 | 228 | |
229 | - return $request; |
|
229 | + return $request; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | return $this->client->execute($request, $expectedClass); |
233 | - } |
|
233 | + } |
|
234 | 234 | |
235 | - protected function convertToArrayAndStripNulls($o) |
|
236 | - { |
|
235 | + protected function convertToArrayAndStripNulls($o) |
|
236 | + { |
|
237 | 237 | $o = (array) $o; |
238 | 238 | foreach ($o as $k => $v) { |
239 | - if ($v === null) { |
|
239 | + if ($v === null) { |
|
240 | 240 | unset($o[$k]); |
241 | - } elseif (is_object($v) || is_array($v)) { |
|
241 | + } elseif (is_object($v) || is_array($v)) { |
|
242 | 242 | $o[$k] = $this->convertToArrayAndStripNulls($o[$k]); |
243 | - } |
|
243 | + } |
|
244 | 244 | } |
245 | 245 | return $o; |
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Parse/expand request parameters and create a fully qualified |
|
250 | - * request uri. |
|
251 | - * @static |
|
252 | - * @param string $restPath |
|
253 | - * @param array $params |
|
254 | - * @return string $requestUrl |
|
255 | - */ |
|
256 | - public function createRequestUri($restPath, $params) |
|
257 | - { |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Parse/expand request parameters and create a fully qualified |
|
250 | + * request uri. |
|
251 | + * @static |
|
252 | + * @param string $restPath |
|
253 | + * @param array $params |
|
254 | + * @return string $requestUrl |
|
255 | + */ |
|
256 | + public function createRequestUri($restPath, $params) |
|
257 | + { |
|
258 | 258 | // Override the default servicePath address if the $restPath use a / |
259 | 259 | if ('/' == substr($restPath, 0, 1)) { |
260 | - $requestUrl = substr($restPath, 1); |
|
260 | + $requestUrl = substr($restPath, 1); |
|
261 | 261 | } else { |
262 | - $requestUrl = $this->servicePath . $restPath; |
|
262 | + $requestUrl = $this->servicePath . $restPath; |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | // code for leading slash |
266 | 266 | if ($this->rootUrl) { |
267 | - if ('/' !== substr($this->rootUrl, -1) && '/' !== substr($requestUrl, 0, 1)) { |
|
267 | + if ('/' !== substr($this->rootUrl, -1) && '/' !== substr($requestUrl, 0, 1)) { |
|
268 | 268 | $requestUrl = '/' . $requestUrl; |
269 | - } |
|
270 | - $requestUrl = $this->rootUrl . $requestUrl; |
|
269 | + } |
|
270 | + $requestUrl = $this->rootUrl . $requestUrl; |
|
271 | 271 | } |
272 | 272 | $uriTemplateVars = array(); |
273 | 273 | $queryVars = array(); |
274 | 274 | foreach ($params as $paramName => $paramSpec) { |
275 | - if ($paramSpec['type'] == 'boolean') { |
|
275 | + if ($paramSpec['type'] == 'boolean') { |
|
276 | 276 | $paramSpec['value'] = $paramSpec['value'] ? 'true' : 'false'; |
277 | - } |
|
278 | - if ($paramSpec['location'] == 'path') { |
|
277 | + } |
|
278 | + if ($paramSpec['location'] == 'path') { |
|
279 | 279 | $uriTemplateVars[$paramName] = $paramSpec['value']; |
280 | - } else if ($paramSpec['location'] == 'query') { |
|
280 | + } else if ($paramSpec['location'] == 'query') { |
|
281 | 281 | if (is_array($paramSpec['value'])) { |
282 | - foreach ($paramSpec['value'] as $value) { |
|
282 | + foreach ($paramSpec['value'] as $value) { |
|
283 | 283 | $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($value)); |
284 | - } |
|
284 | + } |
|
285 | 285 | } else { |
286 | - $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($paramSpec['value'])); |
|
286 | + $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($paramSpec['value'])); |
|
287 | + } |
|
287 | 288 | } |
288 | - } |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | if (count($uriTemplateVars)) { |
292 | - $uriTemplateParser = new Google_Utils_UriTemplate(); |
|
293 | - $requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars); |
|
292 | + $uriTemplateParser = new Google_Utils_UriTemplate(); |
|
293 | + $requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | if (count($queryVars)) { |
297 | - $requestUrl .= '?' . implode($queryVars, '&'); |
|
297 | + $requestUrl .= '?' . implode($queryVars, '&'); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | return $requestUrl; |
301 | - } |
|
301 | + } |
|
302 | 302 | } |
@@ -65,8 +65,7 @@ discard block |
||
65 | 65 | $this->serviceName = $serviceName; |
66 | 66 | $this->resourceName = $resourceName; |
67 | 67 | $this->methods = is_array($resource) && isset($resource['methods']) ? |
68 | - $resource['methods'] : |
|
69 | - array($resourceName => $resource); |
|
68 | + $resource['methods'] : array($resourceName => $resource); |
|
70 | 69 | } |
71 | 70 | |
72 | 71 | /** |
@@ -79,7 +78,7 @@ discard block |
||
79 | 78 | */ |
80 | 79 | public function call($name, $arguments, $expectedClass = null) |
81 | 80 | { |
82 | - if (! isset($this->methods[$name])) { |
|
81 | + if (!isset($this->methods[$name])) { |
|
83 | 82 | $this->client->getLogger()->error( |
84 | 83 | 'Service method unknown', |
85 | 84 | array( |
@@ -112,7 +111,7 @@ discard block |
||
112 | 111 | $parameters['postBody'] = |
113 | 112 | $this->convertToArrayAndStripNulls($parameters['postBody']); |
114 | 113 | } |
115 | - $postBody = (array) $parameters['postBody']; |
|
114 | + $postBody = (array)$parameters['postBody']; |
|
116 | 115 | unset($parameters['postBody']); |
117 | 116 | } |
118 | 117 | |
@@ -134,7 +133,7 @@ discard block |
||
134 | 133 | ); |
135 | 134 | |
136 | 135 | foreach ($parameters as $key => $val) { |
137 | - if ($key != 'postBody' && ! isset($method['parameters'][$key])) { |
|
136 | + if ($key != 'postBody' && !isset($method['parameters'][$key])) { |
|
138 | 137 | $this->client->getLogger()->error( |
139 | 138 | 'Service parameter unknown', |
140 | 139 | array( |
@@ -151,7 +150,7 @@ discard block |
||
151 | 150 | foreach ($method['parameters'] as $paramName => $paramSpec) { |
152 | 151 | if (isset($paramSpec['required']) && |
153 | 152 | $paramSpec['required'] && |
154 | - ! isset($parameters[$paramName]) |
|
153 | + !isset($parameters[$paramName]) |
|
155 | 154 | ) { |
156 | 155 | $this->client->getLogger()->error( |
157 | 156 | 'Service parameter missing', |
@@ -234,7 +233,7 @@ discard block |
||
234 | 233 | |
235 | 234 | protected function convertToArrayAndStripNulls($o) |
236 | 235 | { |
237 | - $o = (array) $o; |
|
236 | + $o = (array)$o; |
|
238 | 237 | foreach ($o as $k => $v) { |
239 | 238 | if ($v === null) { |
240 | 239 | unset($o[$k]); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (!class_exists('Google_Client')) { |
4 | - require_once __DIR__ . '/autoload.php'; |
|
4 | + require_once __DIR__ . '/autoload.php'; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,90 +11,90 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class Google_Collection extends Google_Model implements Iterator, Countable |
13 | 13 | { |
14 | - protected $collection_key = 'items'; |
|
14 | + protected $collection_key = 'items'; |
|
15 | 15 | |
16 | - public function rewind() |
|
17 | - { |
|
16 | + public function rewind() |
|
17 | + { |
|
18 | 18 | if (isset($this->{$this->collection_key}) |
19 | 19 | && is_array($this->{$this->collection_key})) { |
20 | - reset($this->{$this->collection_key}); |
|
20 | + reset($this->{$this->collection_key}); |
|
21 | + } |
|
21 | 22 | } |
22 | - } |
|
23 | 23 | |
24 | - public function current() |
|
25 | - { |
|
24 | + public function current() |
|
25 | + { |
|
26 | 26 | $this->coerceType($this->key()); |
27 | 27 | if (is_array($this->{$this->collection_key})) { |
28 | - return current($this->{$this->collection_key}); |
|
28 | + return current($this->{$this->collection_key}); |
|
29 | + } |
|
29 | 30 | } |
30 | - } |
|
31 | 31 | |
32 | - public function key() |
|
33 | - { |
|
32 | + public function key() |
|
33 | + { |
|
34 | 34 | if (isset($this->{$this->collection_key}) |
35 | 35 | && is_array($this->{$this->collection_key})) { |
36 | - return key($this->{$this->collection_key}); |
|
36 | + return key($this->{$this->collection_key}); |
|
37 | + } |
|
37 | 38 | } |
38 | - } |
|
39 | 39 | |
40 | - public function next() |
|
41 | - { |
|
40 | + public function next() |
|
41 | + { |
|
42 | 42 | return next($this->{$this->collection_key}); |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - public function valid() |
|
46 | - { |
|
45 | + public function valid() |
|
46 | + { |
|
47 | 47 | $key = $this->key(); |
48 | 48 | return $key !== null && $key !== false; |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - public function count() |
|
52 | - { |
|
51 | + public function count() |
|
52 | + { |
|
53 | 53 | if (!isset($this->{$this->collection_key})) { |
54 | - return 0; |
|
54 | + return 0; |
|
55 | 55 | } |
56 | 56 | return count($this->{$this->collection_key}); |
57 | - } |
|
57 | + } |
|
58 | 58 | |
59 | - public function offsetExists($offset) |
|
60 | - { |
|
59 | + public function offsetExists($offset) |
|
60 | + { |
|
61 | 61 | if (!is_numeric($offset)) { |
62 | - return parent::offsetExists($offset); |
|
62 | + return parent::offsetExists($offset); |
|
63 | 63 | } |
64 | 64 | return isset($this->{$this->collection_key}[$offset]); |
65 | - } |
|
65 | + } |
|
66 | 66 | |
67 | - public function offsetGet($offset) |
|
68 | - { |
|
67 | + public function offsetGet($offset) |
|
68 | + { |
|
69 | 69 | if (!is_numeric($offset)) { |
70 | - return parent::offsetGet($offset); |
|
70 | + return parent::offsetGet($offset); |
|
71 | 71 | } |
72 | 72 | $this->coerceType($offset); |
73 | 73 | return $this->{$this->collection_key}[$offset]; |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - public function offsetSet($offset, $value) |
|
77 | - { |
|
76 | + public function offsetSet($offset, $value) |
|
77 | + { |
|
78 | 78 | if (!is_numeric($offset)) { |
79 | - return parent::offsetSet($offset, $value); |
|
79 | + return parent::offsetSet($offset, $value); |
|
80 | 80 | } |
81 | 81 | $this->{$this->collection_key}[$offset] = $value; |
82 | - } |
|
82 | + } |
|
83 | 83 | |
84 | - public function offsetUnset($offset) |
|
85 | - { |
|
84 | + public function offsetUnset($offset) |
|
85 | + { |
|
86 | 86 | if (!is_numeric($offset)) { |
87 | - return parent::offsetUnset($offset); |
|
87 | + return parent::offsetUnset($offset); |
|
88 | 88 | } |
89 | 89 | unset($this->{$this->collection_key}[$offset]); |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - private function coerceType($offset) |
|
93 | - { |
|
92 | + private function coerceType($offset) |
|
93 | + { |
|
94 | 94 | $keyType = $this->keyType($this->collection_key); |
95 | 95 | if ($keyType && !is_object($this->{$this->collection_key}[$offset])) { |
96 | - $this->{$this->collection_key}[$offset] = |
|
97 | - new $keyType($this->{$this->collection_key}[$offset]); |
|
96 | + $this->{$this->collection_key}[$offset] = |
|
97 | + new $keyType($this->{$this->collection_key}[$offset]); |
|
98 | + } |
|
98 | 99 | } |
99 | - } |
|
100 | 100 | } |
@@ -17,40 +17,40 @@ |
||
17 | 17 | |
18 | 18 | class Google_Service |
19 | 19 | { |
20 | - public $batchPath; |
|
21 | - public $rootUrl; |
|
22 | - public $version; |
|
23 | - public $servicePath; |
|
24 | - public $availableScopes; |
|
25 | - public $resource; |
|
26 | - private $client; |
|
20 | + public $batchPath; |
|
21 | + public $rootUrl; |
|
22 | + public $version; |
|
23 | + public $servicePath; |
|
24 | + public $availableScopes; |
|
25 | + public $resource; |
|
26 | + private $client; |
|
27 | 27 | |
28 | - public function __construct(Google_Client $client) |
|
29 | - { |
|
28 | + public function __construct(Google_Client $client) |
|
29 | + { |
|
30 | 30 | $this->client = $client; |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Return the associated Google_Client class. |
|
35 | - * @return Google_Client |
|
36 | - */ |
|
37 | - public function getClient() |
|
38 | - { |
|
33 | + /** |
|
34 | + * Return the associated Google_Client class. |
|
35 | + * @return Google_Client |
|
36 | + */ |
|
37 | + public function getClient() |
|
38 | + { |
|
39 | 39 | return $this->client; |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Create a new HTTP Batch handler for this service |
|
44 | - * |
|
45 | - * @return Google_Http_Batch |
|
46 | - */ |
|
47 | - public function createBatch() |
|
48 | - { |
|
42 | + /** |
|
43 | + * Create a new HTTP Batch handler for this service |
|
44 | + * |
|
45 | + * @return Google_Http_Batch |
|
46 | + */ |
|
47 | + public function createBatch() |
|
48 | + { |
|
49 | 49 | return new Google_Http_Batch( |
50 | 50 | $this->client, |
51 | 51 | false, |
52 | 52 | $this->rootUrl, |
53 | 53 | $this->batchPath |
54 | 54 | ); |
55 | - } |
|
55 | + } |
|
56 | 56 | } |