@@ -224,6 +224,9 @@ discard block |
||
224 | 224 | return $v_block; |
225 | 225 | } |
226 | 226 | |
227 | + /** |
|
228 | + * @param double $p_len |
|
229 | + */ |
|
227 | 230 | private function _jumpBlock($p_len=null) |
228 | 231 | { |
229 | 232 | if (is_resource($this->_file)) { |
@@ -317,6 +320,12 @@ discard block |
||
317 | 320 | return true; |
318 | 321 | } |
319 | 322 | |
323 | + /** |
|
324 | + * @param string $p_path |
|
325 | + * @param string $p_mode |
|
326 | + * @param integer $p_file_list |
|
327 | + * @param string $p_remove_path |
|
328 | + */ |
|
320 | 329 | protected function _extractList($p_path, &$p_list_detail, $p_mode, |
321 | 330 | $p_file_list, $p_remove_path) |
322 | 331 | { |
@@ -35,537 +35,537 @@ |
||
35 | 35 | */ |
36 | 36 | class TTarFileExtractor |
37 | 37 | { |
38 | - /** |
|
39 | - * @var string Name of the Tar |
|
40 | - */ |
|
41 | - private $_tarname=''; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var file descriptor |
|
45 | - */ |
|
46 | - private $_file=0; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string Local Tar name of a remote Tar (http:// or ftp://) |
|
50 | - */ |
|
51 | - private $_temp_tarname=''; |
|
52 | - |
|
53 | - /** |
|
54 | - * Archive_Tar Class constructor. This flavour of the constructor only |
|
55 | - * declare a new Archive_Tar object, identifying it by the name of the |
|
56 | - * tar file. |
|
57 | - * |
|
58 | - * @param string $p_tarname The name of the tar archive to create |
|
59 | - * @access public |
|
60 | - */ |
|
61 | - public function __construct($p_tarname) |
|
62 | - { |
|
63 | - $this->_tarname = $p_tarname; |
|
64 | - } |
|
65 | - |
|
66 | - public function __destruct() |
|
67 | - { |
|
68 | - $this->_close(); |
|
69 | - // ----- Look for a local copy to delete |
|
70 | - if ($this->_temp_tarname != '') |
|
71 | - @unlink($this->_temp_tarname); |
|
72 | - } |
|
73 | - |
|
74 | - public function extract($p_path='') |
|
75 | - { |
|
76 | - return $this->extractModify($p_path, ''); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * This method extract all the content of the archive in the directory |
|
81 | - * indicated by $p_path. When relevant the memorized path of the |
|
82 | - * files/dir can be modified by removing the $p_remove_path path at the |
|
83 | - * beginning of the file/dir path. |
|
84 | - * While extracting a file, if the directory path does not exists it is |
|
85 | - * created. |
|
86 | - * While extracting a file, if the file already exists it is replaced |
|
87 | - * without looking for last modification date. |
|
88 | - * While extracting a file, if the file already exists and is write |
|
89 | - * protected, the extraction is aborted. |
|
90 | - * While extracting a file, if a directory with the same name already |
|
91 | - * exists, the extraction is aborted. |
|
92 | - * While extracting a directory, if a file with the same name already |
|
93 | - * exists, the extraction is aborted. |
|
94 | - * While extracting a file/directory if the destination directory exist |
|
95 | - * and is write protected, or does not exist but can not be created, |
|
96 | - * the extraction is aborted. |
|
97 | - * If after extraction an extracted file does not show the correct |
|
98 | - * stored file size, the extraction is aborted. |
|
99 | - * When the extraction is aborted, a PEAR error text is set and false |
|
100 | - * is returned. However the result can be a partial extraction that may |
|
101 | - * need to be manually cleaned. |
|
102 | - * |
|
103 | - * @param string $p_path The path of the directory where the |
|
104 | - * files/dir need to by extracted. |
|
105 | - * @param string $p_remove_path Part of the memorized path that can be |
|
106 | - * removed if present at the beginning of |
|
107 | - * the file/dir path. |
|
108 | - * @return boolean true on success, false on error. |
|
109 | - * @access public |
|
110 | - */ |
|
111 | - protected function extractModify($p_path, $p_remove_path) |
|
112 | - { |
|
113 | - $v_result = true; |
|
114 | - $v_list_detail = array(); |
|
115 | - |
|
116 | - if ($v_result = $this->_openRead()) { |
|
117 | - $v_result = $this->_extractList($p_path, $v_list_detail, |
|
118 | - "complete", 0, $p_remove_path); |
|
119 | - $this->_close(); |
|
120 | - } |
|
121 | - |
|
122 | - return $v_result; |
|
123 | - } |
|
124 | - |
|
125 | - protected function _error($p_message) |
|
126 | - { |
|
38 | + /** |
|
39 | + * @var string Name of the Tar |
|
40 | + */ |
|
41 | + private $_tarname=''; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var file descriptor |
|
45 | + */ |
|
46 | + private $_file=0; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string Local Tar name of a remote Tar (http:// or ftp://) |
|
50 | + */ |
|
51 | + private $_temp_tarname=''; |
|
52 | + |
|
53 | + /** |
|
54 | + * Archive_Tar Class constructor. This flavour of the constructor only |
|
55 | + * declare a new Archive_Tar object, identifying it by the name of the |
|
56 | + * tar file. |
|
57 | + * |
|
58 | + * @param string $p_tarname The name of the tar archive to create |
|
59 | + * @access public |
|
60 | + */ |
|
61 | + public function __construct($p_tarname) |
|
62 | + { |
|
63 | + $this->_tarname = $p_tarname; |
|
64 | + } |
|
65 | + |
|
66 | + public function __destruct() |
|
67 | + { |
|
68 | + $this->_close(); |
|
69 | + // ----- Look for a local copy to delete |
|
70 | + if ($this->_temp_tarname != '') |
|
71 | + @unlink($this->_temp_tarname); |
|
72 | + } |
|
73 | + |
|
74 | + public function extract($p_path='') |
|
75 | + { |
|
76 | + return $this->extractModify($p_path, ''); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * This method extract all the content of the archive in the directory |
|
81 | + * indicated by $p_path. When relevant the memorized path of the |
|
82 | + * files/dir can be modified by removing the $p_remove_path path at the |
|
83 | + * beginning of the file/dir path. |
|
84 | + * While extracting a file, if the directory path does not exists it is |
|
85 | + * created. |
|
86 | + * While extracting a file, if the file already exists it is replaced |
|
87 | + * without looking for last modification date. |
|
88 | + * While extracting a file, if the file already exists and is write |
|
89 | + * protected, the extraction is aborted. |
|
90 | + * While extracting a file, if a directory with the same name already |
|
91 | + * exists, the extraction is aborted. |
|
92 | + * While extracting a directory, if a file with the same name already |
|
93 | + * exists, the extraction is aborted. |
|
94 | + * While extracting a file/directory if the destination directory exist |
|
95 | + * and is write protected, or does not exist but can not be created, |
|
96 | + * the extraction is aborted. |
|
97 | + * If after extraction an extracted file does not show the correct |
|
98 | + * stored file size, the extraction is aborted. |
|
99 | + * When the extraction is aborted, a PEAR error text is set and false |
|
100 | + * is returned. However the result can be a partial extraction that may |
|
101 | + * need to be manually cleaned. |
|
102 | + * |
|
103 | + * @param string $p_path The path of the directory where the |
|
104 | + * files/dir need to by extracted. |
|
105 | + * @param string $p_remove_path Part of the memorized path that can be |
|
106 | + * removed if present at the beginning of |
|
107 | + * the file/dir path. |
|
108 | + * @return boolean true on success, false on error. |
|
109 | + * @access public |
|
110 | + */ |
|
111 | + protected function extractModify($p_path, $p_remove_path) |
|
112 | + { |
|
113 | + $v_result = true; |
|
114 | + $v_list_detail = array(); |
|
115 | + |
|
116 | + if ($v_result = $this->_openRead()) { |
|
117 | + $v_result = $this->_extractList($p_path, $v_list_detail, |
|
118 | + "complete", 0, $p_remove_path); |
|
119 | + $this->_close(); |
|
120 | + } |
|
121 | + |
|
122 | + return $v_result; |
|
123 | + } |
|
124 | + |
|
125 | + protected function _error($p_message) |
|
126 | + { |
|
127 | 127 | throw new Exception($p_message); |
128 | - } |
|
129 | - |
|
130 | - private function _isArchive($p_filename=null) |
|
131 | - { |
|
132 | - if ($p_filename == null) { |
|
133 | - $p_filename = $this->_tarname; |
|
134 | - } |
|
135 | - clearstatcache(); |
|
136 | - return @is_file($p_filename); |
|
137 | - } |
|
138 | - |
|
139 | - private function _openRead() |
|
140 | - { |
|
141 | - if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') { |
|
142 | - |
|
143 | - // ----- Look if a local copy need to be done |
|
144 | - if ($this->_temp_tarname == '') { |
|
145 | - $this->_temp_tarname = uniqid('tar').'.tmp'; |
|
146 | - if (!$v_file_from = @fopen($this->_tarname, 'rb')) { |
|
147 | - $this->_error('Unable to open in read mode \'' |
|
148 | - .$this->_tarname.'\''); |
|
149 | - $this->_temp_tarname = ''; |
|
150 | - return false; |
|
151 | - } |
|
152 | - if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { |
|
153 | - $this->_error('Unable to open in write mode \'' |
|
154 | - .$this->_temp_tarname.'\''); |
|
155 | - $this->_temp_tarname = ''; |
|
156 | - return false; |
|
157 | - } |
|
158 | - while ($v_data = @fread($v_file_from, 1024)) |
|
159 | - @fwrite($v_file_to, $v_data); |
|
160 | - @fclose($v_file_from); |
|
161 | - @fclose($v_file_to); |
|
162 | - } |
|
163 | - |
|
164 | - // ----- File to open if the local copy |
|
165 | - $v_filename = $this->_temp_tarname; |
|
166 | - |
|
167 | - } else |
|
168 | - // ----- File to open if the normal Tar file |
|
169 | - $v_filename = $this->_tarname; |
|
128 | + } |
|
129 | + |
|
130 | + private function _isArchive($p_filename=null) |
|
131 | + { |
|
132 | + if ($p_filename == null) { |
|
133 | + $p_filename = $this->_tarname; |
|
134 | + } |
|
135 | + clearstatcache(); |
|
136 | + return @is_file($p_filename); |
|
137 | + } |
|
138 | + |
|
139 | + private function _openRead() |
|
140 | + { |
|
141 | + if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') { |
|
142 | + |
|
143 | + // ----- Look if a local copy need to be done |
|
144 | + if ($this->_temp_tarname == '') { |
|
145 | + $this->_temp_tarname = uniqid('tar').'.tmp'; |
|
146 | + if (!$v_file_from = @fopen($this->_tarname, 'rb')) { |
|
147 | + $this->_error('Unable to open in read mode \'' |
|
148 | + .$this->_tarname.'\''); |
|
149 | + $this->_temp_tarname = ''; |
|
150 | + return false; |
|
151 | + } |
|
152 | + if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { |
|
153 | + $this->_error('Unable to open in write mode \'' |
|
154 | + .$this->_temp_tarname.'\''); |
|
155 | + $this->_temp_tarname = ''; |
|
156 | + return false; |
|
157 | + } |
|
158 | + while ($v_data = @fread($v_file_from, 1024)) |
|
159 | + @fwrite($v_file_to, $v_data); |
|
160 | + @fclose($v_file_from); |
|
161 | + @fclose($v_file_to); |
|
162 | + } |
|
163 | + |
|
164 | + // ----- File to open if the local copy |
|
165 | + $v_filename = $this->_temp_tarname; |
|
166 | + |
|
167 | + } else |
|
168 | + // ----- File to open if the normal Tar file |
|
169 | + $v_filename = $this->_tarname; |
|
170 | 170 | |
171 | 171 | $this->_file = @fopen($v_filename, "rb"); |
172 | 172 | |
173 | - if ($this->_file == 0) { |
|
174 | - $this->_error('Unable to open in read mode \''.$v_filename.'\''); |
|
175 | - return false; |
|
176 | - } |
|
173 | + if ($this->_file == 0) { |
|
174 | + $this->_error('Unable to open in read mode \''.$v_filename.'\''); |
|
175 | + return false; |
|
176 | + } |
|
177 | 177 | |
178 | - return true; |
|
179 | - } |
|
178 | + return true; |
|
179 | + } |
|
180 | 180 | |
181 | - private function _close() |
|
182 | - { |
|
183 | - //if (isset($this->_file)) { |
|
184 | - if (is_resource($this->_file)) |
|
181 | + private function _close() |
|
182 | + { |
|
183 | + //if (isset($this->_file)) { |
|
184 | + if (is_resource($this->_file)) |
|
185 | 185 | { |
186 | - @fclose($this->_file); |
|
187 | - $this->_file = 0; |
|
188 | - } |
|
189 | - |
|
190 | - // ----- Look if a local copy need to be erase |
|
191 | - // Note that it might be interesting to keep the url for a time : ToDo |
|
192 | - if ($this->_temp_tarname != '') { |
|
193 | - @unlink($this->_temp_tarname); |
|
194 | - $this->_temp_tarname = ''; |
|
195 | - } |
|
196 | - |
|
197 | - return true; |
|
198 | - } |
|
199 | - |
|
200 | - private function _cleanFile() |
|
201 | - { |
|
202 | - $this->_close(); |
|
203 | - |
|
204 | - // ----- Look for a local copy |
|
205 | - if ($this->_temp_tarname != '') { |
|
206 | - // ----- Remove the local copy but not the remote tarname |
|
207 | - @unlink($this->_temp_tarname); |
|
208 | - $this->_temp_tarname = ''; |
|
209 | - } else { |
|
210 | - // ----- Remove the local tarname file |
|
211 | - @unlink($this->_tarname); |
|
212 | - } |
|
213 | - $this->_tarname = ''; |
|
214 | - |
|
215 | - return true; |
|
216 | - } |
|
217 | - |
|
218 | - private function _readBlock() |
|
219 | - { |
|
220 | - $v_block = null; |
|
221 | - if (is_resource($this->_file)) { |
|
222 | - $v_block = @fread($this->_file, 512); |
|
223 | - } |
|
224 | - return $v_block; |
|
225 | - } |
|
226 | - |
|
227 | - private function _jumpBlock($p_len=null) |
|
228 | - { |
|
229 | - if (is_resource($this->_file)) { |
|
230 | - if ($p_len === null) |
|
231 | - $p_len = 1; |
|
232 | - |
|
233 | - @fseek($this->_file, @ftell($this->_file)+($p_len*512)); |
|
234 | - } |
|
235 | - return true; |
|
236 | - } |
|
237 | - |
|
238 | - private function _readHeader($v_binary_data, &$v_header) |
|
239 | - { |
|
240 | - if (strlen($v_binary_data)==0) { |
|
241 | - $v_header['filename'] = ''; |
|
242 | - return true; |
|
243 | - } |
|
244 | - |
|
245 | - if (strlen($v_binary_data) != 512) { |
|
246 | - $v_header['filename'] = ''; |
|
247 | - $this->_error('Invalid block size : '.strlen($v_binary_data)); |
|
248 | - return false; |
|
249 | - } |
|
250 | - |
|
251 | - // ----- Calculate the checksum |
|
252 | - $v_checksum = 0; |
|
253 | - // ..... First part of the header |
|
254 | - for ($i=0; $i<148; $i++) |
|
255 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
256 | - // ..... Ignore the checksum value and replace it by ' ' (space) |
|
257 | - for ($i=148; $i<156; $i++) |
|
258 | - $v_checksum += ord(' '); |
|
259 | - // ..... Last part of the header |
|
260 | - for ($i=156; $i<512; $i++) |
|
261 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
262 | - |
|
263 | - $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
264 | - ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
|
186 | + @fclose($this->_file); |
|
187 | + $this->_file = 0; |
|
188 | + } |
|
189 | + |
|
190 | + // ----- Look if a local copy need to be erase |
|
191 | + // Note that it might be interesting to keep the url for a time : ToDo |
|
192 | + if ($this->_temp_tarname != '') { |
|
193 | + @unlink($this->_temp_tarname); |
|
194 | + $this->_temp_tarname = ''; |
|
195 | + } |
|
196 | + |
|
197 | + return true; |
|
198 | + } |
|
199 | + |
|
200 | + private function _cleanFile() |
|
201 | + { |
|
202 | + $this->_close(); |
|
203 | + |
|
204 | + // ----- Look for a local copy |
|
205 | + if ($this->_temp_tarname != '') { |
|
206 | + // ----- Remove the local copy but not the remote tarname |
|
207 | + @unlink($this->_temp_tarname); |
|
208 | + $this->_temp_tarname = ''; |
|
209 | + } else { |
|
210 | + // ----- Remove the local tarname file |
|
211 | + @unlink($this->_tarname); |
|
212 | + } |
|
213 | + $this->_tarname = ''; |
|
214 | + |
|
215 | + return true; |
|
216 | + } |
|
217 | + |
|
218 | + private function _readBlock() |
|
219 | + { |
|
220 | + $v_block = null; |
|
221 | + if (is_resource($this->_file)) { |
|
222 | + $v_block = @fread($this->_file, 512); |
|
223 | + } |
|
224 | + return $v_block; |
|
225 | + } |
|
226 | + |
|
227 | + private function _jumpBlock($p_len=null) |
|
228 | + { |
|
229 | + if (is_resource($this->_file)) { |
|
230 | + if ($p_len === null) |
|
231 | + $p_len = 1; |
|
232 | + |
|
233 | + @fseek($this->_file, @ftell($this->_file)+($p_len*512)); |
|
234 | + } |
|
235 | + return true; |
|
236 | + } |
|
237 | + |
|
238 | + private function _readHeader($v_binary_data, &$v_header) |
|
239 | + { |
|
240 | + if (strlen($v_binary_data)==0) { |
|
241 | + $v_header['filename'] = ''; |
|
242 | + return true; |
|
243 | + } |
|
244 | + |
|
245 | + if (strlen($v_binary_data) != 512) { |
|
246 | + $v_header['filename'] = ''; |
|
247 | + $this->_error('Invalid block size : '.strlen($v_binary_data)); |
|
248 | + return false; |
|
249 | + } |
|
250 | + |
|
251 | + // ----- Calculate the checksum |
|
252 | + $v_checksum = 0; |
|
253 | + // ..... First part of the header |
|
254 | + for ($i=0; $i<148; $i++) |
|
255 | + $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
256 | + // ..... Ignore the checksum value and replace it by ' ' (space) |
|
257 | + for ($i=148; $i<156; $i++) |
|
258 | + $v_checksum += ord(' '); |
|
259 | + // ..... Last part of the header |
|
260 | + for ($i=156; $i<512; $i++) |
|
261 | + $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
262 | + |
|
263 | + $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
264 | + ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
|
265 | 265 | ."a32uname/a32gname/a8devmajor/a8devminor", |
266 | 266 | $v_binary_data); |
267 | 267 | |
268 | - // ----- Extract the checksum |
|
269 | - $v_header['checksum'] = OctDec(trim($v_data['checksum'])); |
|
270 | - if ($v_header['checksum'] != $v_checksum) { |
|
271 | - $v_header['filename'] = ''; |
|
268 | + // ----- Extract the checksum |
|
269 | + $v_header['checksum'] = OctDec(trim($v_data['checksum'])); |
|
270 | + if ($v_header['checksum'] != $v_checksum) { |
|
271 | + $v_header['filename'] = ''; |
|
272 | 272 | |
273 | - // ----- Look for last block (empty block) |
|
274 | - if (($v_checksum == 256) && ($v_header['checksum'] == 0)) |
|
275 | - return true; |
|
273 | + // ----- Look for last block (empty block) |
|
274 | + if (($v_checksum == 256) && ($v_header['checksum'] == 0)) |
|
275 | + return true; |
|
276 | 276 | |
277 | - $this->_error('Invalid checksum for file "'.$v_data['filename'] |
|
278 | - .'" : '.$v_checksum.' calculated, ' |
|
277 | + $this->_error('Invalid checksum for file "'.$v_data['filename'] |
|
278 | + .'" : '.$v_checksum.' calculated, ' |
|
279 | 279 | .$v_header['checksum'].' expected'); |
280 | - return false; |
|
281 | - } |
|
282 | - |
|
283 | - // ----- Extract the properties |
|
284 | - $v_header['filename'] = trim($v_data['filename']); |
|
285 | - $v_header['mode'] = OctDec(trim($v_data['mode'])); |
|
286 | - $v_header['uid'] = OctDec(trim($v_data['uid'])); |
|
287 | - $v_header['gid'] = OctDec(trim($v_data['gid'])); |
|
288 | - $v_header['size'] = OctDec(trim($v_data['size'])); |
|
289 | - $v_header['mtime'] = OctDec(trim($v_data['mtime'])); |
|
290 | - if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { |
|
291 | - $v_header['size'] = 0; |
|
292 | - } |
|
293 | - return true; |
|
294 | - } |
|
295 | - |
|
296 | - private function _readLongHeader(&$v_header) |
|
297 | - { |
|
298 | - $v_filename = ''; |
|
299 | - $n = floor($v_header['size']/512); |
|
300 | - for ($i=0; $i<$n; $i++) { |
|
301 | - $v_content = $this->_readBlock(); |
|
302 | - $v_filename .= $v_content; |
|
303 | - } |
|
304 | - if (($v_header['size'] % 512) != 0) { |
|
305 | - $v_content = $this->_readBlock(); |
|
306 | - $v_filename .= $v_content; |
|
307 | - } |
|
308 | - |
|
309 | - // ----- Read the next header |
|
310 | - $v_binary_data = $this->_readBlock(); |
|
311 | - |
|
312 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
313 | - return false; |
|
314 | - |
|
315 | - $v_header['filename'] = $v_filename; |
|
316 | - |
|
317 | - return true; |
|
318 | - } |
|
319 | - |
|
320 | - protected function _extractList($p_path, &$p_list_detail, $p_mode, |
|
321 | - $p_file_list, $p_remove_path) |
|
322 | - { |
|
323 | - $v_result=true; |
|
324 | - $v_nb = 0; |
|
325 | - $v_extract_all = true; |
|
326 | - $v_listing = false; |
|
327 | - |
|
328 | - $p_path = $this->_translateWinPath($p_path, false); |
|
329 | - if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
|
330 | - && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
|
331 | - $p_path = "./".$p_path; |
|
332 | - } |
|
333 | - $p_remove_path = $this->_translateWinPath($p_remove_path); |
|
334 | - |
|
335 | - // ----- Look for path to remove format (should end by /) |
|
336 | - if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) |
|
337 | - $p_remove_path .= '/'; |
|
338 | - $p_remove_path_size = strlen($p_remove_path); |
|
339 | - |
|
340 | - switch ($p_mode) { |
|
341 | - case "complete" : |
|
342 | - $v_extract_all = true; |
|
343 | - $v_listing = false; |
|
344 | - break; |
|
345 | - case "partial" : |
|
346 | - $v_extract_all = false; |
|
347 | - $v_listing = false; |
|
348 | - break; |
|
349 | - case "list" : |
|
350 | - $v_extract_all = false; |
|
351 | - $v_listing = true; |
|
352 | - break; |
|
353 | - default : |
|
354 | - $this->_error('Invalid extract mode ('.$p_mode.')'); |
|
355 | - return false; |
|
356 | - } |
|
357 | - |
|
358 | - clearstatcache(); |
|
359 | - |
|
360 | - while (strlen($v_binary_data = $this->_readBlock()) != 0) |
|
361 | - { |
|
362 | - $v_extract_file = false; |
|
363 | - $v_extraction_stopped = 0; |
|
364 | - |
|
365 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
366 | - return false; |
|
367 | - |
|
368 | - if ($v_header['filename'] == '') { |
|
369 | - continue; |
|
370 | - } |
|
371 | - |
|
372 | - // ----- Look for long filename |
|
373 | - if ($v_header['typeflag'] == 'L') { |
|
374 | - if (!$this->_readLongHeader($v_header)) |
|
375 | - return false; |
|
376 | - } |
|
377 | - |
|
378 | - if ((!$v_extract_all) && (is_array($p_file_list))) { |
|
379 | - // ----- By default no unzip if the file is not found |
|
380 | - $v_extract_file = false; |
|
381 | - |
|
382 | - for ($i=0; $i<sizeof($p_file_list); $i++) { |
|
383 | - // ----- Look if it is a directory |
|
384 | - if (substr($p_file_list[$i], -1) == '/') { |
|
385 | - // ----- Look if the directory is in the filename path |
|
386 | - if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
387 | - && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) |
|
388 | - == $p_file_list[$i])) { |
|
389 | - $v_extract_file = true; |
|
390 | - break; |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - // ----- It is a file, so compare the file names |
|
395 | - elseif ($p_file_list[$i] == $v_header['filename']) { |
|
396 | - $v_extract_file = true; |
|
397 | - break; |
|
398 | - } |
|
399 | - } |
|
400 | - } else { |
|
401 | - $v_extract_file = true; |
|
402 | - } |
|
403 | - |
|
404 | - // ----- Look if this file need to be extracted |
|
405 | - if (($v_extract_file) && (!$v_listing)) |
|
406 | - { |
|
407 | - if (($p_remove_path != '') |
|
408 | - && (substr($v_header['filename'], 0, $p_remove_path_size) |
|
409 | - == $p_remove_path)) |
|
410 | - $v_header['filename'] = substr($v_header['filename'], |
|
411 | - $p_remove_path_size); |
|
412 | - if (($p_path != './') && ($p_path != '/')) { |
|
413 | - while (substr($p_path, -1) == '/') |
|
414 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
415 | - |
|
416 | - if (substr($v_header['filename'], 0, 1) == '/') |
|
417 | - $v_header['filename'] = $p_path.$v_header['filename']; |
|
418 | - else |
|
419 | - $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
|
420 | - } |
|
421 | - if (file_exists($v_header['filename'])) { |
|
422 | - if ( (@is_dir($v_header['filename'])) |
|
423 | - && ($v_header['typeflag'] == '')) { |
|
424 | - $this->_error('File '.$v_header['filename'] |
|
425 | - .' already exists as a directory'); |
|
426 | - return false; |
|
427 | - } |
|
428 | - if ( ($this->_isArchive($v_header['filename'])) |
|
429 | - && ($v_header['typeflag'] == "5")) { |
|
430 | - $this->_error('Directory '.$v_header['filename'] |
|
431 | - .' already exists as a file'); |
|
432 | - return false; |
|
433 | - } |
|
434 | - if (!is_writeable($v_header['filename'])) { |
|
435 | - $this->_error('File '.$v_header['filename'] |
|
436 | - .' already exists and is write protected'); |
|
437 | - return false; |
|
438 | - } |
|
439 | - if (filemtime($v_header['filename']) > $v_header['mtime']) { |
|
440 | - // To be completed : An error or silent no replace ? |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - // ----- Check the directory availability and create it if necessary |
|
445 | - elseif (($v_result |
|
446 | - = $this->_dirCheck(($v_header['typeflag'] == "5" |
|
447 | - ?$v_header['filename'] |
|
280 | + return false; |
|
281 | + } |
|
282 | + |
|
283 | + // ----- Extract the properties |
|
284 | + $v_header['filename'] = trim($v_data['filename']); |
|
285 | + $v_header['mode'] = OctDec(trim($v_data['mode'])); |
|
286 | + $v_header['uid'] = OctDec(trim($v_data['uid'])); |
|
287 | + $v_header['gid'] = OctDec(trim($v_data['gid'])); |
|
288 | + $v_header['size'] = OctDec(trim($v_data['size'])); |
|
289 | + $v_header['mtime'] = OctDec(trim($v_data['mtime'])); |
|
290 | + if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { |
|
291 | + $v_header['size'] = 0; |
|
292 | + } |
|
293 | + return true; |
|
294 | + } |
|
295 | + |
|
296 | + private function _readLongHeader(&$v_header) |
|
297 | + { |
|
298 | + $v_filename = ''; |
|
299 | + $n = floor($v_header['size']/512); |
|
300 | + for ($i=0; $i<$n; $i++) { |
|
301 | + $v_content = $this->_readBlock(); |
|
302 | + $v_filename .= $v_content; |
|
303 | + } |
|
304 | + if (($v_header['size'] % 512) != 0) { |
|
305 | + $v_content = $this->_readBlock(); |
|
306 | + $v_filename .= $v_content; |
|
307 | + } |
|
308 | + |
|
309 | + // ----- Read the next header |
|
310 | + $v_binary_data = $this->_readBlock(); |
|
311 | + |
|
312 | + if (!$this->_readHeader($v_binary_data, $v_header)) |
|
313 | + return false; |
|
314 | + |
|
315 | + $v_header['filename'] = $v_filename; |
|
316 | + |
|
317 | + return true; |
|
318 | + } |
|
319 | + |
|
320 | + protected function _extractList($p_path, &$p_list_detail, $p_mode, |
|
321 | + $p_file_list, $p_remove_path) |
|
322 | + { |
|
323 | + $v_result=true; |
|
324 | + $v_nb = 0; |
|
325 | + $v_extract_all = true; |
|
326 | + $v_listing = false; |
|
327 | + |
|
328 | + $p_path = $this->_translateWinPath($p_path, false); |
|
329 | + if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
|
330 | + && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
|
331 | + $p_path = "./".$p_path; |
|
332 | + } |
|
333 | + $p_remove_path = $this->_translateWinPath($p_remove_path); |
|
334 | + |
|
335 | + // ----- Look for path to remove format (should end by /) |
|
336 | + if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) |
|
337 | + $p_remove_path .= '/'; |
|
338 | + $p_remove_path_size = strlen($p_remove_path); |
|
339 | + |
|
340 | + switch ($p_mode) { |
|
341 | + case "complete" : |
|
342 | + $v_extract_all = true; |
|
343 | + $v_listing = false; |
|
344 | + break; |
|
345 | + case "partial" : |
|
346 | + $v_extract_all = false; |
|
347 | + $v_listing = false; |
|
348 | + break; |
|
349 | + case "list" : |
|
350 | + $v_extract_all = false; |
|
351 | + $v_listing = true; |
|
352 | + break; |
|
353 | + default : |
|
354 | + $this->_error('Invalid extract mode ('.$p_mode.')'); |
|
355 | + return false; |
|
356 | + } |
|
357 | + |
|
358 | + clearstatcache(); |
|
359 | + |
|
360 | + while (strlen($v_binary_data = $this->_readBlock()) != 0) |
|
361 | + { |
|
362 | + $v_extract_file = false; |
|
363 | + $v_extraction_stopped = 0; |
|
364 | + |
|
365 | + if (!$this->_readHeader($v_binary_data, $v_header)) |
|
366 | + return false; |
|
367 | + |
|
368 | + if ($v_header['filename'] == '') { |
|
369 | + continue; |
|
370 | + } |
|
371 | + |
|
372 | + // ----- Look for long filename |
|
373 | + if ($v_header['typeflag'] == 'L') { |
|
374 | + if (!$this->_readLongHeader($v_header)) |
|
375 | + return false; |
|
376 | + } |
|
377 | + |
|
378 | + if ((!$v_extract_all) && (is_array($p_file_list))) { |
|
379 | + // ----- By default no unzip if the file is not found |
|
380 | + $v_extract_file = false; |
|
381 | + |
|
382 | + for ($i=0; $i<sizeof($p_file_list); $i++) { |
|
383 | + // ----- Look if it is a directory |
|
384 | + if (substr($p_file_list[$i], -1) == '/') { |
|
385 | + // ----- Look if the directory is in the filename path |
|
386 | + if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
387 | + && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) |
|
388 | + == $p_file_list[$i])) { |
|
389 | + $v_extract_file = true; |
|
390 | + break; |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + // ----- It is a file, so compare the file names |
|
395 | + elseif ($p_file_list[$i] == $v_header['filename']) { |
|
396 | + $v_extract_file = true; |
|
397 | + break; |
|
398 | + } |
|
399 | + } |
|
400 | + } else { |
|
401 | + $v_extract_file = true; |
|
402 | + } |
|
403 | + |
|
404 | + // ----- Look if this file need to be extracted |
|
405 | + if (($v_extract_file) && (!$v_listing)) |
|
406 | + { |
|
407 | + if (($p_remove_path != '') |
|
408 | + && (substr($v_header['filename'], 0, $p_remove_path_size) |
|
409 | + == $p_remove_path)) |
|
410 | + $v_header['filename'] = substr($v_header['filename'], |
|
411 | + $p_remove_path_size); |
|
412 | + if (($p_path != './') && ($p_path != '/')) { |
|
413 | + while (substr($p_path, -1) == '/') |
|
414 | + $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
415 | + |
|
416 | + if (substr($v_header['filename'], 0, 1) == '/') |
|
417 | + $v_header['filename'] = $p_path.$v_header['filename']; |
|
418 | + else |
|
419 | + $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
|
420 | + } |
|
421 | + if (file_exists($v_header['filename'])) { |
|
422 | + if ( (@is_dir($v_header['filename'])) |
|
423 | + && ($v_header['typeflag'] == '')) { |
|
424 | + $this->_error('File '.$v_header['filename'] |
|
425 | + .' already exists as a directory'); |
|
426 | + return false; |
|
427 | + } |
|
428 | + if ( ($this->_isArchive($v_header['filename'])) |
|
429 | + && ($v_header['typeflag'] == "5")) { |
|
430 | + $this->_error('Directory '.$v_header['filename'] |
|
431 | + .' already exists as a file'); |
|
432 | + return false; |
|
433 | + } |
|
434 | + if (!is_writeable($v_header['filename'])) { |
|
435 | + $this->_error('File '.$v_header['filename'] |
|
436 | + .' already exists and is write protected'); |
|
437 | + return false; |
|
438 | + } |
|
439 | + if (filemtime($v_header['filename']) > $v_header['mtime']) { |
|
440 | + // To be completed : An error or silent no replace ? |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + // ----- Check the directory availability and create it if necessary |
|
445 | + elseif (($v_result |
|
446 | + = $this->_dirCheck(($v_header['typeflag'] == "5" |
|
447 | + ?$v_header['filename'] |
|
448 | 448 | :dirname($v_header['filename'])))) != 1) { |
449 | - $this->_error('Unable to create path for '.$v_header['filename']); |
|
450 | - return false; |
|
451 | - } |
|
452 | - |
|
453 | - if ($v_extract_file) { |
|
454 | - if ($v_header['typeflag'] == "5") { |
|
455 | - if (!@file_exists($v_header['filename'])) { |
|
456 | - if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
457 | - $this->_error('Unable to create directory {' |
|
458 | - .$v_header['filename'].'}'); |
|
459 | - return false; |
|
460 | - } |
|
461 | - chmod($v_header['filename'], PRADO_CHMOD); |
|
462 | - } |
|
463 | - } else { |
|
464 | - if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
|
465 | - $this->_error('Error while opening {'.$v_header['filename'] |
|
466 | - .'} in write binary mode'); |
|
467 | - return false; |
|
468 | - } else { |
|
469 | - $n = floor($v_header['size']/512); |
|
470 | - for ($i=0; $i<$n; $i++) { |
|
471 | - $v_content = $this->_readBlock(); |
|
472 | - fwrite($v_dest_file, $v_content, 512); |
|
473 | - } |
|
474 | - if (($v_header['size'] % 512) != 0) { |
|
475 | - $v_content = $this->_readBlock(); |
|
476 | - fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); |
|
477 | - } |
|
478 | - |
|
479 | - @fclose($v_dest_file); |
|
480 | - |
|
481 | - // ----- Change the file mode, mtime |
|
482 | - @touch($v_header['filename'], $v_header['mtime']); |
|
483 | - // To be completed |
|
484 | - //chmod($v_header[filename], DecOct($v_header[mode])); |
|
485 | - } |
|
486 | - |
|
487 | - // ----- Check the file size |
|
488 | - clearstatcache(); |
|
489 | - if (filesize($v_header['filename']) != $v_header['size']) { |
|
490 | - $this->_error('Extracted file '.$v_header['filename'] |
|
491 | - .' does not have the correct file size \'' |
|
449 | + $this->_error('Unable to create path for '.$v_header['filename']); |
|
450 | + return false; |
|
451 | + } |
|
452 | + |
|
453 | + if ($v_extract_file) { |
|
454 | + if ($v_header['typeflag'] == "5") { |
|
455 | + if (!@file_exists($v_header['filename'])) { |
|
456 | + if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
457 | + $this->_error('Unable to create directory {' |
|
458 | + .$v_header['filename'].'}'); |
|
459 | + return false; |
|
460 | + } |
|
461 | + chmod($v_header['filename'], PRADO_CHMOD); |
|
462 | + } |
|
463 | + } else { |
|
464 | + if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
|
465 | + $this->_error('Error while opening {'.$v_header['filename'] |
|
466 | + .'} in write binary mode'); |
|
467 | + return false; |
|
468 | + } else { |
|
469 | + $n = floor($v_header['size']/512); |
|
470 | + for ($i=0; $i<$n; $i++) { |
|
471 | + $v_content = $this->_readBlock(); |
|
472 | + fwrite($v_dest_file, $v_content, 512); |
|
473 | + } |
|
474 | + if (($v_header['size'] % 512) != 0) { |
|
475 | + $v_content = $this->_readBlock(); |
|
476 | + fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); |
|
477 | + } |
|
478 | + |
|
479 | + @fclose($v_dest_file); |
|
480 | + |
|
481 | + // ----- Change the file mode, mtime |
|
482 | + @touch($v_header['filename'], $v_header['mtime']); |
|
483 | + // To be completed |
|
484 | + //chmod($v_header[filename], DecOct($v_header[mode])); |
|
485 | + } |
|
486 | + |
|
487 | + // ----- Check the file size |
|
488 | + clearstatcache(); |
|
489 | + if (filesize($v_header['filename']) != $v_header['size']) { |
|
490 | + $this->_error('Extracted file '.$v_header['filename'] |
|
491 | + .' does not have the correct file size \'' |
|
492 | 492 | .filesize($v_header['filename']) |
493 | 493 | .'\' ('.$v_header['size'] |
494 | 494 | .' expected). Archive may be corrupted.'); |
495 | - return false; |
|
496 | - } |
|
497 | - } |
|
498 | - } else { |
|
499 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
500 | - } |
|
501 | - } else { |
|
502 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
503 | - } |
|
504 | - |
|
505 | - /* TBC : Seems to be unused ... |
|
495 | + return false; |
|
496 | + } |
|
497 | + } |
|
498 | + } else { |
|
499 | + $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
500 | + } |
|
501 | + } else { |
|
502 | + $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
503 | + } |
|
504 | + |
|
505 | + /* TBC : Seems to be unused ... |
|
506 | 506 | if ($this->_compress) |
507 | 507 | $v_end_of_file = @gzeof($this->_file); |
508 | 508 | else |
509 | 509 | $v_end_of_file = @feof($this->_file); |
510 | 510 | */ |
511 | 511 | |
512 | - if ($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
513 | - // ----- Log extracted files |
|
514 | - if (($v_file_dir = dirname($v_header['filename'])) |
|
515 | - == $v_header['filename']) |
|
516 | - $v_file_dir = ''; |
|
517 | - if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) |
|
518 | - $v_file_dir = '/'; |
|
519 | - |
|
520 | - $p_list_detail[$v_nb++] = $v_header; |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - return true; |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Check if a directory exists and create it (including parent |
|
529 | - * dirs) if not. |
|
530 | - * |
|
531 | - * @param string $p_dir directory to check |
|
532 | - * |
|
533 | - * @return bool true if the directory exists or was created |
|
534 | - */ |
|
535 | - protected function _dirCheck($p_dir) |
|
536 | - { |
|
537 | - if ((@is_dir($p_dir)) || ($p_dir == '')) |
|
538 | - return true; |
|
539 | - |
|
540 | - $p_parent_dir = dirname($p_dir); |
|
541 | - |
|
542 | - if (($p_parent_dir != $p_dir) && |
|
543 | - ($p_parent_dir != '') && |
|
544 | - (!$this->_dirCheck($p_parent_dir))) |
|
545 | - return false; |
|
546 | - |
|
547 | - if (!@mkdir($p_dir, PRADO_CHMOD)) { |
|
548 | - $this->_error("Unable to create directory '$p_dir'"); |
|
549 | - return false; |
|
550 | - } |
|
551 | - chmod($p_dir,PRADO_CHMOD); |
|
552 | - |
|
553 | - return true; |
|
554 | - } |
|
555 | - |
|
556 | - protected function _translateWinPath($p_path, $p_remove_disk_letter=true) |
|
557 | - { |
|
558 | - if (substr(PHP_OS, 0, 3) == 'WIN') { |
|
559 | - // ----- Look for potential disk letter |
|
560 | - if ( ($p_remove_disk_letter) |
|
561 | - && (($v_position = strpos($p_path, ':')) != false)) { |
|
562 | - $p_path = substr($p_path, $v_position+1); |
|
563 | - } |
|
564 | - // ----- Change potential windows directory separator |
|
565 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
566 | - $p_path = strtr($p_path, '\\', '/'); |
|
567 | - } |
|
568 | - } |
|
569 | - return $p_path; |
|
570 | - } |
|
512 | + if ($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
513 | + // ----- Log extracted files |
|
514 | + if (($v_file_dir = dirname($v_header['filename'])) |
|
515 | + == $v_header['filename']) |
|
516 | + $v_file_dir = ''; |
|
517 | + if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) |
|
518 | + $v_file_dir = '/'; |
|
519 | + |
|
520 | + $p_list_detail[$v_nb++] = $v_header; |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + return true; |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Check if a directory exists and create it (including parent |
|
529 | + * dirs) if not. |
|
530 | + * |
|
531 | + * @param string $p_dir directory to check |
|
532 | + * |
|
533 | + * @return bool true if the directory exists or was created |
|
534 | + */ |
|
535 | + protected function _dirCheck($p_dir) |
|
536 | + { |
|
537 | + if ((@is_dir($p_dir)) || ($p_dir == '')) |
|
538 | + return true; |
|
539 | + |
|
540 | + $p_parent_dir = dirname($p_dir); |
|
541 | + |
|
542 | + if (($p_parent_dir != $p_dir) && |
|
543 | + ($p_parent_dir != '') && |
|
544 | + (!$this->_dirCheck($p_parent_dir))) |
|
545 | + return false; |
|
546 | + |
|
547 | + if (!@mkdir($p_dir, PRADO_CHMOD)) { |
|
548 | + $this->_error("Unable to create directory '$p_dir'"); |
|
549 | + return false; |
|
550 | + } |
|
551 | + chmod($p_dir,PRADO_CHMOD); |
|
552 | + |
|
553 | + return true; |
|
554 | + } |
|
555 | + |
|
556 | + protected function _translateWinPath($p_path, $p_remove_disk_letter=true) |
|
557 | + { |
|
558 | + if (substr(PHP_OS, 0, 3) == 'WIN') { |
|
559 | + // ----- Look for potential disk letter |
|
560 | + if ( ($p_remove_disk_letter) |
|
561 | + && (($v_position = strpos($p_path, ':')) != false)) { |
|
562 | + $p_path = substr($p_path, $v_position+1); |
|
563 | + } |
|
564 | + // ----- Change potential windows directory separator |
|
565 | + if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
566 | + $p_path = strtr($p_path, '\\', '/'); |
|
567 | + } |
|
568 | + } |
|
569 | + return $p_path; |
|
570 | + } |
|
571 | 571 | } |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * @var string Name of the Tar |
40 | 40 | */ |
41 | - private $_tarname=''; |
|
41 | + private $_tarname = ''; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @var file descriptor |
45 | 45 | */ |
46 | - private $_file=0; |
|
46 | + private $_file = 0; |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * @var string Local Tar name of a remote Tar (http:// or ftp://) |
50 | 50 | */ |
51 | - private $_temp_tarname=''; |
|
51 | + private $_temp_tarname = ''; |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Archive_Tar Class constructor. This flavour of the constructor only |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | @unlink($this->_temp_tarname); |
72 | 72 | } |
73 | 73 | |
74 | - public function extract($p_path='') |
|
74 | + public function extract($p_path = '') |
|
75 | 75 | { |
76 | 76 | return $this->extractModify($p_path, ''); |
77 | 77 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | throw new Exception($p_message); |
128 | 128 | } |
129 | 129 | |
130 | - private function _isArchive($p_filename=null) |
|
130 | + private function _isArchive($p_filename = null) |
|
131 | 131 | { |
132 | 132 | if ($p_filename == null) { |
133 | 133 | $p_filename = $this->_tarname; |
@@ -142,16 +142,16 @@ discard block |
||
142 | 142 | |
143 | 143 | // ----- Look if a local copy need to be done |
144 | 144 | if ($this->_temp_tarname == '') { |
145 | - $this->_temp_tarname = uniqid('tar').'.tmp'; |
|
145 | + $this->_temp_tarname = uniqid('tar') . '.tmp'; |
|
146 | 146 | if (!$v_file_from = @fopen($this->_tarname, 'rb')) { |
147 | 147 | $this->_error('Unable to open in read mode \'' |
148 | - .$this->_tarname.'\''); |
|
148 | + .$this->_tarname . '\''); |
|
149 | 149 | $this->_temp_tarname = ''; |
150 | 150 | return false; |
151 | 151 | } |
152 | 152 | if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { |
153 | 153 | $this->_error('Unable to open in write mode \'' |
154 | - .$this->_temp_tarname.'\''); |
|
154 | + .$this->_temp_tarname . '\''); |
|
155 | 155 | $this->_temp_tarname = ''; |
156 | 156 | return false; |
157 | 157 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $this->_file = @fopen($v_filename, "rb"); |
172 | 172 | |
173 | 173 | if ($this->_file == 0) { |
174 | - $this->_error('Unable to open in read mode \''.$v_filename.'\''); |
|
174 | + $this->_error('Unable to open in read mode \'' . $v_filename . '\''); |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | |
@@ -224,41 +224,41 @@ discard block |
||
224 | 224 | return $v_block; |
225 | 225 | } |
226 | 226 | |
227 | - private function _jumpBlock($p_len=null) |
|
227 | + private function _jumpBlock($p_len = null) |
|
228 | 228 | { |
229 | 229 | if (is_resource($this->_file)) { |
230 | 230 | if ($p_len === null) |
231 | 231 | $p_len = 1; |
232 | 232 | |
233 | - @fseek($this->_file, @ftell($this->_file)+($p_len*512)); |
|
233 | + @fseek($this->_file, @ftell($this->_file) + ($p_len * 512)); |
|
234 | 234 | } |
235 | 235 | return true; |
236 | 236 | } |
237 | 237 | |
238 | 238 | private function _readHeader($v_binary_data, &$v_header) |
239 | 239 | { |
240 | - if (strlen($v_binary_data)==0) { |
|
240 | + if (strlen($v_binary_data) == 0) { |
|
241 | 241 | $v_header['filename'] = ''; |
242 | 242 | return true; |
243 | 243 | } |
244 | 244 | |
245 | 245 | if (strlen($v_binary_data) != 512) { |
246 | 246 | $v_header['filename'] = ''; |
247 | - $this->_error('Invalid block size : '.strlen($v_binary_data)); |
|
247 | + $this->_error('Invalid block size : ' . strlen($v_binary_data)); |
|
248 | 248 | return false; |
249 | 249 | } |
250 | 250 | |
251 | 251 | // ----- Calculate the checksum |
252 | 252 | $v_checksum = 0; |
253 | 253 | // ..... First part of the header |
254 | - for ($i=0; $i<148; $i++) |
|
255 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
254 | + for ($i = 0; $i < 148; $i++) |
|
255 | + $v_checksum += ord(substr($v_binary_data, $i, 1)); |
|
256 | 256 | // ..... Ignore the checksum value and replace it by ' ' (space) |
257 | - for ($i=148; $i<156; $i++) |
|
257 | + for ($i = 148; $i < 156; $i++) |
|
258 | 258 | $v_checksum += ord(' '); |
259 | 259 | // ..... Last part of the header |
260 | - for ($i=156; $i<512; $i++) |
|
261 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
260 | + for ($i = 156; $i < 512; $i++) |
|
261 | + $v_checksum += ord(substr($v_binary_data, $i, 1)); |
|
262 | 262 | |
263 | 263 | $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
264 | 264 | ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | if (($v_checksum == 256) && ($v_header['checksum'] == 0)) |
275 | 275 | return true; |
276 | 276 | |
277 | - $this->_error('Invalid checksum for file "'.$v_data['filename'] |
|
278 | - .'" : '.$v_checksum.' calculated, ' |
|
279 | - .$v_header['checksum'].' expected'); |
|
277 | + $this->_error('Invalid checksum for file "' . $v_data['filename'] |
|
278 | + .'" : ' . $v_checksum . ' calculated, ' |
|
279 | + .$v_header['checksum'] . ' expected'); |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | private function _readLongHeader(&$v_header) |
297 | 297 | { |
298 | 298 | $v_filename = ''; |
299 | - $n = floor($v_header['size']/512); |
|
300 | - for ($i=0; $i<$n; $i++) { |
|
299 | + $n = floor($v_header['size'] / 512); |
|
300 | + for ($i = 0; $i < $n; $i++) { |
|
301 | 301 | $v_content = $this->_readBlock(); |
302 | 302 | $v_filename .= $v_content; |
303 | 303 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | protected function _extractList($p_path, &$p_list_detail, $p_mode, |
321 | 321 | $p_file_list, $p_remove_path) |
322 | 322 | { |
323 | - $v_result=true; |
|
323 | + $v_result = true; |
|
324 | 324 | $v_nb = 0; |
325 | 325 | $v_extract_all = true; |
326 | 326 | $v_listing = false; |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | $p_path = $this->_translateWinPath($p_path, false); |
329 | 329 | if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
330 | 330 | && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
331 | - $p_path = "./".$p_path; |
|
331 | + $p_path = "./" . $p_path; |
|
332 | 332 | } |
333 | 333 | $p_remove_path = $this->_translateWinPath($p_remove_path); |
334 | 334 | |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | $v_listing = true; |
352 | 352 | break; |
353 | 353 | default : |
354 | - $this->_error('Invalid extract mode ('.$p_mode.')'); |
|
354 | + $this->_error('Invalid extract mode (' . $p_mode . ')'); |
|
355 | 355 | return false; |
356 | 356 | } |
357 | 357 | |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | // ----- By default no unzip if the file is not found |
380 | 380 | $v_extract_file = false; |
381 | 381 | |
382 | - for ($i=0; $i<sizeof($p_file_list); $i++) { |
|
382 | + for ($i = 0; $i < sizeof($p_file_list); $i++) { |
|
383 | 383 | // ----- Look if it is a directory |
384 | 384 | if (substr($p_file_list[$i], -1) == '/') { |
385 | 385 | // ----- Look if the directory is in the filename path |
@@ -411,28 +411,28 @@ discard block |
||
411 | 411 | $p_remove_path_size); |
412 | 412 | if (($p_path != './') && ($p_path != '/')) { |
413 | 413 | while (substr($p_path, -1) == '/') |
414 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
414 | + $p_path = substr($p_path, 0, strlen($p_path) - 1); |
|
415 | 415 | |
416 | 416 | if (substr($v_header['filename'], 0, 1) == '/') |
417 | - $v_header['filename'] = $p_path.$v_header['filename']; |
|
417 | + $v_header['filename'] = $p_path . $v_header['filename']; |
|
418 | 418 | else |
419 | - $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
|
419 | + $v_header['filename'] = $p_path . '/' . $v_header['filename']; |
|
420 | 420 | } |
421 | 421 | if (file_exists($v_header['filename'])) { |
422 | - if ( (@is_dir($v_header['filename'])) |
|
422 | + if ((@is_dir($v_header['filename'])) |
|
423 | 423 | && ($v_header['typeflag'] == '')) { |
424 | - $this->_error('File '.$v_header['filename'] |
|
424 | + $this->_error('File ' . $v_header['filename'] |
|
425 | 425 | .' already exists as a directory'); |
426 | 426 | return false; |
427 | 427 | } |
428 | - if ( ($this->_isArchive($v_header['filename'])) |
|
428 | + if (($this->_isArchive($v_header['filename'])) |
|
429 | 429 | && ($v_header['typeflag'] == "5")) { |
430 | - $this->_error('Directory '.$v_header['filename'] |
|
430 | + $this->_error('Directory ' . $v_header['filename'] |
|
431 | 431 | .' already exists as a file'); |
432 | 432 | return false; |
433 | 433 | } |
434 | 434 | if (!is_writeable($v_header['filename'])) { |
435 | - $this->_error('File '.$v_header['filename'] |
|
435 | + $this->_error('File ' . $v_header['filename'] |
|
436 | 436 | .' already exists and is write protected'); |
437 | 437 | return false; |
438 | 438 | } |
@@ -444,9 +444,9 @@ discard block |
||
444 | 444 | // ----- Check the directory availability and create it if necessary |
445 | 445 | elseif (($v_result |
446 | 446 | = $this->_dirCheck(($v_header['typeflag'] == "5" |
447 | - ?$v_header['filename'] |
|
447 | + ? $v_header['filename'] |
|
448 | 448 | :dirname($v_header['filename'])))) != 1) { |
449 | - $this->_error('Unable to create path for '.$v_header['filename']); |
|
449 | + $this->_error('Unable to create path for ' . $v_header['filename']); |
|
450 | 450 | return false; |
451 | 451 | } |
452 | 452 | |
@@ -455,19 +455,19 @@ discard block |
||
455 | 455 | if (!@file_exists($v_header['filename'])) { |
456 | 456 | if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
457 | 457 | $this->_error('Unable to create directory {' |
458 | - .$v_header['filename'].'}'); |
|
458 | + .$v_header['filename'] . '}'); |
|
459 | 459 | return false; |
460 | 460 | } |
461 | 461 | chmod($v_header['filename'], PRADO_CHMOD); |
462 | 462 | } |
463 | 463 | } else { |
464 | 464 | if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
465 | - $this->_error('Error while opening {'.$v_header['filename'] |
|
465 | + $this->_error('Error while opening {' . $v_header['filename'] |
|
466 | 466 | .'} in write binary mode'); |
467 | 467 | return false; |
468 | 468 | } else { |
469 | - $n = floor($v_header['size']/512); |
|
470 | - for ($i=0; $i<$n; $i++) { |
|
469 | + $n = floor($v_header['size'] / 512); |
|
470 | + for ($i = 0; $i < $n; $i++) { |
|
471 | 471 | $v_content = $this->_readBlock(); |
472 | 472 | fwrite($v_dest_file, $v_content, 512); |
473 | 473 | } |
@@ -487,19 +487,19 @@ discard block |
||
487 | 487 | // ----- Check the file size |
488 | 488 | clearstatcache(); |
489 | 489 | if (filesize($v_header['filename']) != $v_header['size']) { |
490 | - $this->_error('Extracted file '.$v_header['filename'] |
|
490 | + $this->_error('Extracted file ' . $v_header['filename'] |
|
491 | 491 | .' does not have the correct file size \'' |
492 | 492 | .filesize($v_header['filename']) |
493 | - .'\' ('.$v_header['size'] |
|
493 | + .'\' (' . $v_header['size'] |
|
494 | 494 | .' expected). Archive may be corrupted.'); |
495 | 495 | return false; |
496 | 496 | } |
497 | 497 | } |
498 | 498 | } else { |
499 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
499 | + $this->_jumpBlock(ceil(($v_header['size'] / 512))); |
|
500 | 500 | } |
501 | 501 | } else { |
502 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
502 | + $this->_jumpBlock(ceil(($v_header['size'] / 512))); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /* TBC : Seems to be unused ... |
@@ -548,21 +548,21 @@ discard block |
||
548 | 548 | $this->_error("Unable to create directory '$p_dir'"); |
549 | 549 | return false; |
550 | 550 | } |
551 | - chmod($p_dir,PRADO_CHMOD); |
|
551 | + chmod($p_dir, PRADO_CHMOD); |
|
552 | 552 | |
553 | 553 | return true; |
554 | 554 | } |
555 | 555 | |
556 | - protected function _translateWinPath($p_path, $p_remove_disk_letter=true) |
|
556 | + protected function _translateWinPath($p_path, $p_remove_disk_letter = true) |
|
557 | 557 | { |
558 | 558 | if (substr(PHP_OS, 0, 3) == 'WIN') { |
559 | 559 | // ----- Look for potential disk letter |
560 | - if ( ($p_remove_disk_letter) |
|
560 | + if (($p_remove_disk_letter) |
|
561 | 561 | && (($v_position = strpos($p_path, ':')) != false)) { |
562 | - $p_path = substr($p_path, $v_position+1); |
|
562 | + $p_path = substr($p_path, $v_position + 1); |
|
563 | 563 | } |
564 | 564 | // ----- Change potential windows directory separator |
565 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
565 | + if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1) == '\\')) { |
|
566 | 566 | $p_path = strtr($p_path, '\\', '/'); |
567 | 567 | } |
568 | 568 | } |
@@ -155,8 +155,9 @@ discard block |
||
155 | 155 | $this->_temp_tarname = ''; |
156 | 156 | return false; |
157 | 157 | } |
158 | - while ($v_data = @fread($v_file_from, 1024)) |
|
159 | - @fwrite($v_file_to, $v_data); |
|
158 | + while ($v_data = @fread($v_file_from, 1024)) { |
|
159 | + @fwrite($v_file_to, $v_data); |
|
160 | + } |
|
160 | 161 | @fclose($v_file_from); |
161 | 162 | @fclose($v_file_to); |
162 | 163 | } |
@@ -251,14 +252,17 @@ discard block |
||
251 | 252 | // ----- Calculate the checksum |
252 | 253 | $v_checksum = 0; |
253 | 254 | // ..... First part of the header |
254 | - for ($i=0; $i<148; $i++) |
|
255 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
255 | + for ($i=0; $i<148; $i++) { |
|
256 | + $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
257 | + } |
|
256 | 258 | // ..... Ignore the checksum value and replace it by ' ' (space) |
257 | - for ($i=148; $i<156; $i++) |
|
258 | - $v_checksum += ord(' '); |
|
259 | + for ($i=148; $i<156; $i++) { |
|
260 | + $v_checksum += ord(' '); |
|
261 | + } |
|
259 | 262 | // ..... Last part of the header |
260 | - for ($i=156; $i<512; $i++) |
|
261 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
263 | + for ($i=156; $i<512; $i++) { |
|
264 | + $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
265 | + } |
|
262 | 266 | |
263 | 267 | $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
264 | 268 | ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
@@ -410,8 +414,9 @@ discard block |
||
410 | 414 | $v_header['filename'] = substr($v_header['filename'], |
411 | 415 | $p_remove_path_size); |
412 | 416 | if (($p_path != './') && ($p_path != '/')) { |
413 | - while (substr($p_path, -1) == '/') |
|
414 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
417 | + while (substr($p_path, -1) == '/') { |
|
418 | + $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
419 | + } |
|
415 | 420 | |
416 | 421 | if (substr($v_header['filename'], 0, 1) == '/') |
417 | 422 | $v_header['filename'] = $p_path.$v_header['filename']; |
@@ -184,6 +184,7 @@ |
||
184 | 184 | * will cause the throw of an exception. |
185 | 185 | * This method should only be used by framework developers. |
186 | 186 | * @param TApplication the application instance |
187 | + * @param TApplication $application |
|
187 | 188 | * @throws TInvalidOperationException if this method is invoked twice or more. |
188 | 189 | */ |
189 | 190 | public static function setApplication($application) |
@@ -18,8 +18,8 @@ |
||
18 | 18 | if(!defined('PRADO_DIR')) |
19 | 19 | define('PRADO_DIR',dirname(__FILE__)); |
20 | 20 | /** |
21 | - * Defines the default permission for writable directories and files |
|
22 | - */ |
|
21 | + * Defines the default permission for writable directories and files |
|
22 | + */ |
|
23 | 23 | if(!defined('PRADO_CHMOD')) |
24 | 24 | define('PRADO_CHMOD',0777); |
25 | 25 |
@@ -116,8 +116,7 @@ discard block |
||
116 | 116 | { |
117 | 117 | $am=self::$_application->getAssetManager(); |
118 | 118 | $url=$am->publishFilePath(self::getPathOfNamespace('System.'.$logoName,'.gif')); |
119 | - } |
|
120 | - else |
|
119 | + } else |
|
121 | 120 | $url='http://pradosoft.github.io/docs/'.$logoName.'.gif'; |
122 | 121 | return '<a title="Powered by PRADO" href="https://github.com/pradosoft/prado" target="_blank"><img src="'.$url.'" style="border-width:0px;" alt="Powered by PRADO" /></a>'; |
123 | 122 | } |
@@ -169,8 +168,7 @@ discard block |
||
169 | 168 | if(self::$_application!==null && ($errorHandler=self::$_application->getErrorHandler())!==null) |
170 | 169 | { |
171 | 170 | $errorHandler->handleError(null,$exception); |
172 | - } |
|
173 | - else |
|
171 | + } else |
|
174 | 172 | { |
175 | 173 | echo $exception; |
176 | 174 | } |
@@ -253,14 +251,14 @@ discard block |
||
253 | 251 | break; |
254 | 252 | default: |
255 | 253 | $s='$args[1]'; |
256 | - for($i=2;$i<$n;++$i) |
|
257 | - $s.=",\$args[$i]"; |
|
254 | + for($i=2;$i<$n;++$i) { |
|
255 | + $s.=",\$args[$i]"; |
|
256 | + } |
|
258 | 257 | eval("\$component=new $type($s);"); |
259 | 258 | return $component; |
260 | 259 | break; |
261 | 260 | } |
262 | - } |
|
263 | - else |
|
261 | + } else |
|
264 | 262 | return new $type; |
265 | 263 | } |
266 | 264 | |
@@ -282,24 +280,21 @@ discard block |
||
282 | 280 | try |
283 | 281 | { |
284 | 282 | include_once($namespace.self::CLASS_FILE_EXT); |
285 | - } |
|
286 | - catch(Exception $e) |
|
283 | + } catch(Exception $e) |
|
287 | 284 | { |
288 | 285 | if($checkClassExistence && !class_exists($namespace,false)) |
289 | 286 | throw new TInvalidOperationException('prado_component_unknown',$namespace,$e->getMessage()); |
290 | 287 | else |
291 | 288 | throw $e; |
292 | 289 | } |
293 | - } |
|
294 | - else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null) |
|
290 | + } else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null) |
|
295 | 291 | { |
296 | 292 | $className=substr($namespace,$pos+1); |
297 | 293 | if($className==='*') // a directory |
298 | 294 | { |
299 | 295 | self::$_usings[$namespace]=$path; |
300 | 296 | set_include_path(get_include_path().PATH_SEPARATOR.$path); |
301 | - } |
|
302 | - else // a file |
|
297 | + } else // a file |
|
303 | 298 | { |
304 | 299 | self::$_usings[$namespace]=$path; |
305 | 300 | if(!$checkClassExistence || !class_exists($className,false)) |
@@ -307,8 +302,7 @@ discard block |
||
307 | 302 | try |
308 | 303 | { |
309 | 304 | include_once($path); |
310 | - } |
|
311 | - catch(Exception $e) |
|
305 | + } catch(Exception $e) |
|
312 | 306 | { |
313 | 307 | if($checkClassExistence && !class_exists($className,false)) |
314 | 308 | throw new TInvalidOperationException('prado_component_unknown',$className,$e->getMessage()); |
@@ -317,8 +311,7 @@ discard block |
||
317 | 311 | } |
318 | 312 | } |
319 | 313 | } |
320 | - } |
|
321 | - else |
|
314 | + } else |
|
322 | 315 | throw new TInvalidDataValueException('prado_using_invalid',$namespace); |
323 | 316 | } |
324 | 317 | |
@@ -384,8 +377,7 @@ discard block |
||
384 | 377 | self::$_aliases[$alias]=$rp; |
385 | 378 | else |
386 | 379 | throw new TInvalidDataValueException('prado_aliasname_invalid',$alias); |
387 | - } |
|
388 | - else |
|
380 | + } else |
|
389 | 381 | throw new TInvalidDataValueException('prado_alias_invalid',$alias,$path); |
390 | 382 | } |
391 | 383 | |
@@ -430,8 +422,7 @@ discard block |
||
430 | 422 | echo "'". substr($str, 0, 70) . "...'"; |
431 | 423 | else |
432 | 424 | echo "'" . $str . "'"; |
433 | - } |
|
434 | - else if (is_int($item) || is_float($item)) |
|
425 | + } else if (is_int($item) || is_float($item)) |
|
435 | 426 | echo $item; |
436 | 427 | else if (is_object($item)) |
437 | 428 | echo get_class($item); |
@@ -526,8 +517,7 @@ discard block |
||
526 | 517 | if(isset($trace[0]['file']) && isset($trace[0]['line'])) |
527 | 518 | $msg.=" (line {$trace[0]['line']}, {$trace[0]['file']})"; |
528 | 519 | $level=TLogger::DEBUG; |
529 | - } |
|
530 | - else |
|
520 | + } else |
|
531 | 521 | $level=TLogger::INFO; |
532 | 522 | self::log($msg,$level,$category,$ctl); |
533 | 523 | } |
@@ -592,8 +582,9 @@ discard block |
||
592 | 582 | $app = Prado::getApplication()->getGlobalization(false); |
593 | 583 | |
594 | 584 | $params = array(); |
595 | - foreach($parameters as $key => $value) |
|
596 | - $params['{'.$key.'}'] = $value; |
|
585 | + foreach($parameters as $key => $value) { |
|
586 | + $params['{'.$key.'}'] = $value; |
|
587 | + } |
|
597 | 588 | |
598 | 589 | //no translation handler provided |
599 | 590 | if($app===null || ($config = $app->getTranslationConfiguration())===null) |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Defines the PRADO framework installation path. |
17 | 17 | */ |
18 | -if(!defined('PRADO_DIR')) |
|
19 | - define('PRADO_DIR',dirname(__FILE__)); |
|
18 | +if (!defined('PRADO_DIR')) |
|
19 | + define('PRADO_DIR', dirname(__FILE__)); |
|
20 | 20 | /** |
21 | 21 | * Defines the default permission for writable directories and files |
22 | 22 | */ |
23 | -if(!defined('PRADO_CHMOD')) |
|
24 | - define('PRADO_CHMOD',0777); |
|
23 | +if (!defined('PRADO_CHMOD')) |
|
24 | + define('PRADO_CHMOD', 0777); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * PradoBase class. |
@@ -41,23 +41,23 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * File extension for Prado class files. |
43 | 43 | */ |
44 | - const CLASS_FILE_EXT='.php'; |
|
44 | + const CLASS_FILE_EXT = '.php'; |
|
45 | 45 | /** |
46 | 46 | * @var array list of path aliases |
47 | 47 | */ |
48 | - private static $_aliases=array('System'=>PRADO_DIR); |
|
48 | + private static $_aliases = array('System'=>PRADO_DIR); |
|
49 | 49 | /** |
50 | 50 | * @var array list of namespaces currently in use |
51 | 51 | */ |
52 | - private static $_usings=array(); |
|
52 | + private static $_usings = array(); |
|
53 | 53 | /** |
54 | 54 | * @var TApplication the application instance |
55 | 55 | */ |
56 | - private static $_application=null; |
|
56 | + private static $_application = null; |
|
57 | 57 | /** |
58 | 58 | * @var TLogger logger instance |
59 | 59 | */ |
60 | - private static $_logger=null; |
|
60 | + private static $_logger = null; |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @var array list of class exists checks |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * Sets error handler to be Prado::phpErrorHandler |
84 | 84 | */ |
85 | - set_error_handler(array('PradoBase','phpErrorHandler')); |
|
85 | + set_error_handler(array('PradoBase', 'phpErrorHandler')); |
|
86 | 86 | /** |
87 | 87 | * Sets shutdown function to be Prado::phpFatalErrorHandler |
88 | 88 | */ |
89 | - register_shutdown_function(array('PradoBase','phpFatalErrorHandler')); |
|
89 | + register_shutdown_function(array('PradoBase', 'phpFatalErrorHandler')); |
|
90 | 90 | /** |
91 | 91 | * Sets exception handler to be Prado::exceptionHandler |
92 | 92 | */ |
93 | - set_exception_handler(array('PradoBase','exceptionHandler')); |
|
93 | + set_exception_handler(array('PradoBase', 'exceptionHandler')); |
|
94 | 94 | /** |
95 | 95 | * Disable php's builtin error reporting to avoid duplicated reports |
96 | 96 | */ |
@@ -104,24 +104,24 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public static function autoload($className) |
106 | 106 | { |
107 | - @include_once($className.self::CLASS_FILE_EXT); |
|
107 | + @include_once($className . self::CLASS_FILE_EXT); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * @param integer the type of "powered logo". Valid values include 0 and 1. |
112 | 112 | * @return string a string that can be displayed on your Web page showing powered-by-PRADO information |
113 | 113 | */ |
114 | - public static function poweredByPrado($logoType=0) |
|
114 | + public static function poweredByPrado($logoType = 0) |
|
115 | 115 | { |
116 | - $logoName=$logoType==1?'powered2':'powered'; |
|
117 | - if(self::$_application!==null) |
|
116 | + $logoName = $logoType == 1 ? 'powered2' : 'powered'; |
|
117 | + if (self::$_application !== null) |
|
118 | 118 | { |
119 | - $am=self::$_application->getAssetManager(); |
|
120 | - $url=$am->publishFilePath(self::getPathOfNamespace('System.'.$logoName,'.gif')); |
|
119 | + $am = self::$_application->getAssetManager(); |
|
120 | + $url = $am->publishFilePath(self::getPathOfNamespace('System.' . $logoName, '.gif')); |
|
121 | 121 | } |
122 | 122 | else |
123 | - $url='http://pradosoft.github.io/docs/'.$logoName.'.gif'; |
|
124 | - return '<a title="Powered by PRADO" href="https://github.com/pradosoft/prado" target="_blank"><img src="'.$url.'" style="border-width:0px;" alt="Powered by PRADO" /></a>'; |
|
123 | + $url = 'http://pradosoft.github.io/docs/' . $logoName . '.gif'; |
|
124 | + return '<a title="Powered by PRADO" href="https://github.com/pradosoft/prado" target="_blank"><img src="' . $url . '" style="border-width:0px;" alt="Powered by PRADO" /></a>'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | * @param string the filename that the error was raised in |
135 | 135 | * @param integer the line number the error was raised at |
136 | 136 | */ |
137 | - public static function phpErrorHandler($errno,$errstr,$errfile,$errline) |
|
137 | + public static function phpErrorHandler($errno, $errstr, $errfile, $errline) |
|
138 | 138 | { |
139 | - if(error_reporting() & $errno) |
|
140 | - throw new TPhpErrorException($errno,$errstr,$errfile,$errline); |
|
139 | + if (error_reporting() & $errno) |
|
140 | + throw new TPhpErrorException($errno, $errstr, $errfile, $errline); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | public static function phpFatalErrorHandler() |
150 | 150 | { |
151 | 151 | $error = error_get_last(); |
152 | - if($error && |
|
152 | + if ($error && |
|
153 | 153 | TPhpErrorException::isFatalError($error) && |
154 | 154 | error_reporting() & $error['type']) |
155 | 155 | { |
156 | - self::exceptionHandler(new TPhpErrorException($error['type'],$error['message'],$error['file'],$error['line'])); |
|
156 | + self::exceptionHandler(new TPhpErrorException($error['type'], $error['message'], $error['file'], $error['line'])); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public static function exceptionHandler($exception) |
170 | 170 | { |
171 | - if(self::$_application!==null && ($errorHandler=self::$_application->getErrorHandler())!==null) |
|
171 | + if (self::$_application !== null && ($errorHandler = self::$_application->getErrorHandler()) !== null) |
|
172 | 172 | { |
173 | - $errorHandler->handleError(null,$exception); |
|
173 | + $errorHandler->handleError(null, $exception); |
|
174 | 174 | } |
175 | 175 | else |
176 | 176 | { |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public static function setApplication($application) |
192 | 192 | { |
193 | - if(self::$_application!==null && !defined('PRADO_TEST_RUN')) |
|
193 | + if (self::$_application !== null && !defined('PRADO_TEST_RUN')) |
|
194 | 194 | throw new TInvalidOperationException('prado_application_singleton_required'); |
195 | - self::$_application=$application; |
|
195 | + self::$_application = $application; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -226,21 +226,21 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public static function createComponent($type) |
228 | 228 | { |
229 | - if(!isset(self::$classExists[$type])) |
|
229 | + if (!isset(self::$classExists[$type])) |
|
230 | 230 | self::$classExists[$type] = class_exists($type, false); |
231 | 231 | |
232 | - if( !isset(self::$_usings[$type]) && !self::$classExists[$type]) { |
|
232 | + if (!isset(self::$_usings[$type]) && !self::$classExists[$type]) { |
|
233 | 233 | self::using($type); |
234 | 234 | self::$classExists[$type] = class_exists($type, false); |
235 | 235 | } |
236 | 236 | |
237 | - if( ($pos = strrpos($type, '.')) !== false) |
|
238 | - $type = substr($type,$pos+1); |
|
237 | + if (($pos = strrpos($type, '.')) !== false) |
|
238 | + $type = substr($type, $pos + 1); |
|
239 | 239 | |
240 | - if(($n=func_num_args())>1) |
|
240 | + if (($n = func_num_args()) > 1) |
|
241 | 241 | { |
242 | 242 | $args = func_get_args(); |
243 | - switch($n) { |
|
243 | + switch ($n) { |
|
244 | 244 | case 2: |
245 | 245 | return new $type($args[1]); |
246 | 246 | break; |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | return new $type($args[1], $args[2], $args[3], $args[4]); |
255 | 255 | break; |
256 | 256 | default: |
257 | - $s='$args[1]'; |
|
258 | - for($i=2;$i<$n;++$i) |
|
259 | - $s.=",\$args[$i]"; |
|
257 | + $s = '$args[1]'; |
|
258 | + for ($i = 2; $i < $n; ++$i) |
|
259 | + $s .= ",\$args[$i]"; |
|
260 | 260 | eval("\$component=new $type($s);"); |
261 | 261 | return $component; |
262 | 262 | break; |
@@ -275,45 +275,45 @@ discard block |
||
275 | 275 | * @param boolean whether to check the existence of the class after the class file is included |
276 | 276 | * @throws TInvalidDataValueException if the namespace is invalid |
277 | 277 | */ |
278 | - public static function using($namespace,$checkClassExistence=true) |
|
278 | + public static function using($namespace, $checkClassExistence = true) |
|
279 | 279 | { |
280 | - if(isset(self::$_usings[$namespace]) || class_exists($namespace,false)) |
|
280 | + if (isset(self::$_usings[$namespace]) || class_exists($namespace, false)) |
|
281 | 281 | return; |
282 | - if(($pos=strrpos($namespace,'.'))===false) // a class name |
|
282 | + if (($pos = strrpos($namespace, '.')) === false) // a class name |
|
283 | 283 | { |
284 | 284 | try |
285 | 285 | { |
286 | - include_once($namespace.self::CLASS_FILE_EXT); |
|
286 | + include_once($namespace . self::CLASS_FILE_EXT); |
|
287 | 287 | } |
288 | - catch(Exception $e) |
|
288 | + catch (Exception $e) |
|
289 | 289 | { |
290 | - if($checkClassExistence && !class_exists($namespace,false)) |
|
291 | - throw new TInvalidOperationException('prado_component_unknown',$namespace,$e->getMessage()); |
|
290 | + if ($checkClassExistence && !class_exists($namespace, false)) |
|
291 | + throw new TInvalidOperationException('prado_component_unknown', $namespace, $e->getMessage()); |
|
292 | 292 | else |
293 | 293 | throw $e; |
294 | 294 | } |
295 | 295 | } |
296 | - else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null) |
|
296 | + else if (($path = self::getPathOfNamespace($namespace, self::CLASS_FILE_EXT)) !== null) |
|
297 | 297 | { |
298 | - $className=substr($namespace,$pos+1); |
|
299 | - if($className==='*') // a directory |
|
298 | + $className = substr($namespace, $pos + 1); |
|
299 | + if ($className === '*') // a directory |
|
300 | 300 | { |
301 | - self::$_usings[$namespace]=$path; |
|
302 | - set_include_path(get_include_path().PATH_SEPARATOR.$path); |
|
301 | + self::$_usings[$namespace] = $path; |
|
302 | + set_include_path(get_include_path() . PATH_SEPARATOR . $path); |
|
303 | 303 | } |
304 | 304 | else // a file |
305 | 305 | { |
306 | - self::$_usings[$namespace]=$path; |
|
307 | - if(!$checkClassExistence || !class_exists($className,false)) |
|
306 | + self::$_usings[$namespace] = $path; |
|
307 | + if (!$checkClassExistence || !class_exists($className, false)) |
|
308 | 308 | { |
309 | 309 | try |
310 | 310 | { |
311 | 311 | include_once($path); |
312 | 312 | } |
313 | - catch(Exception $e) |
|
313 | + catch (Exception $e) |
|
314 | 314 | { |
315 | - if($checkClassExistence && !class_exists($className,false)) |
|
316 | - throw new TInvalidOperationException('prado_component_unknown',$className,$e->getMessage()); |
|
315 | + if ($checkClassExistence && !class_exists($className, false)) |
|
316 | + throw new TInvalidOperationException('prado_component_unknown', $className, $e->getMessage()); |
|
317 | 317 | else |
318 | 318 | throw $e; |
319 | 319 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | } |
322 | 322 | } |
323 | 323 | else |
324 | - throw new TInvalidDataValueException('prado_using_invalid',$namespace); |
|
324 | + throw new TInvalidDataValueException('prado_using_invalid', $namespace); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -336,22 +336,22 @@ discard block |
||
336 | 336 | * @param string extension to be appended if the namespace refers to a file |
337 | 337 | * @return string file path corresponding to the namespace, null if namespace is invalid |
338 | 338 | */ |
339 | - public static function getPathOfNamespace($namespace, $ext='') |
|
339 | + public static function getPathOfNamespace($namespace, $ext = '') |
|
340 | 340 | { |
341 | - if(self::CLASS_FILE_EXT === $ext || empty($ext)) |
|
341 | + if (self::CLASS_FILE_EXT === $ext || empty($ext)) |
|
342 | 342 | { |
343 | - if(isset(self::$_usings[$namespace])) |
|
343 | + if (isset(self::$_usings[$namespace])) |
|
344 | 344 | return self::$_usings[$namespace]; |
345 | 345 | |
346 | - if(isset(self::$_aliases[$namespace])) |
|
346 | + if (isset(self::$_aliases[$namespace])) |
|
347 | 347 | return self::$_aliases[$namespace]; |
348 | 348 | } |
349 | 349 | |
350 | - $segs = explode('.',$namespace); |
|
350 | + $segs = explode('.', $namespace); |
|
351 | 351 | $alias = array_shift($segs); |
352 | 352 | |
353 | - if(null !== ($file = array_pop($segs)) && null !== ($root = self::getPathOfAlias($alias))) |
|
354 | - return rtrim($root.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR ,$segs),'/\\').(($file === '*') ? '' : DIRECTORY_SEPARATOR.$file.$ext); |
|
353 | + if (null !== ($file = array_pop($segs)) && null !== ($root = self::getPathOfAlias($alias))) |
|
354 | + return rtrim($root . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $segs), '/\\') . (($file === '*') ? '' : DIRECTORY_SEPARATOR . $file . $ext); |
|
355 | 355 | |
356 | 356 | return null; |
357 | 357 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | */ |
363 | 363 | public static function getPathOfAlias($alias) |
364 | 364 | { |
365 | - return isset(self::$_aliases[$alias])?self::$_aliases[$alias]:null; |
|
365 | + return isset(self::$_aliases[$alias]) ?self::$_aliases[$alias] : null; |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | protected static function getPathAliases() |
@@ -376,19 +376,19 @@ discard block |
||
376 | 376 | * @throws TInvalidOperationException if the alias is already defined |
377 | 377 | * @throws TInvalidDataValueException if the path is not a valid file path |
378 | 378 | */ |
379 | - public static function setPathOfAlias($alias,$path) |
|
379 | + public static function setPathOfAlias($alias, $path) |
|
380 | 380 | { |
381 | - if(isset(self::$_aliases[$alias]) && !defined('PRADO_TEST_RUN')) |
|
382 | - throw new TInvalidOperationException('prado_alias_redefined',$alias); |
|
383 | - else if(($rp=realpath($path))!==false && is_dir($rp)) |
|
381 | + if (isset(self::$_aliases[$alias]) && !defined('PRADO_TEST_RUN')) |
|
382 | + throw new TInvalidOperationException('prado_alias_redefined', $alias); |
|
383 | + else if (($rp = realpath($path)) !== false && is_dir($rp)) |
|
384 | 384 | { |
385 | - if(strpos($alias,'.')===false) |
|
386 | - self::$_aliases[$alias]=$rp; |
|
385 | + if (strpos($alias, '.') === false) |
|
386 | + self::$_aliases[$alias] = $rp; |
|
387 | 387 | else |
388 | - throw new TInvalidDataValueException('prado_aliasname_invalid',$alias); |
|
388 | + throw new TInvalidDataValueException('prado_aliasname_invalid', $alias); |
|
389 | 389 | } |
390 | 390 | else |
391 | - throw new TInvalidDataValueException('prado_alias_invalid',$alias,$path); |
|
391 | + throw new TInvalidDataValueException('prado_alias_invalid', $alias, $path); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -400,36 +400,36 @@ discard block |
||
400 | 400 | public static function fatalError($msg) |
401 | 401 | { |
402 | 402 | echo '<h1>Fatal Error</h1>'; |
403 | - echo '<p>'.$msg.'</p>'; |
|
404 | - if(!function_exists('debug_backtrace')) |
|
403 | + echo '<p>' . $msg . '</p>'; |
|
404 | + if (!function_exists('debug_backtrace')) |
|
405 | 405 | return; |
406 | 406 | echo '<h2>Debug Backtrace</h2>'; |
407 | 407 | echo '<pre>'; |
408 | - $index=-1; |
|
409 | - foreach(debug_backtrace() as $t) |
|
408 | + $index = -1; |
|
409 | + foreach (debug_backtrace() as $t) |
|
410 | 410 | { |
411 | 411 | $index++; |
412 | - if($index==0) // hide the backtrace of this function |
|
412 | + if ($index == 0) // hide the backtrace of this function |
|
413 | 413 | continue; |
414 | - echo '#'.$index.' '; |
|
415 | - if(isset($t['file'])) |
|
414 | + echo '#' . $index . ' '; |
|
415 | + if (isset($t['file'])) |
|
416 | 416 | echo basename($t['file']) . ':' . $t['line']; |
417 | 417 | else |
418 | 418 | echo '<PHP inner-code>'; |
419 | 419 | echo ' -- '; |
420 | - if(isset($t['class'])) |
|
420 | + if (isset($t['class'])) |
|
421 | 421 | echo $t['class'] . $t['type']; |
422 | 422 | echo $t['function'] . '('; |
423 | - if(isset($t['args']) && sizeof($t['args']) > 0) |
|
423 | + if (isset($t['args']) && sizeof($t['args']) > 0) |
|
424 | 424 | { |
425 | - $count=0; |
|
426 | - foreach($t['args'] as $item) |
|
425 | + $count = 0; |
|
426 | + foreach ($t['args'] as $item) |
|
427 | 427 | { |
428 | - if(is_string($item)) |
|
428 | + if (is_string($item)) |
|
429 | 429 | { |
430 | - $str=htmlentities(str_replace("\r\n", "", $item), ENT_QUOTES); |
|
430 | + $str = htmlentities(str_replace("\r\n", "", $item), ENT_QUOTES); |
|
431 | 431 | if (strlen($item) > 70) |
432 | - echo "'". substr($str, 0, 70) . "...'"; |
|
432 | + echo "'" . substr($str, 0, 70) . "...'"; |
|
433 | 433 | else |
434 | 434 | echo "'" . $str . "'"; |
435 | 435 | } |
@@ -465,23 +465,23 @@ discard block |
||
465 | 465 | */ |
466 | 466 | public static function getUserLanguages() |
467 | 467 | { |
468 | - static $languages=null; |
|
469 | - if($languages===null) |
|
468 | + static $languages = null; |
|
469 | + if ($languages === null) |
|
470 | 470 | { |
471 | - if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) |
|
472 | - $languages[0]='en'; |
|
471 | + if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) |
|
472 | + $languages[0] = 'en'; |
|
473 | 473 | else |
474 | 474 | { |
475 | - $languages=array(); |
|
476 | - foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language) |
|
475 | + $languages = array(); |
|
476 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language) |
|
477 | 477 | { |
478 | - $array=explode(';q=',trim($language)); |
|
479 | - $languages[trim($array[0])]=isset($array[1])?(float)$array[1]:1.0; |
|
478 | + $array = explode(';q=', trim($language)); |
|
479 | + $languages[trim($array[0])] = isset($array[1]) ? (float) $array[1] : 1.0; |
|
480 | 480 | } |
481 | 481 | arsort($languages); |
482 | - $languages=array_keys($languages); |
|
483 | - if(empty($languages)) |
|
484 | - $languages[0]='en'; |
|
482 | + $languages = array_keys($languages); |
|
483 | + if (empty($languages)) |
|
484 | + $languages[0] = 'en'; |
|
485 | 485 | } |
486 | 486 | } |
487 | 487 | return $languages; |
@@ -493,15 +493,15 @@ discard block |
||
493 | 493 | */ |
494 | 494 | public static function getPreferredLanguage() |
495 | 495 | { |
496 | - static $language=null; |
|
497 | - if($language===null) |
|
496 | + static $language = null; |
|
497 | + if ($language === null) |
|
498 | 498 | { |
499 | - $langs=Prado::getUserLanguages(); |
|
500 | - $lang=explode('-',$langs[0]); |
|
501 | - if(empty($lang[0]) || !ctype_alpha($lang[0])) |
|
502 | - $language='en'; |
|
499 | + $langs = Prado::getUserLanguages(); |
|
500 | + $lang = explode('-', $langs[0]); |
|
501 | + if (empty($lang[0]) || !ctype_alpha($lang[0])) |
|
502 | + $language = 'en'; |
|
503 | 503 | else |
504 | - $language=$lang[0]; |
|
504 | + $language = $lang[0]; |
|
505 | 505 | } |
506 | 506 | return $language; |
507 | 507 | } |
@@ -518,20 +518,20 @@ discard block |
||
518 | 518 | * @param (string|TControl) control of the message |
519 | 519 | * @see log, getLogger |
520 | 520 | */ |
521 | - public static function trace($msg,$category='Uncategorized',$ctl=null) |
|
521 | + public static function trace($msg, $category = 'Uncategorized', $ctl = null) |
|
522 | 522 | { |
523 | - if(self::$_application && self::$_application->getMode()===TApplicationMode::Performance) |
|
523 | + if (self::$_application && self::$_application->getMode() === TApplicationMode::Performance) |
|
524 | 524 | return; |
525 | - if(!self::$_application || self::$_application->getMode()===TApplicationMode::Debug) |
|
525 | + if (!self::$_application || self::$_application->getMode() === TApplicationMode::Debug) |
|
526 | 526 | { |
527 | - $trace=debug_backtrace(); |
|
528 | - if(isset($trace[0]['file']) && isset($trace[0]['line'])) |
|
529 | - $msg.=" (line {$trace[0]['line']}, {$trace[0]['file']})"; |
|
530 | - $level=TLogger::DEBUG; |
|
527 | + $trace = debug_backtrace(); |
|
528 | + if (isset($trace[0]['file']) && isset($trace[0]['line'])) |
|
529 | + $msg .= " (line {$trace[0]['line']}, {$trace[0]['file']})"; |
|
530 | + $level = TLogger::DEBUG; |
|
531 | 531 | } |
532 | 532 | else |
533 | - $level=TLogger::INFO; |
|
534 | - self::log($msg,$level,$category,$ctl); |
|
533 | + $level = TLogger::INFO; |
|
534 | + self::log($msg, $level, $category, $ctl); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
@@ -546,11 +546,11 @@ discard block |
||
546 | 546 | * @param string category of the message |
547 | 547 | * @param (string|TControl) control of the message |
548 | 548 | */ |
549 | - public static function log($msg,$level=TLogger::INFO,$category='Uncategorized',$ctl=null) |
|
549 | + public static function log($msg, $level = TLogger::INFO, $category = 'Uncategorized', $ctl = null) |
|
550 | 550 | { |
551 | - if(self::$_logger===null) |
|
552 | - self::$_logger=new TLogger; |
|
553 | - self::$_logger->log($msg,$level,$category,$ctl); |
|
551 | + if (self::$_logger === null) |
|
552 | + self::$_logger = new TLogger; |
|
553 | + self::$_logger->log($msg, $level, $category, $ctl); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -558,8 +558,8 @@ discard block |
||
558 | 558 | */ |
559 | 559 | public static function getLogger() |
560 | 560 | { |
561 | - if(self::$_logger===null) |
|
562 | - self::$_logger=new TLogger; |
|
561 | + if (self::$_logger === null) |
|
562 | + self::$_logger = new TLogger; |
|
563 | 563 | return self::$_logger; |
564 | 564 | } |
565 | 565 | |
@@ -572,10 +572,10 @@ discard block |
||
572 | 572 | * @param boolean whether to syntax highlight the output. Defaults to false. |
573 | 573 | * @return string the string representation of the variable |
574 | 574 | */ |
575 | - public static function varDump($var,$depth=10,$highlight=false) |
|
575 | + public static function varDump($var, $depth = 10, $highlight = false) |
|
576 | 576 | { |
577 | 577 | Prado::using('System.Util.TVarDumper'); |
578 | - return TVarDumper::dump($var,$depth,$highlight); |
|
578 | + return TVarDumper::dump($var, $depth, $highlight); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
@@ -588,35 +588,35 @@ discard block |
||
588 | 588 | * @see TTranslate::formatter() |
589 | 589 | * @see TTranslate::init() |
590 | 590 | */ |
591 | - public static function localize($text, $parameters=array(), $catalogue=null, $charset=null) |
|
591 | + public static function localize($text, $parameters = array(), $catalogue = null, $charset = null) |
|
592 | 592 | { |
593 | 593 | Prado::using('System.I18N.Translation'); |
594 | 594 | $app = Prado::getApplication()->getGlobalization(false); |
595 | 595 | |
596 | 596 | $params = array(); |
597 | - foreach($parameters as $key => $value) |
|
598 | - $params['{'.$key.'}'] = $value; |
|
597 | + foreach ($parameters as $key => $value) |
|
598 | + $params['{' . $key . '}'] = $value; |
|
599 | 599 | |
600 | 600 | //no translation handler provided |
601 | - if($app===null || ($config = $app->getTranslationConfiguration())===null) |
|
601 | + if ($app === null || ($config = $app->getTranslationConfiguration()) === null) |
|
602 | 602 | return strtr($text, $params); |
603 | 603 | |
604 | - if ($catalogue===null) |
|
605 | - $catalogue=isset($config['catalogue'])?$config['catalogue']:'messages'; |
|
604 | + if ($catalogue === null) |
|
605 | + $catalogue = isset($config['catalogue']) ? $config['catalogue'] : 'messages'; |
|
606 | 606 | |
607 | 607 | Translation::init($catalogue); |
608 | 608 | |
609 | 609 | //globalization charset |
610 | - $appCharset = $app===null ? '' : $app->getCharset(); |
|
610 | + $appCharset = $app === null ? '' : $app->getCharset(); |
|
611 | 611 | |
612 | 612 | //default charset |
613 | - $defaultCharset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset(); |
|
613 | + $defaultCharset = ($app === null) ? 'UTF-8' : $app->getDefaultCharset(); |
|
614 | 614 | |
615 | 615 | //fall back |
616 | - if(empty($charset)) $charset = $appCharset; |
|
617 | - if(empty($charset)) $charset = $defaultCharset; |
|
616 | + if (empty($charset)) $charset = $appCharset; |
|
617 | + if (empty($charset)) $charset = $defaultCharset; |
|
618 | 618 | |
619 | - return Translation::formatter($catalogue)->format($text,$params,$catalogue,$charset); |
|
619 | + return Translation::formatter($catalogue)->format($text, $params, $catalogue, $charset); |
|
620 | 620 | } |
621 | 621 | } |
622 | 622 |
@@ -219,11 +219,17 @@ discard block |
||
219 | 219 | return 0; |
220 | 220 | } |
221 | 221 | |
222 | + /** |
|
223 | + * @param IUser $user |
|
224 | + */ |
|
222 | 225 | private function isUserMatched($user) |
223 | 226 | { |
224 | 227 | return ($this->_everyone || ($this->_guest && $user->getIsGuest()) || ($this->_authenticated && !$user->getIsGuest()) || in_array(strtolower($user->getName()),$this->_users)); |
225 | 228 | } |
226 | 229 | |
230 | + /** |
|
231 | + * @param IUser $user |
|
232 | + */ |
|
227 | 233 | private function isRoleMatched($user) |
228 | 234 | { |
229 | 235 | foreach($this->_roles as $role) |
@@ -256,6 +262,9 @@ discard block |
||
256 | 262 | * @param IUser the user to be authorized |
257 | 263 | * @param string verb, can be empty, 'post' or 'get'. |
258 | 264 | * @param string the request IP address |
265 | + * @param IUser $user |
|
266 | + * @param string $verb |
|
267 | + * @param string $ip |
|
259 | 268 | * @return boolean whether the user is allowed |
260 | 269 | */ |
261 | 270 | public function isUserAllowed($user,$verb,$ip) |
@@ -70,61 +70,61 @@ discard block |
||
70 | 70 | * @param string verb, can be empty, 'get', or 'post' |
71 | 71 | * @param string IP rules (separated by comma, can contain wild card *) |
72 | 72 | */ |
73 | - public function __construct($action,$users,$roles,$verb='',$ipRules='') |
|
73 | + public function __construct($action, $users, $roles, $verb = '', $ipRules = '') |
|
74 | 74 | { |
75 | - $action=strtolower(trim($action)); |
|
76 | - if($action==='allow' || $action==='deny') |
|
77 | - $this->_action=$action; |
|
75 | + $action = strtolower(trim($action)); |
|
76 | + if ($action === 'allow' || $action === 'deny') |
|
77 | + $this->_action = $action; |
|
78 | 78 | else |
79 | - throw new TInvalidDataValueException('authorizationrule_action_invalid',$action); |
|
80 | - $this->_users=array(); |
|
81 | - $this->_roles=array(); |
|
82 | - $this->_ipRules=array(); |
|
83 | - $this->_everyone=false; |
|
84 | - $this->_guest=false; |
|
85 | - $this->_authenticated=false; |
|
79 | + throw new TInvalidDataValueException('authorizationrule_action_invalid', $action); |
|
80 | + $this->_users = array(); |
|
81 | + $this->_roles = array(); |
|
82 | + $this->_ipRules = array(); |
|
83 | + $this->_everyone = false; |
|
84 | + $this->_guest = false; |
|
85 | + $this->_authenticated = false; |
|
86 | 86 | |
87 | - if(trim($users)==='') |
|
88 | - $users='*'; |
|
89 | - foreach(explode(',',$users) as $user) |
|
87 | + if (trim($users) === '') |
|
88 | + $users = '*'; |
|
89 | + foreach (explode(',', $users) as $user) |
|
90 | 90 | { |
91 | - if(($user=trim(strtolower($user)))!=='') |
|
91 | + if (($user = trim(strtolower($user))) !== '') |
|
92 | 92 | { |
93 | - if($user==='*') |
|
93 | + if ($user === '*') |
|
94 | 94 | { |
95 | - $this->_everyone=true; |
|
95 | + $this->_everyone = true; |
|
96 | 96 | break; |
97 | 97 | } |
98 | - else if($user==='?') |
|
99 | - $this->_guest=true; |
|
100 | - else if($user==='@') |
|
101 | - $this->_authenticated=true; |
|
98 | + else if ($user === '?') |
|
99 | + $this->_guest = true; |
|
100 | + else if ($user === '@') |
|
101 | + $this->_authenticated = true; |
|
102 | 102 | else |
103 | - $this->_users[]=$user; |
|
103 | + $this->_users[] = $user; |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | - if(trim($roles)==='') |
|
108 | - $roles='*'; |
|
109 | - foreach(explode(',',$roles) as $role) |
|
107 | + if (trim($roles) === '') |
|
108 | + $roles = '*'; |
|
109 | + foreach (explode(',', $roles) as $role) |
|
110 | 110 | { |
111 | - if(($role=trim(strtolower($role)))!=='') |
|
112 | - $this->_roles[]=$role; |
|
111 | + if (($role = trim(strtolower($role))) !== '') |
|
112 | + $this->_roles[] = $role; |
|
113 | 113 | } |
114 | 114 | |
115 | - if(($verb=trim(strtolower($verb)))==='') |
|
116 | - $verb='*'; |
|
117 | - if($verb==='*' || $verb==='get' || $verb==='post') |
|
118 | - $this->_verb=$verb; |
|
115 | + if (($verb = trim(strtolower($verb))) === '') |
|
116 | + $verb = '*'; |
|
117 | + if ($verb === '*' || $verb === 'get' || $verb === 'post') |
|
118 | + $this->_verb = $verb; |
|
119 | 119 | else |
120 | - throw new TInvalidDataValueException('authorizationrule_verb_invalid',$verb); |
|
120 | + throw new TInvalidDataValueException('authorizationrule_verb_invalid', $verb); |
|
121 | 121 | |
122 | - if(trim($ipRules)==='') |
|
123 | - $ipRules='*'; |
|
124 | - foreach(explode(',',$ipRules) as $ipRule) |
|
122 | + if (trim($ipRules) === '') |
|
123 | + $ipRules = '*'; |
|
124 | + foreach (explode(',', $ipRules) as $ipRule) |
|
125 | 125 | { |
126 | - if(($ipRule=trim($ipRule))!=='') |
|
127 | - $this->_ipRules[]=$ipRule; |
|
126 | + if (($ipRule = trim($ipRule)) !== '') |
|
127 | + $this->_ipRules[] = $ipRule; |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
@@ -199,21 +199,21 @@ discard block |
||
199 | 199 | * @param string the request IP address |
200 | 200 | * @return integer 1 if the user is allowed, -1 if the user is denied, 0 if the rule does not apply to the user |
201 | 201 | */ |
202 | - public function isUserAllowed(IUser $user,$verb,$ip) |
|
202 | + public function isUserAllowed(IUser $user, $verb, $ip) |
|
203 | 203 | { |
204 | - if($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user)) |
|
205 | - return ($this->_action==='allow')?1:-1; |
|
204 | + if ($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user)) |
|
205 | + return ($this->_action === 'allow') ? 1 : -1; |
|
206 | 206 | else |
207 | 207 | return 0; |
208 | 208 | } |
209 | 209 | |
210 | 210 | private function isIpMatched($ip) |
211 | 211 | { |
212 | - if(empty($this->_ipRules)) |
|
212 | + if (empty($this->_ipRules)) |
|
213 | 213 | return 1; |
214 | - foreach($this->_ipRules as $rule) |
|
214 | + foreach ($this->_ipRules as $rule) |
|
215 | 215 | { |
216 | - if($rule==='*' || $rule===$ip || (($pos=strpos($rule,'*'))!==false && strncmp($ip,$rule,$pos)===0)) |
|
216 | + if ($rule === '*' || $rule === $ip || (($pos = strpos($rule, '*')) !== false && strncmp($ip, $rule, $pos) === 0)) |
|
217 | 217 | return 1; |
218 | 218 | } |
219 | 219 | return 0; |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | |
222 | 222 | private function isUserMatched($user) |
223 | 223 | { |
224 | - return ($this->_everyone || ($this->_guest && $user->getIsGuest()) || ($this->_authenticated && !$user->getIsGuest()) || in_array(strtolower($user->getName()),$this->_users)); |
|
224 | + return ($this->_everyone || ($this->_guest && $user->getIsGuest()) || ($this->_authenticated && !$user->getIsGuest()) || in_array(strtolower($user->getName()), $this->_users)); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | private function isRoleMatched($user) |
228 | 228 | { |
229 | - foreach($this->_roles as $role) |
|
229 | + foreach ($this->_roles as $role) |
|
230 | 230 | { |
231 | - if($role==='*' || $user->isInRole($role)) |
|
231 | + if ($role === '*' || $user->isInRole($role)) |
|
232 | 232 | return true; |
233 | 233 | } |
234 | 234 | return false; |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | |
237 | 237 | private function isVerbMatched($verb) |
238 | 238 | { |
239 | - return ($this->_verb==='*' || strcasecmp($verb,$this->_verb)===0); |
|
239 | + return ($this->_verb === '*' || strcasecmp($verb, $this->_verb) === 0); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -258,15 +258,15 @@ discard block |
||
258 | 258 | * @param string the request IP address |
259 | 259 | * @return boolean whether the user is allowed |
260 | 260 | */ |
261 | - public function isUserAllowed($user,$verb,$ip) |
|
261 | + public function isUserAllowed($user, $verb, $ip) |
|
262 | 262 | { |
263 | - if($user instanceof IUser) |
|
263 | + if ($user instanceof IUser) |
|
264 | 264 | { |
265 | - $verb=strtolower(trim($verb)); |
|
266 | - foreach($this as $rule) |
|
265 | + $verb = strtolower(trim($verb)); |
|
266 | + foreach ($this as $rule) |
|
267 | 267 | { |
268 | - if(($decision=$rule->isUserAllowed($user,$verb,$ip))!==0) |
|
269 | - return ($decision>0); |
|
268 | + if (($decision = $rule->isUserAllowed($user, $verb, $ip)) !== 0) |
|
269 | + return ($decision > 0); |
|
270 | 270 | } |
271 | 271 | return true; |
272 | 272 | } |
@@ -282,10 +282,10 @@ discard block |
||
282 | 282 | * @param mixed new item |
283 | 283 | * @throws TInvalidDataTypeException if the item to be inserted is not a TAuthorizationRule object. |
284 | 284 | */ |
285 | - public function insertAt($index,$item) |
|
285 | + public function insertAt($index, $item) |
|
286 | 286 | { |
287 | - if($item instanceof TAuthorizationRule) |
|
288 | - parent::insertAt($index,$item); |
|
287 | + if ($item instanceof TAuthorizationRule) |
|
288 | + parent::insertAt($index, $item); |
|
289 | 289 | else |
290 | 290 | throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required'); |
291 | 291 | } |
@@ -94,8 +94,7 @@ discard block |
||
94 | 94 | { |
95 | 95 | $this->_everyone=true; |
96 | 96 | break; |
97 | - } |
|
98 | - else if($user==='?') |
|
97 | + } else if($user==='?') |
|
99 | 98 | $this->_guest=true; |
100 | 99 | else if($user==='@') |
101 | 100 | $this->_authenticated=true; |
@@ -269,8 +268,7 @@ discard block |
||
269 | 268 | return ($decision>0); |
270 | 269 | } |
271 | 270 | return true; |
272 | - } |
|
273 | - else |
|
271 | + } else |
|
274 | 272 | return false; |
275 | 273 | } |
276 | 274 |
@@ -163,6 +163,7 @@ |
||
163 | 163 | /** |
164 | 164 | * Creates the DB connection. |
165 | 165 | * @param string the module ID for TDataSourceConfig |
166 | + * @param string $connectionID |
|
166 | 167 | * @return TDbConnection the created DB connection |
167 | 168 | * @throws TConfigurationException if module ID is invalid or empty |
168 | 169 | */ |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | */ |
49 | 49 | class TDbUserManager extends TModule implements IUserManager |
50 | 50 | { |
51 | - private $_connID=''; |
|
51 | + private $_connID = ''; |
|
52 | 52 | private $_conn; |
53 | - private $_guestName='Guest'; |
|
54 | - private $_userClass=''; |
|
53 | + private $_guestName = 'Guest'; |
|
54 | + private $_userClass = ''; |
|
55 | 55 | private $_userFactory; |
56 | 56 | |
57 | 57 | /** |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function init($config) |
63 | 63 | { |
64 | - if($this->_userClass==='') |
|
64 | + if ($this->_userClass === '') |
|
65 | 65 | throw new TConfigurationException('dbusermanager_userclass_required'); |
66 | - $this->_userFactory=Prado::createComponent($this->_userClass,$this); |
|
67 | - if(!($this->_userFactory instanceof TDbUser)) |
|
68 | - throw new TInvalidDataTypeException('dbusermanager_userclass_invalid',$this->_userClass); |
|
66 | + $this->_userFactory = Prado::createComponent($this->_userClass, $this); |
|
67 | + if (!($this->_userFactory instanceof TDbUser)) |
|
68 | + throw new TInvalidDataTypeException('dbusermanager_userclass_invalid', $this->_userClass); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function setUserClass($value) |
83 | 83 | { |
84 | - $this->_userClass=$value; |
|
84 | + $this->_userClass = $value; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function setGuestName($value) |
99 | 99 | { |
100 | - $this->_guestName=$value; |
|
100 | + $this->_guestName = $value; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param string password |
107 | 107 | * @return boolean true if validation is successful, false otherwise. |
108 | 108 | */ |
109 | - public function validateUser($username,$password) |
|
109 | + public function validateUser($username, $password) |
|
110 | 110 | { |
111 | - return $this->_userFactory->validateUser($username,$password); |
|
111 | + return $this->_userFactory->validateUser($username, $password); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | * @param string user name, null if it is a guest. |
117 | 117 | * @return TUser the user instance, null if the specified username is not in the user database. |
118 | 118 | */ |
119 | - public function getUser($username=null) |
|
119 | + public function getUser($username = null) |
|
120 | 120 | { |
121 | - if($username===null) |
|
121 | + if ($username === null) |
|
122 | 122 | { |
123 | - $user=Prado::createComponent($this->_userClass,$this); |
|
123 | + $user = Prado::createComponent($this->_userClass, $this); |
|
124 | 124 | $user->setIsGuest(true); |
125 | 125 | return $user; |
126 | 126 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function setConnectionID($value) |
146 | 146 | { |
147 | - $this->_connID=$value; |
|
147 | + $this->_connID = $value; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function getDbConnection() |
154 | 154 | { |
155 | - if($this->_conn===null) |
|
155 | + if ($this->_conn === null) |
|
156 | 156 | { |
157 | - $this->_conn=$this->createDbConnection($this->_connID); |
|
157 | + $this->_conn = $this->createDbConnection($this->_connID); |
|
158 | 158 | $this->_conn->setActive(true); |
159 | 159 | } |
160 | 160 | return $this->_conn; |
@@ -168,13 +168,13 @@ discard block |
||
168 | 168 | */ |
169 | 169 | protected function createDbConnection($connectionID) |
170 | 170 | { |
171 | - if($connectionID!=='') |
|
171 | + if ($connectionID !== '') |
|
172 | 172 | { |
173 | - $conn=$this->getApplication()->getModule($connectionID); |
|
174 | - if($conn instanceof TDataSourceConfig) |
|
173 | + $conn = $this->getApplication()->getModule($connectionID); |
|
174 | + if ($conn instanceof TDataSourceConfig) |
|
175 | 175 | return $conn->getDbConnection(); |
176 | 176 | else |
177 | - throw new TConfigurationException('dbusermanager_connectionid_invalid',$connectionID); |
|
177 | + throw new TConfigurationException('dbusermanager_connectionid_invalid', $connectionID); |
|
178 | 178 | } |
179 | 179 | else |
180 | 180 | throw new TConfigurationException('dbusermanager_connectionid_required'); |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function saveUserToCookie($cookie) |
200 | 200 | { |
201 | - $user=$this->getApplication()->getUser(); |
|
202 | - if($user instanceof TDbUser) |
|
201 | + $user = $this->getApplication()->getUser(); |
|
202 | + if ($user instanceof TDbUser) |
|
203 | 203 | $user->saveUserToCookie($cookie); |
204 | 204 | } |
205 | 205 | } |
@@ -228,19 +228,19 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function getDbConnection() |
230 | 230 | { |
231 | - if($this->_connection===null) |
|
231 | + if ($this->_connection === null) |
|
232 | 232 | { |
233 | - $userManager=$this->getManager(); |
|
234 | - if($userManager instanceof TDbUserManager) |
|
233 | + $userManager = $this->getManager(); |
|
234 | + if ($userManager instanceof TDbUserManager) |
|
235 | 235 | { |
236 | - $connection=$userManager->getDbConnection(); |
|
237 | - if($connection instanceof TDbConnection) |
|
236 | + $connection = $userManager->getDbConnection(); |
|
237 | + if ($connection instanceof TDbConnection) |
|
238 | 238 | { |
239 | 239 | $connection->setActive(true); |
240 | - $this->_connection=$connection; |
|
240 | + $this->_connection = $connection; |
|
241 | 241 | } |
242 | 242 | } |
243 | - if($this->_connection===null) |
|
243 | + if ($this->_connection === null) |
|
244 | 244 | throw new TConfigurationException('dbuser_dbconnection_invalid'); |
245 | 245 | } |
246 | 246 | return $this->_connection; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @param string password |
256 | 256 | * @return boolean whether the validation succeeds |
257 | 257 | */ |
258 | - abstract public function validateUser($username,$password); |
|
258 | + abstract public function validateUser($username, $password); |
|
259 | 259 | |
260 | 260 | /** |
261 | 261 | * Creates a new user instance given the username. |
@@ -123,8 +123,7 @@ discard block |
||
123 | 123 | $user=Prado::createComponent($this->_userClass,$this); |
124 | 124 | $user->setIsGuest(true); |
125 | 125 | return $user; |
126 | - } |
|
127 | - else |
|
126 | + } else |
|
128 | 127 | return $this->_userFactory->createUser($username); |
129 | 128 | } |
130 | 129 | |
@@ -175,8 +174,7 @@ discard block |
||
175 | 174 | return $conn->getDbConnection(); |
176 | 175 | else |
177 | 176 | throw new TConfigurationException('dbusermanager_connectionid_invalid',$connectionID); |
178 | - } |
|
179 | - else |
|
177 | + } else |
|
180 | 178 | throw new TConfigurationException('dbusermanager_connectionid_required'); |
181 | 179 | } |
182 | 180 |
@@ -342,6 +342,7 @@ discard block |
||
342 | 342 | * to determine the application configuration file, |
343 | 343 | * application root path and the runtime path. |
344 | 344 | * @param string the application root path or the application configuration file |
345 | + * @param string $basePath |
|
345 | 346 | * @see setBasePath |
346 | 347 | * @see setRuntimePath |
347 | 348 | * @see setConfigurationFile |
@@ -440,6 +441,7 @@ discard block |
||
440 | 441 | * A global value is one that is persistent across users sessions and requests. |
441 | 442 | * @param string the name of the value to be returned |
442 | 443 | * @param mixed the default value. If $key is not found, $defaultValue will be returned |
444 | + * @param integer $defaultValue |
|
443 | 445 | * @return mixed the global value corresponding to $key |
444 | 446 | */ |
445 | 447 | public function getGlobalState($key,$defaultValue=null) |
@@ -456,6 +458,7 @@ discard block |
||
456 | 458 | * @param mixed the global value to be set |
457 | 459 | * @param mixed the default value. If $key is not found, $defaultValue will be returned |
458 | 460 | * @param boolean wheter to force an immediate GlobalState save. defaults to false |
461 | + * @param string $key |
|
459 | 462 | */ |
460 | 463 | public function setGlobalState($key,$value,$defaultValue=null,$forceSave=false) |
461 | 464 | { |
@@ -545,7 +548,7 @@ discard block |
||
545 | 548 | } |
546 | 549 | |
547 | 550 | /** |
548 | - * @return TApplicationMode application mode. Defaults to TApplicationMode::Debug. |
|
551 | + * @return string application mode. Defaults to TApplicationMode::Debug. |
|
549 | 552 | */ |
550 | 553 | public function getMode() |
551 | 554 | { |
@@ -570,6 +573,7 @@ discard block |
||
570 | 573 | |
571 | 574 | /** |
572 | 575 | * @param string the directory containing the application configuration file |
576 | + * @param string $value |
|
573 | 577 | */ |
574 | 578 | public function setBasePath($value) |
575 | 579 | { |
@@ -586,6 +590,7 @@ discard block |
||
586 | 590 | |
587 | 591 | /** |
588 | 592 | * @param string the application configuration file (absolute path) |
593 | + * @param string $value |
|
589 | 594 | */ |
590 | 595 | public function setConfigurationFile($value) |
591 | 596 | { |
@@ -602,6 +607,7 @@ discard block |
||
602 | 607 | |
603 | 608 | /** |
604 | 609 | * @param string the application configuration type. 'xml' and 'php' are valid values |
610 | + * @param string $value |
|
605 | 611 | */ |
606 | 612 | public function setConfigurationType($value) |
607 | 613 | { |
@@ -657,6 +663,7 @@ discard block |
||
657 | 663 | |
658 | 664 | /** |
659 | 665 | * @param string the directory storing cache data and application-level persistent data. (absolute path) |
666 | + * @param string $value |
|
660 | 667 | */ |
661 | 668 | public function setRuntimePath($value) |
662 | 669 | { |
@@ -677,6 +684,7 @@ discard block |
||
677 | 684 | |
678 | 685 | /** |
679 | 686 | * @param IService the currently requested service |
687 | + * @param IService $value |
|
680 | 688 | */ |
681 | 689 | public function setService($value) |
682 | 690 | { |
@@ -1126,6 +1134,7 @@ discard block |
||
1126 | 1134 | * This method is invoked when an exception is raised during the lifecycles |
1127 | 1135 | * of the application. |
1128 | 1136 | * @param mixed event parameter |
1137 | + * @param Exception $param |
|
1129 | 1138 | */ |
1130 | 1139 | public function onError($param) |
1131 | 1140 | { |
@@ -602,7 +602,7 @@ |
||
602 | 602 | |
603 | 603 | /** |
604 | 604 | * @param string the application configuration type. 'xml' and 'php' are valid values |
605 | - */ |
|
605 | + */ |
|
606 | 606 | public function setConfigurationType($value) |
607 | 607 | { |
608 | 608 | $this->_configType = $value; |
@@ -357,8 +357,7 @@ discard block |
||
357 | 357 | { |
358 | 358 | $configFile=$basePath; |
359 | 359 | $basePath=dirname($configFile); |
360 | - } |
|
361 | - else |
|
360 | + } else |
|
362 | 361 | $configFile=null; |
363 | 362 | |
364 | 363 | // determine runtime path |
@@ -378,8 +377,7 @@ discard block |
||
378 | 377 | } |
379 | 378 | $this->setBasePath($basePath); |
380 | 379 | $this->setRuntimePath($runtimePath); |
381 | - } |
|
382 | - else |
|
380 | + } else |
|
383 | 381 | throw new TConfigurationException('application_runtimepath_invalid',$runtimePath); |
384 | 382 | |
385 | 383 | } |
@@ -408,8 +406,7 @@ discard block |
||
408 | 406 | $this->$method(); |
409 | 407 | $this->_step++; |
410 | 408 | } |
411 | - } |
|
412 | - catch(Exception $e) |
|
409 | + } catch(Exception $e) |
|
413 | 410 | { |
414 | 411 | $this->onError($e); |
415 | 412 | } |
@@ -986,16 +983,19 @@ discard block |
||
986 | 983 | return; |
987 | 984 | |
988 | 985 | // set path aliases and using namespaces |
989 | - foreach($config->getAliases() as $alias=>$path) |
|
990 | - Prado::setPathOfAlias($alias,$path); |
|
991 | - foreach($config->getUsings() as $using) |
|
992 | - Prado::using($using); |
|
986 | + foreach($config->getAliases() as $alias=>$path) { |
|
987 | + Prado::setPathOfAlias($alias,$path); |
|
988 | + } |
|
989 | + foreach($config->getUsings() as $using) { |
|
990 | + Prado::using($using); |
|
991 | + } |
|
993 | 992 | |
994 | 993 | // set application properties |
995 | 994 | if(!$withinService) |
996 | 995 | { |
997 | - foreach($config->getProperties() as $name=>$value) |
|
998 | - $this->setSubProperty($name,$value); |
|
996 | + foreach($config->getProperties() as $name=>$value) { |
|
997 | + $this->setSubProperty($name,$value); |
|
998 | + } |
|
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | if(empty($this->_services)) |
@@ -1007,11 +1007,11 @@ discard block |
||
1007 | 1007 | if(is_array($parameter)) |
1008 | 1008 | { |
1009 | 1009 | $component=Prado::createComponent($parameter[0]); |
1010 | - foreach($parameter[1] as $name=>$value) |
|
1011 | - $component->setSubProperty($name,$value); |
|
1010 | + foreach($parameter[1] as $name=>$value) { |
|
1011 | + $component->setSubProperty($name,$value); |
|
1012 | + } |
|
1012 | 1013 | $this->_parameters->add($id,$component); |
1013 | - } |
|
1014 | - else |
|
1014 | + } else |
|
1015 | 1015 | $this->_parameters->add($id,$parameter); |
1016 | 1016 | } |
1017 | 1017 | |
@@ -1025,12 +1025,14 @@ discard block |
||
1025 | 1025 | if($module = $this->internalLoadModule($id)) |
1026 | 1026 | $modules[]=$module; |
1027 | 1027 | } |
1028 | - foreach($modules as $module) |
|
1029 | - $module[0]->init($module[1]); |
|
1028 | + foreach($modules as $module) { |
|
1029 | + $module[0]->init($module[1]); |
|
1030 | + } |
|
1030 | 1031 | |
1031 | 1032 | // load service |
1032 | - foreach($config->getServices() as $serviceID=>$serviceConfig) |
|
1033 | - $this->_services[$serviceID]=$serviceConfig; |
|
1033 | + foreach($config->getServices() as $serviceID=>$serviceConfig) { |
|
1034 | + $this->_services[$serviceID]=$serviceConfig; |
|
1035 | + } |
|
1034 | 1036 | |
1035 | 1037 | // external configurations |
1036 | 1038 | foreach($config->getExternalConfigurations() as $filePath=>$condition) |
@@ -1070,8 +1072,7 @@ discard block |
||
1070 | 1072 | $config->loadFromFile($this->_configFile); |
1071 | 1073 | if($this->_cacheFile!==null) |
1072 | 1074 | file_put_contents($this->_cacheFile,serialize($config),LOCK_EX); |
1073 | - } |
|
1074 | - else |
|
1075 | + } else |
|
1075 | 1076 | $config=unserialize(file_get_contents($this->_cacheFile)); |
1076 | 1077 | |
1077 | 1078 | $this->applyConfiguration($config,false); |
@@ -1102,8 +1103,9 @@ discard block |
||
1102 | 1103 | $service->setID($serviceID); |
1103 | 1104 | $this->setService($service); |
1104 | 1105 | |
1105 | - foreach($initProperties as $name=>$value) |
|
1106 | - $service->setSubProperty($name,$value); |
|
1106 | + foreach($initProperties as $name=>$value) { |
|
1107 | + $service->setSubProperty($name,$value); |
|
1108 | + } |
|
1107 | 1109 | |
1108 | 1110 | if($configElement!==null) |
1109 | 1111 | { |
@@ -1116,8 +1118,7 @@ discard block |
||
1116 | 1118 | } |
1117 | 1119 | |
1118 | 1120 | $service->init($configElement); |
1119 | - } |
|
1120 | - else |
|
1121 | + } else |
|
1121 | 1122 | throw new THttpException(500,'application_service_unknown',$serviceID); |
1122 | 1123 | } |
1123 | 1124 | |
@@ -1346,8 +1347,7 @@ discard block |
||
1346 | 1347 | { |
1347 | 1348 | $fcontent = include $fname; |
1348 | 1349 | $this->loadFromPhp($fcontent,dirname($fname)); |
1349 | - } |
|
1350 | - else |
|
1350 | + } else |
|
1351 | 1351 | { |
1352 | 1352 | $dom=new TXmlDocument; |
1353 | 1353 | $dom->loadFromFile($fname); |
@@ -1494,8 +1494,7 @@ discard block |
||
1494 | 1494 | if(isset($this->_aliases[$id])) |
1495 | 1495 | throw new TConfigurationException('appconfig_alias_redefined',$id); |
1496 | 1496 | $this->_aliases[$id]=$p; |
1497 | - } |
|
1498 | - else |
|
1497 | + } else |
|
1499 | 1498 | throw new TConfigurationException('appconfig_alias_invalid'); |
1500 | 1499 | $this->_empty=false; |
1501 | 1500 | break; |
@@ -1562,8 +1561,7 @@ discard block |
||
1562 | 1561 | else |
1563 | 1562 | $this->_modules[$id]=array($type,$properties->toArray(),$element); |
1564 | 1563 | $this->_empty=false; |
1565 | - } |
|
1566 | - else |
|
1564 | + } else |
|
1567 | 1565 | throw new TConfigurationException('appconfig_modules_invalid',$element->getTagName()); |
1568 | 1566 | } |
1569 | 1567 | } |
@@ -1607,8 +1605,7 @@ discard block |
||
1607 | 1605 | $element->setParent(null); |
1608 | 1606 | $this->_services[$id]=array($type,$properties->toArray(),$element); |
1609 | 1607 | $this->_empty=false; |
1610 | - } |
|
1611 | - else |
|
1608 | + } else |
|
1612 | 1609 | throw new TConfigurationException('appconfig_services_invalid',$element->getTagName()); |
1613 | 1610 | } |
1614 | 1611 | } |
@@ -1632,8 +1629,7 @@ discard block |
||
1632 | 1629 | $properties['id'] = $id; |
1633 | 1630 | $this->_parameters[$id] = array($type,$properties); |
1634 | 1631 | } |
1635 | - } |
|
1636 | - else |
|
1632 | + } else |
|
1637 | 1633 | { |
1638 | 1634 | $this->_parameters[$id] = $parameter; |
1639 | 1635 | } |
@@ -1660,12 +1656,10 @@ discard block |
||
1660 | 1656 | $this->_parameters[$id]=$element; |
1661 | 1657 | else |
1662 | 1658 | $this->_parameters[$id]=$value; |
1663 | - } |
|
1664 | - else |
|
1659 | + } else |
|
1665 | 1660 | $this->_parameters[$id]=array($type,$properties->toArray()); |
1666 | 1661 | $this->_empty=false; |
1667 | - } |
|
1668 | - else |
|
1662 | + } else |
|
1669 | 1663 | throw new TConfigurationException('appconfig_parameters_invalid',$element->getTagName()); |
1670 | 1664 | } |
1671 | 1665 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Includes core interfaces essential for TApplication class |
14 | 14 | */ |
15 | -require_once(PRADO_DIR.'/interfaces.php'); |
|
15 | +require_once(PRADO_DIR . '/interfaces.php'); |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Includes core classes essential for TApplication class |
@@ -113,23 +113,23 @@ discard block |
||
113 | 113 | * possible application mode. |
114 | 114 | * @deprecated deprecated since version 3.0.4 (use TApplicationMode constants instead) |
115 | 115 | */ |
116 | - const STATE_OFF='Off'; |
|
117 | - const STATE_DEBUG='Debug'; |
|
118 | - const STATE_NORMAL='Normal'; |
|
119 | - const STATE_PERFORMANCE='Performance'; |
|
116 | + const STATE_OFF = 'Off'; |
|
117 | + const STATE_DEBUG = 'Debug'; |
|
118 | + const STATE_NORMAL = 'Normal'; |
|
119 | + const STATE_PERFORMANCE = 'Performance'; |
|
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Page service ID |
123 | 123 | */ |
124 | - const PAGE_SERVICE_ID='page'; |
|
124 | + const PAGE_SERVICE_ID = 'page'; |
|
125 | 125 | /** |
126 | 126 | * Application configuration file name |
127 | 127 | */ |
128 | - const CONFIG_FILE_XML='application.xml'; |
|
128 | + const CONFIG_FILE_XML = 'application.xml'; |
|
129 | 129 | /** |
130 | 130 | * File extension for external config files |
131 | 131 | */ |
132 | - const CONFIG_FILE_EXT_XML='.xml'; |
|
132 | + const CONFIG_FILE_EXT_XML = '.xml'; |
|
133 | 133 | /** |
134 | 134 | * Configuration file type, application.xml and config.xml |
135 | 135 | */ |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * Application configuration file name |
139 | 139 | */ |
140 | - const CONFIG_FILE_PHP='application.php'; |
|
140 | + const CONFIG_FILE_PHP = 'application.php'; |
|
141 | 141 | /** |
142 | 142 | * File extension for external config files |
143 | 143 | */ |
144 | - const CONFIG_FILE_EXT_PHP='.php'; |
|
144 | + const CONFIG_FILE_EXT_PHP = '.php'; |
|
145 | 145 | /** |
146 | 146 | * Configuration file type, application.php and config.php |
147 | 147 | */ |
@@ -149,20 +149,20 @@ discard block |
||
149 | 149 | /** |
150 | 150 | * Runtime directory name |
151 | 151 | */ |
152 | - const RUNTIME_PATH='runtime'; |
|
152 | + const RUNTIME_PATH = 'runtime'; |
|
153 | 153 | /** |
154 | 154 | * Config cache file |
155 | 155 | */ |
156 | - const CONFIGCACHE_FILE='config.cache'; |
|
156 | + const CONFIGCACHE_FILE = 'config.cache'; |
|
157 | 157 | /** |
158 | 158 | * Global data file |
159 | 159 | */ |
160 | - const GLOBAL_FILE='global.cache'; |
|
160 | + const GLOBAL_FILE = 'global.cache'; |
|
161 | 161 | |
162 | 162 | /** |
163 | 163 | * @var array list of events that define application lifecycles |
164 | 164 | */ |
165 | - private static $_steps=array( |
|
165 | + private static $_steps = array( |
|
166 | 166 | 'onBeginRequest', |
167 | 167 | 'onLoadState', |
168 | 168 | 'onLoadStateComplete', |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | /** |
190 | 190 | * @var boolean whether the request is completed |
191 | 191 | */ |
192 | - private $_requestCompleted=false; |
|
192 | + private $_requestCompleted = false; |
|
193 | 193 | /** |
194 | 194 | * @var integer application state |
195 | 195 | */ |
@@ -205,11 +205,11 @@ discard block |
||
205 | 205 | /** |
206 | 206 | * @var array list of loaded application modules |
207 | 207 | */ |
208 | - private $_modules=array(); |
|
208 | + private $_modules = array(); |
|
209 | 209 | /** |
210 | 210 | * @var array list of application modules yet to be loaded |
211 | 211 | */ |
212 | - private $_lazyModules=array(); |
|
212 | + private $_lazyModules = array(); |
|
213 | 213 | /** |
214 | 214 | * @var TMap list of application parameters |
215 | 215 | */ |
@@ -237,11 +237,11 @@ discard block |
||
237 | 237 | /** |
238 | 238 | * @var boolean if any global state is changed during the current request |
239 | 239 | */ |
240 | - private $_stateChanged=false; |
|
240 | + private $_stateChanged = false; |
|
241 | 241 | /** |
242 | 242 | * @var array global variables (persistent across sessions, requests) |
243 | 243 | */ |
244 | - private $_globals=array(); |
|
244 | + private $_globals = array(); |
|
245 | 245 | /** |
246 | 246 | * @var string cache file |
247 | 247 | */ |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | /** |
294 | 294 | * @var TApplicationMode application mode |
295 | 295 | */ |
296 | - private $_mode=TApplicationMode::Debug; |
|
296 | + private $_mode = TApplicationMode::Debug; |
|
297 | 297 | |
298 | 298 | /** |
299 | 299 | * @var string Customizable page service ID |
@@ -318,22 +318,22 @@ discard block |
||
318 | 318 | * @param boolean whether to cache application configuration. Defaults to true. |
319 | 319 | * @throws TConfigurationException if configuration file cannot be read or the runtime path is invalid. |
320 | 320 | */ |
321 | - public function __construct($basePath='protected',$cacheConfig=true, $configType=self::CONFIG_TYPE_XML) |
|
321 | + public function __construct($basePath = 'protected', $cacheConfig = true, $configType = self::CONFIG_TYPE_XML) |
|
322 | 322 | { |
323 | 323 | // register application as a singleton |
324 | 324 | Prado::setApplication($this); |
325 | 325 | $this->setConfigurationType($configType); |
326 | 326 | $this->resolvePaths($basePath); |
327 | 327 | |
328 | - if($cacheConfig) |
|
329 | - $this->_cacheFile=$this->_runtimePath.DIRECTORY_SEPARATOR.self::CONFIGCACHE_FILE; |
|
328 | + if ($cacheConfig) |
|
329 | + $this->_cacheFile = $this->_runtimePath . DIRECTORY_SEPARATOR . self::CONFIGCACHE_FILE; |
|
330 | 330 | |
331 | 331 | // generates unique ID by hashing the runtime path |
332 | - $this->_uniqueID=md5($this->_runtimePath); |
|
333 | - $this->_parameters=new TMap; |
|
334 | - $this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null)); |
|
332 | + $this->_uniqueID = md5($this->_runtimePath); |
|
333 | + $this->_parameters = new TMap; |
|
334 | + $this->_services = array($this->getPageServiceID()=>array('TPageService', array(), null)); |
|
335 | 335 | |
336 | - Prado::setPathOfAlias('Application',$this->_basePath); |
|
336 | + Prado::setPathOfAlias('Application', $this->_basePath); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -349,29 +349,29 @@ discard block |
||
349 | 349 | protected function resolvePaths($basePath) |
350 | 350 | { |
351 | 351 | // determine configuration path and file |
352 | - if(empty($basePath) || ($basePath=realpath($basePath))===false) |
|
353 | - throw new TConfigurationException('application_basepath_invalid',$basePath); |
|
354 | - if(is_dir($basePath) && is_file($basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName())) |
|
355 | - $configFile=$basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName(); |
|
356 | - else if(is_file($basePath)) |
|
352 | + if (empty($basePath) || ($basePath = realpath($basePath)) === false) |
|
353 | + throw new TConfigurationException('application_basepath_invalid', $basePath); |
|
354 | + if (is_dir($basePath) && is_file($basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName())) |
|
355 | + $configFile = $basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName(); |
|
356 | + else if (is_file($basePath)) |
|
357 | 357 | { |
358 | - $configFile=$basePath; |
|
359 | - $basePath=dirname($configFile); |
|
358 | + $configFile = $basePath; |
|
359 | + $basePath = dirname($configFile); |
|
360 | 360 | } |
361 | 361 | else |
362 | - $configFile=null; |
|
362 | + $configFile = null; |
|
363 | 363 | |
364 | 364 | // determine runtime path |
365 | - $runtimePath=$basePath.DIRECTORY_SEPARATOR.self::RUNTIME_PATH; |
|
366 | - if(is_writable($runtimePath)) |
|
365 | + $runtimePath = $basePath . DIRECTORY_SEPARATOR . self::RUNTIME_PATH; |
|
366 | + if (is_writable($runtimePath)) |
|
367 | 367 | { |
368 | - if($configFile!==null) |
|
368 | + if ($configFile !== null) |
|
369 | 369 | { |
370 | - $runtimePath.=DIRECTORY_SEPARATOR.basename($configFile).'-'.Prado::getVersion(); |
|
371 | - if(!is_dir($runtimePath)) |
|
370 | + $runtimePath .= DIRECTORY_SEPARATOR . basename($configFile) . '-' . Prado::getVersion(); |
|
371 | + if (!is_dir($runtimePath)) |
|
372 | 372 | { |
373 | - if(@mkdir($runtimePath)===false) |
|
374 | - throw new TConfigurationException('application_runtimepath_failed',$runtimePath); |
|
373 | + if (@mkdir($runtimePath) === false) |
|
374 | + throw new TConfigurationException('application_runtimepath_failed', $runtimePath); |
|
375 | 375 | @chmod($runtimePath, PRADO_CHMOD); //make it deletable |
376 | 376 | } |
377 | 377 | $this->setConfigurationFile($configFile); |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | $this->setRuntimePath($runtimePath); |
381 | 381 | } |
382 | 382 | else |
383 | - throw new TConfigurationException('application_runtimepath_invalid',$runtimePath); |
|
383 | + throw new TConfigurationException('application_runtimepath_invalid', $runtimePath); |
|
384 | 384 | |
385 | 385 | } |
386 | 386 | |
@@ -394,22 +394,22 @@ discard block |
||
394 | 394 | try |
395 | 395 | { |
396 | 396 | $this->initApplication(); |
397 | - $n=count(self::$_steps); |
|
398 | - $this->_step=0; |
|
399 | - $this->_requestCompleted=false; |
|
400 | - while($this->_step<$n) |
|
397 | + $n = count(self::$_steps); |
|
398 | + $this->_step = 0; |
|
399 | + $this->_requestCompleted = false; |
|
400 | + while ($this->_step < $n) |
|
401 | 401 | { |
402 | - if($this->_mode===self::STATE_OFF) |
|
403 | - throw new THttpException(503,'application_unavailable'); |
|
404 | - if($this->_requestCompleted) |
|
402 | + if ($this->_mode === self::STATE_OFF) |
|
403 | + throw new THttpException(503, 'application_unavailable'); |
|
404 | + if ($this->_requestCompleted) |
|
405 | 405 | break; |
406 | - $method=self::$_steps[$this->_step]; |
|
407 | - Prado::trace("Executing $method()",'System.TApplication'); |
|
406 | + $method = self::$_steps[$this->_step]; |
|
407 | + Prado::trace("Executing $method()", 'System.TApplication'); |
|
408 | 408 | $this->$method(); |
409 | 409 | $this->_step++; |
410 | 410 | } |
411 | 411 | } |
412 | - catch(Exception $e) |
|
412 | + catch (Exception $e) |
|
413 | 413 | { |
414 | 414 | $this->onError($e); |
415 | 415 | } |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | */ |
424 | 424 | public function completeRequest() |
425 | 425 | { |
426 | - $this->_requestCompleted=true; |
|
426 | + $this->_requestCompleted = true; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -442,9 +442,9 @@ discard block |
||
442 | 442 | * @param mixed the default value. If $key is not found, $defaultValue will be returned |
443 | 443 | * @return mixed the global value corresponding to $key |
444 | 444 | */ |
445 | - public function getGlobalState($key,$defaultValue=null) |
|
445 | + public function getGlobalState($key, $defaultValue = null) |
|
446 | 446 | { |
447 | - return isset($this->_globals[$key])?$this->_globals[$key]:$defaultValue; |
|
447 | + return isset($this->_globals[$key]) ? $this->_globals[$key] : $defaultValue; |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -457,14 +457,14 @@ discard block |
||
457 | 457 | * @param mixed the default value. If $key is not found, $defaultValue will be returned |
458 | 458 | * @param boolean wheter to force an immediate GlobalState save. defaults to false |
459 | 459 | */ |
460 | - public function setGlobalState($key,$value,$defaultValue=null,$forceSave=false) |
|
460 | + public function setGlobalState($key, $value, $defaultValue = null, $forceSave = false) |
|
461 | 461 | { |
462 | - $this->_stateChanged=true; |
|
463 | - if($value===$defaultValue) |
|
462 | + $this->_stateChanged = true; |
|
463 | + if ($value === $defaultValue) |
|
464 | 464 | unset($this->_globals[$key]); |
465 | 465 | else |
466 | - $this->_globals[$key]=$value; |
|
467 | - if($forceSave) |
|
466 | + $this->_globals[$key] = $value; |
|
467 | + if ($forceSave) |
|
468 | 468 | $this->saveGlobals(); |
469 | 469 | } |
470 | 470 | |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | */ |
477 | 477 | public function clearGlobalState($key) |
478 | 478 | { |
479 | - $this->_stateChanged=true; |
|
479 | + $this->_stateChanged = true; |
|
480 | 480 | unset($this->_globals[$key]); |
481 | 481 | } |
482 | 482 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | */ |
489 | 489 | protected function loadGlobals() |
490 | 490 | { |
491 | - $this->_globals=$this->getApplicationStatePersister()->load(); |
|
491 | + $this->_globals = $this->getApplicationStatePersister()->load(); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -497,9 +497,9 @@ discard block |
||
497 | 497 | */ |
498 | 498 | protected function saveGlobals() |
499 | 499 | { |
500 | - if($this->_stateChanged) |
|
500 | + if ($this->_stateChanged) |
|
501 | 501 | { |
502 | - $this->_stateChanged=false; |
|
502 | + $this->_stateChanged = false; |
|
503 | 503 | $this->getApplicationStatePersister()->save($this->_globals); |
504 | 504 | } |
505 | 505 | } |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | */ |
518 | 518 | public function setID($value) |
519 | 519 | { |
520 | - $this->_id=$value; |
|
520 | + $this->_id = $value; |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | */ |
534 | 534 | public function setPageServiceID($value) |
535 | 535 | { |
536 | - $this->_pageServiceID=$value; |
|
536 | + $this->_pageServiceID = $value; |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | */ |
558 | 558 | public function setMode($value) |
559 | 559 | { |
560 | - $this->_mode=TPropertyValue::ensureEnum($value,'TApplicationMode'); |
|
560 | + $this->_mode = TPropertyValue::ensureEnum($value, 'TApplicationMode'); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | */ |
574 | 574 | public function setBasePath($value) |
575 | 575 | { |
576 | - $this->_basePath=$value; |
|
576 | + $this->_basePath = $value; |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | */ |
590 | 590 | public function setConfigurationFile($value) |
591 | 591 | { |
592 | - $this->_configFile=$value; |
|
592 | + $this->_configFile = $value; |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | /** |
@@ -613,9 +613,9 @@ discard block |
||
613 | 613 | */ |
614 | 614 | public function getConfigurationFileExt() |
615 | 615 | { |
616 | - if($this->_configFileExt===null) |
|
616 | + if ($this->_configFileExt === null) |
|
617 | 617 | { |
618 | - switch($this->_configType) |
|
618 | + switch ($this->_configType) |
|
619 | 619 | { |
620 | 620 | case TApplication::CONFIG_TYPE_PHP: |
621 | 621 | $this->_configFileExt = TApplication::CONFIG_FILE_EXT_PHP; |
@@ -633,9 +633,9 @@ discard block |
||
633 | 633 | public function getConfigurationFileName() |
634 | 634 | { |
635 | 635 | static $fileName; |
636 | - if($fileName == null) |
|
636 | + if ($fileName == null) |
|
637 | 637 | { |
638 | - switch($this->_configType) |
|
638 | + switch ($this->_configType) |
|
639 | 639 | { |
640 | 640 | case TApplication::CONFIG_TYPE_PHP: |
641 | 641 | $fileName = TApplication::CONFIG_FILE_PHP; |
@@ -660,11 +660,11 @@ discard block |
||
660 | 660 | */ |
661 | 661 | public function setRuntimePath($value) |
662 | 662 | { |
663 | - $this->_runtimePath=$value; |
|
664 | - if($this->_cacheFile) |
|
665 | - $this->_cacheFile=$this->_runtimePath.DIRECTORY_SEPARATOR.self::CONFIGCACHE_FILE; |
|
663 | + $this->_runtimePath = $value; |
|
664 | + if ($this->_cacheFile) |
|
665 | + $this->_cacheFile = $this->_runtimePath . DIRECTORY_SEPARATOR . self::CONFIGCACHE_FILE; |
|
666 | 666 | // generates unique ID by hashing the runtime path |
667 | - $this->_uniqueID=md5($this->_runtimePath); |
|
667 | + $this->_uniqueID = md5($this->_runtimePath); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | */ |
681 | 681 | public function setService($value) |
682 | 682 | { |
683 | - $this->_service=$value; |
|
683 | + $this->_service = $value; |
|
684 | 684 | } |
685 | 685 | |
686 | 686 | /** |
@@ -689,12 +689,12 @@ discard block |
||
689 | 689 | * @param string ID of the module |
690 | 690 | * @param IModule module object or null if the module has not been loaded yet |
691 | 691 | */ |
692 | - public function setModule($id,IModule $module=null) |
|
692 | + public function setModule($id, IModule $module = null) |
|
693 | 693 | { |
694 | - if(isset($this->_modules[$id])) |
|
695 | - throw new TConfigurationException('application_moduleid_duplicated',$id); |
|
694 | + if (isset($this->_modules[$id])) |
|
695 | + throw new TConfigurationException('application_moduleid_duplicated', $id); |
|
696 | 696 | else |
697 | - $this->_modules[$id]=$module; |
|
697 | + $this->_modules[$id] = $module; |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
@@ -702,11 +702,11 @@ discard block |
||
702 | 702 | */ |
703 | 703 | public function getModule($id) |
704 | 704 | { |
705 | - if(!array_key_exists($id, $this->_modules)) |
|
705 | + if (!array_key_exists($id, $this->_modules)) |
|
706 | 706 | return null; |
707 | 707 | |
708 | 708 | // force loading of a lazy module |
709 | - if($this->_modules[$id]===null) |
|
709 | + if ($this->_modules[$id] === null) |
|
710 | 710 | { |
711 | 711 | $module = $this->internalLoadModule($id, true); |
712 | 712 | $module[0]->init($module[1]); |
@@ -741,9 +741,9 @@ discard block |
||
741 | 741 | */ |
742 | 742 | public function getRequest() |
743 | 743 | { |
744 | - if(!$this->_request) |
|
744 | + if (!$this->_request) |
|
745 | 745 | { |
746 | - $this->_request=new THttpRequest; |
|
746 | + $this->_request = new THttpRequest; |
|
747 | 747 | $this->_request->init(null); |
748 | 748 | } |
749 | 749 | return $this->_request; |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | */ |
755 | 755 | public function setRequest(THttpRequest $request) |
756 | 756 | { |
757 | - $this->_request=$request; |
|
757 | + $this->_request = $request; |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | /** |
@@ -762,9 +762,9 @@ discard block |
||
762 | 762 | */ |
763 | 763 | public function getResponse() |
764 | 764 | { |
765 | - if(!$this->_response) |
|
765 | + if (!$this->_response) |
|
766 | 766 | { |
767 | - $this->_response=new THttpResponse; |
|
767 | + $this->_response = new THttpResponse; |
|
768 | 768 | $this->_response->init(null); |
769 | 769 | } |
770 | 770 | return $this->_response; |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | */ |
776 | 776 | public function setResponse(THttpResponse $response) |
777 | 777 | { |
778 | - $this->_response=$response; |
|
778 | + $this->_response = $response; |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | /** |
@@ -783,9 +783,9 @@ discard block |
||
783 | 783 | */ |
784 | 784 | public function getSession() |
785 | 785 | { |
786 | - if(!$this->_session) |
|
786 | + if (!$this->_session) |
|
787 | 787 | { |
788 | - $this->_session=new THttpSession; |
|
788 | + $this->_session = new THttpSession; |
|
789 | 789 | $this->_session->init(null); |
790 | 790 | } |
791 | 791 | return $this->_session; |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | */ |
797 | 797 | public function setSession(THttpSession $session) |
798 | 798 | { |
799 | - $this->_session=$session; |
|
799 | + $this->_session = $session; |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | /** |
@@ -804,9 +804,9 @@ discard block |
||
804 | 804 | */ |
805 | 805 | public function getErrorHandler() |
806 | 806 | { |
807 | - if(!$this->_errorHandler) |
|
807 | + if (!$this->_errorHandler) |
|
808 | 808 | { |
809 | - $this->_errorHandler=new TErrorHandler; |
|
809 | + $this->_errorHandler = new TErrorHandler; |
|
810 | 810 | $this->_errorHandler->init(null); |
811 | 811 | } |
812 | 812 | return $this->_errorHandler; |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | */ |
818 | 818 | public function setErrorHandler(TErrorHandler $handler) |
819 | 819 | { |
820 | - $this->_errorHandler=$handler; |
|
820 | + $this->_errorHandler = $handler; |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | /** |
@@ -825,9 +825,9 @@ discard block |
||
825 | 825 | */ |
826 | 826 | public function getSecurityManager() |
827 | 827 | { |
828 | - if(!$this->_security) |
|
828 | + if (!$this->_security) |
|
829 | 829 | { |
830 | - $this->_security=new TSecurityManager; |
|
830 | + $this->_security = new TSecurityManager; |
|
831 | 831 | $this->_security->init(null); |
832 | 832 | } |
833 | 833 | return $this->_security; |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | */ |
839 | 839 | public function setSecurityManager(TSecurityManager $sm) |
840 | 840 | { |
841 | - $this->_security=$sm; |
|
841 | + $this->_security = $sm; |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | /** |
@@ -846,9 +846,9 @@ discard block |
||
846 | 846 | */ |
847 | 847 | public function getAssetManager() |
848 | 848 | { |
849 | - if(!$this->_assetManager) |
|
849 | + if (!$this->_assetManager) |
|
850 | 850 | { |
851 | - $this->_assetManager=new TAssetManager; |
|
851 | + $this->_assetManager = new TAssetManager; |
|
852 | 852 | $this->_assetManager->init(null); |
853 | 853 | } |
854 | 854 | return $this->_assetManager; |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | */ |
860 | 860 | public function setAssetManager(TAssetManager $value) |
861 | 861 | { |
862 | - $this->_assetManager=$value; |
|
862 | + $this->_assetManager = $value; |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | /** |
@@ -867,9 +867,9 @@ discard block |
||
867 | 867 | */ |
868 | 868 | public function getApplicationStatePersister() |
869 | 869 | { |
870 | - if(!$this->_statePersister) |
|
870 | + if (!$this->_statePersister) |
|
871 | 871 | { |
872 | - $this->_statePersister=new TApplicationStatePersister; |
|
872 | + $this->_statePersister = new TApplicationStatePersister; |
|
873 | 873 | $this->_statePersister->init(null); |
874 | 874 | } |
875 | 875 | return $this->_statePersister; |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | */ |
881 | 881 | public function setApplicationStatePersister(IStatePersister $persister) |
882 | 882 | { |
883 | - $this->_statePersister=$persister; |
|
883 | + $this->_statePersister = $persister; |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | */ |
897 | 897 | public function setCache(ICache $cache) |
898 | 898 | { |
899 | - $this->_cache=$cache; |
|
899 | + $this->_cache = $cache; |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | /** |
@@ -912,18 +912,18 @@ discard block |
||
912 | 912 | */ |
913 | 913 | public function setUser(IUser $user) |
914 | 914 | { |
915 | - $this->_user=$user; |
|
915 | + $this->_user = $user; |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | /** |
919 | 919 | * @param boolean whether to create globalization if it does not exist |
920 | 920 | * @return TGlobalization globalization module |
921 | 921 | */ |
922 | - public function getGlobalization($createIfNotExists=true) |
|
922 | + public function getGlobalization($createIfNotExists = true) |
|
923 | 923 | { |
924 | - if($this->_globalization===null && $createIfNotExists) |
|
924 | + if ($this->_globalization === null && $createIfNotExists) |
|
925 | 925 | { |
926 | - $this->_globalization=new TGlobalization; |
|
926 | + $this->_globalization = new TGlobalization; |
|
927 | 927 | $this->_globalization->init(null); |
928 | 928 | } |
929 | 929 | return $this->_globalization; |
@@ -934,7 +934,7 @@ discard block |
||
934 | 934 | */ |
935 | 935 | public function setGlobalization(TGlobalization $glob) |
936 | 936 | { |
937 | - $this->_globalization=$glob; |
|
937 | + $this->_globalization = $glob; |
|
938 | 938 | } |
939 | 939 | |
940 | 940 | /** |
@@ -942,8 +942,8 @@ discard block |
||
942 | 942 | */ |
943 | 943 | public function getAuthorizationRules() |
944 | 944 | { |
945 | - if($this->_authRules===null) |
|
946 | - $this->_authRules=new TAuthorizationRuleCollection; |
|
945 | + if ($this->_authRules === null) |
|
946 | + $this->_authRules = new TAuthorizationRuleCollection; |
|
947 | 947 | return $this->_authRules; |
948 | 948 | } |
949 | 949 | |
@@ -952,99 +952,99 @@ discard block |
||
952 | 952 | return 'TApplicationConfiguration'; |
953 | 953 | } |
954 | 954 | |
955 | - protected function internalLoadModule($id, $force=false) |
|
955 | + protected function internalLoadModule($id, $force = false) |
|
956 | 956 | { |
957 | - list($moduleClass, $initProperties, $configElement)=$this->_lazyModules[$id]; |
|
958 | - if(isset($initProperties['lazy']) && $initProperties['lazy'] && !$force) |
|
957 | + list($moduleClass, $initProperties, $configElement) = $this->_lazyModules[$id]; |
|
958 | + if (isset($initProperties['lazy']) && $initProperties['lazy'] && !$force) |
|
959 | 959 | { |
960 | - Prado::trace("Postponed loading of lazy module $id ({$moduleClass})",'System.TApplication'); |
|
960 | + Prado::trace("Postponed loading of lazy module $id ({$moduleClass})", 'System.TApplication'); |
|
961 | 961 | $this->setModule($id, null); |
962 | 962 | return null; |
963 | 963 | } |
964 | 964 | |
965 | - Prado::trace("Loading module $id ({$moduleClass})",'System.TApplication'); |
|
966 | - $module=Prado::createComponent($moduleClass); |
|
967 | - foreach($initProperties as $name=>$value) |
|
965 | + Prado::trace("Loading module $id ({$moduleClass})", 'System.TApplication'); |
|
966 | + $module = Prado::createComponent($moduleClass); |
|
967 | + foreach ($initProperties as $name=>$value) |
|
968 | 968 | { |
969 | - if($name==='lazy') continue; |
|
970 | - $module->setSubProperty($name,$value); |
|
969 | + if ($name === 'lazy') continue; |
|
970 | + $module->setSubProperty($name, $value); |
|
971 | 971 | } |
972 | - $this->setModule($id,$module); |
|
972 | + $this->setModule($id, $module); |
|
973 | 973 | // keep the key to avoid reuse of the old module id |
974 | - $this->_lazyModules[$id]=null; |
|
974 | + $this->_lazyModules[$id] = null; |
|
975 | 975 | |
976 | - return array($module,$configElement); |
|
976 | + return array($module, $configElement); |
|
977 | 977 | } |
978 | 978 | /** |
979 | 979 | * Applies an application configuration. |
980 | 980 | * @param TApplicationConfiguration the configuration |
981 | 981 | * @param boolean whether the configuration is specified within a service. |
982 | 982 | */ |
983 | - public function applyConfiguration($config,$withinService=false) |
|
983 | + public function applyConfiguration($config, $withinService = false) |
|
984 | 984 | { |
985 | - if($config->getIsEmpty()) |
|
985 | + if ($config->getIsEmpty()) |
|
986 | 986 | return; |
987 | 987 | |
988 | 988 | // set path aliases and using namespaces |
989 | - foreach($config->getAliases() as $alias=>$path) |
|
990 | - Prado::setPathOfAlias($alias,$path); |
|
991 | - foreach($config->getUsings() as $using) |
|
989 | + foreach ($config->getAliases() as $alias=>$path) |
|
990 | + Prado::setPathOfAlias($alias, $path); |
|
991 | + foreach ($config->getUsings() as $using) |
|
992 | 992 | Prado::using($using); |
993 | 993 | |
994 | 994 | // set application properties |
995 | - if(!$withinService) |
|
995 | + if (!$withinService) |
|
996 | 996 | { |
997 | - foreach($config->getProperties() as $name=>$value) |
|
998 | - $this->setSubProperty($name,$value); |
|
997 | + foreach ($config->getProperties() as $name=>$value) |
|
998 | + $this->setSubProperty($name, $value); |
|
999 | 999 | } |
1000 | 1000 | |
1001 | - if(empty($this->_services)) |
|
1002 | - $this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null)); |
|
1001 | + if (empty($this->_services)) |
|
1002 | + $this->_services = array($this->getPageServiceID()=>array('TPageService', array(), null)); |
|
1003 | 1003 | |
1004 | 1004 | // load parameters |
1005 | - foreach($config->getParameters() as $id=>$parameter) |
|
1005 | + foreach ($config->getParameters() as $id=>$parameter) |
|
1006 | 1006 | { |
1007 | - if(is_array($parameter)) |
|
1007 | + if (is_array($parameter)) |
|
1008 | 1008 | { |
1009 | - $component=Prado::createComponent($parameter[0]); |
|
1010 | - foreach($parameter[1] as $name=>$value) |
|
1011 | - $component->setSubProperty($name,$value); |
|
1012 | - $this->_parameters->add($id,$component); |
|
1009 | + $component = Prado::createComponent($parameter[0]); |
|
1010 | + foreach ($parameter[1] as $name=>$value) |
|
1011 | + $component->setSubProperty($name, $value); |
|
1012 | + $this->_parameters->add($id, $component); |
|
1013 | 1013 | } |
1014 | 1014 | else |
1015 | - $this->_parameters->add($id,$parameter); |
|
1015 | + $this->_parameters->add($id, $parameter); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | // load and init modules specified in app config |
1019 | - $modules=array(); |
|
1020 | - foreach($config->getModules() as $id=>$moduleConfig) |
|
1019 | + $modules = array(); |
|
1020 | + foreach ($config->getModules() as $id=>$moduleConfig) |
|
1021 | 1021 | { |
1022 | - if(!is_string($id)) |
|
1023 | - $id='_module'.count($this->_lazyModules); |
|
1024 | - $this->_lazyModules[$id]=$moduleConfig; |
|
1025 | - if($module = $this->internalLoadModule($id)) |
|
1026 | - $modules[]=$module; |
|
1022 | + if (!is_string($id)) |
|
1023 | + $id = '_module' . count($this->_lazyModules); |
|
1024 | + $this->_lazyModules[$id] = $moduleConfig; |
|
1025 | + if ($module = $this->internalLoadModule($id)) |
|
1026 | + $modules[] = $module; |
|
1027 | 1027 | } |
1028 | - foreach($modules as $module) |
|
1028 | + foreach ($modules as $module) |
|
1029 | 1029 | $module[0]->init($module[1]); |
1030 | 1030 | |
1031 | 1031 | // load service |
1032 | - foreach($config->getServices() as $serviceID=>$serviceConfig) |
|
1033 | - $this->_services[$serviceID]=$serviceConfig; |
|
1032 | + foreach ($config->getServices() as $serviceID=>$serviceConfig) |
|
1033 | + $this->_services[$serviceID] = $serviceConfig; |
|
1034 | 1034 | |
1035 | 1035 | // external configurations |
1036 | - foreach($config->getExternalConfigurations() as $filePath=>$condition) |
|
1036 | + foreach ($config->getExternalConfigurations() as $filePath=>$condition) |
|
1037 | 1037 | { |
1038 | - if($condition!==true) |
|
1039 | - $condition=$this->evaluateExpression($condition); |
|
1040 | - if($condition) |
|
1038 | + if ($condition !== true) |
|
1039 | + $condition = $this->evaluateExpression($condition); |
|
1040 | + if ($condition) |
|
1041 | 1041 | { |
1042 | - if(($path=Prado::getPathOfNamespace($filePath,$this->getConfigurationFileExt()))===null || !is_file($path)) |
|
1043 | - throw new TConfigurationException('application_includefile_invalid',$filePath); |
|
1044 | - $cn=$this->getApplicationConfigurationClass(); |
|
1045 | - $c=new $cn; |
|
1042 | + if (($path = Prado::getPathOfNamespace($filePath, $this->getConfigurationFileExt())) === null || !is_file($path)) |
|
1043 | + throw new TConfigurationException('application_includefile_invalid', $filePath); |
|
1044 | + $cn = $this->getApplicationConfigurationClass(); |
|
1045 | + $c = new $cn; |
|
1046 | 1046 | $c->loadFromFile($path); |
1047 | - $this->applyConfiguration($c,$withinService); |
|
1047 | + $this->applyConfiguration($c, $withinService); |
|
1048 | 1048 | } |
1049 | 1049 | } |
1050 | 1050 | } |
@@ -1060,25 +1060,25 @@ discard block |
||
1060 | 1060 | */ |
1061 | 1061 | protected function initApplication() |
1062 | 1062 | { |
1063 | - Prado::trace('Initializing application','System.TApplication'); |
|
1063 | + Prado::trace('Initializing application', 'System.TApplication'); |
|
1064 | 1064 | |
1065 | - if($this->_configFile!==null) |
|
1065 | + if ($this->_configFile !== null) |
|
1066 | 1066 | { |
1067 | - if($this->_cacheFile===null || @filemtime($this->_cacheFile)<filemtime($this->_configFile)) |
|
1067 | + if ($this->_cacheFile === null || @filemtime($this->_cacheFile) < filemtime($this->_configFile)) |
|
1068 | 1068 | { |
1069 | - $config=new TApplicationConfiguration; |
|
1069 | + $config = new TApplicationConfiguration; |
|
1070 | 1070 | $config->loadFromFile($this->_configFile); |
1071 | - if($this->_cacheFile!==null) |
|
1072 | - file_put_contents($this->_cacheFile,serialize($config),LOCK_EX); |
|
1071 | + if ($this->_cacheFile !== null) |
|
1072 | + file_put_contents($this->_cacheFile, serialize($config), LOCK_EX); |
|
1073 | 1073 | } |
1074 | 1074 | else |
1075 | - $config=unserialize(file_get_contents($this->_cacheFile)); |
|
1075 | + $config = unserialize(file_get_contents($this->_cacheFile)); |
|
1076 | 1076 | |
1077 | - $this->applyConfiguration($config,false); |
|
1077 | + $this->applyConfiguration($config, false); |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | - if(($serviceID=$this->getRequest()->resolveRequest(array_keys($this->_services)))===null) |
|
1081 | - $serviceID=$this->getPageServiceID(); |
|
1080 | + if (($serviceID = $this->getRequest()->resolveRequest(array_keys($this->_services))) === null) |
|
1081 | + $serviceID = $this->getPageServiceID(); |
|
1082 | 1082 | |
1083 | 1083 | $this->startService($serviceID); |
1084 | 1084 | } |
@@ -1091,34 +1091,34 @@ discard block |
||
1091 | 1091 | */ |
1092 | 1092 | public function startService($serviceID) |
1093 | 1093 | { |
1094 | - if(isset($this->_services[$serviceID])) |
|
1094 | + if (isset($this->_services[$serviceID])) |
|
1095 | 1095 | { |
1096 | - list($serviceClass,$initProperties,$configElement)=$this->_services[$serviceID]; |
|
1097 | - $service=Prado::createComponent($serviceClass); |
|
1098 | - if(!($service instanceof IService)) |
|
1099 | - throw new THttpException(500,'application_service_invalid',$serviceClass); |
|
1100 | - if(!$service->getEnabled()) |
|
1101 | - throw new THttpException(500,'application_service_unavailable',$serviceClass); |
|
1096 | + list($serviceClass, $initProperties, $configElement) = $this->_services[$serviceID]; |
|
1097 | + $service = Prado::createComponent($serviceClass); |
|
1098 | + if (!($service instanceof IService)) |
|
1099 | + throw new THttpException(500, 'application_service_invalid', $serviceClass); |
|
1100 | + if (!$service->getEnabled()) |
|
1101 | + throw new THttpException(500, 'application_service_unavailable', $serviceClass); |
|
1102 | 1102 | $service->setID($serviceID); |
1103 | 1103 | $this->setService($service); |
1104 | 1104 | |
1105 | - foreach($initProperties as $name=>$value) |
|
1106 | - $service->setSubProperty($name,$value); |
|
1105 | + foreach ($initProperties as $name=>$value) |
|
1106 | + $service->setSubProperty($name, $value); |
|
1107 | 1107 | |
1108 | - if($configElement!==null) |
|
1108 | + if ($configElement !== null) |
|
1109 | 1109 | { |
1110 | - $config=new TApplicationConfiguration; |
|
1111 | - if($this->getConfigurationType()==self::CONFIG_TYPE_PHP) |
|
1112 | - $config->loadFromPhp($configElement,$this->getBasePath()); |
|
1110 | + $config = new TApplicationConfiguration; |
|
1111 | + if ($this->getConfigurationType() == self::CONFIG_TYPE_PHP) |
|
1112 | + $config->loadFromPhp($configElement, $this->getBasePath()); |
|
1113 | 1113 | else |
1114 | - $config->loadFromXml($configElement,$this->getBasePath()); |
|
1115 | - $this->applyConfiguration($config,true); |
|
1114 | + $config->loadFromXml($configElement, $this->getBasePath()); |
|
1115 | + $this->applyConfiguration($config, true); |
|
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | $service->init($configElement); |
1119 | 1119 | } |
1120 | 1120 | else |
1121 | - throw new THttpException(500,'application_service_unknown',$serviceID); |
|
1121 | + throw new THttpException(500, 'application_service_unknown', $serviceID); |
|
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | /** |
@@ -1129,9 +1129,9 @@ discard block |
||
1129 | 1129 | */ |
1130 | 1130 | public function onError($param) |
1131 | 1131 | { |
1132 | - Prado::log($param->getMessage(),TLogger::ERROR,'System.TApplication'); |
|
1133 | - $this->raiseEvent('OnError',$this,$param); |
|
1134 | - $this->getErrorHandler()->handleError($this,$param); |
|
1132 | + Prado::log($param->getMessage(), TLogger::ERROR, 'System.TApplication'); |
|
1133 | + $this->raiseEvent('OnError', $this, $param); |
|
1134 | + $this->getErrorHandler()->handleError($this, $param); |
|
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | /** |
@@ -1143,7 +1143,7 @@ discard block |
||
1143 | 1143 | */ |
1144 | 1144 | public function onBeginRequest() |
1145 | 1145 | { |
1146 | - $this->raiseEvent('OnBeginRequest',$this,null); |
|
1146 | + $this->raiseEvent('OnBeginRequest', $this, null); |
|
1147 | 1147 | } |
1148 | 1148 | |
1149 | 1149 | /** |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | public function onAuthentication() |
1154 | 1154 | { |
1155 | - $this->raiseEvent('OnAuthentication',$this,null); |
|
1155 | + $this->raiseEvent('OnAuthentication', $this, null); |
|
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | /** |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | */ |
1162 | 1162 | public function onAuthenticationComplete() |
1163 | 1163 | { |
1164 | - $this->raiseEvent('OnAuthenticationComplete',$this,null); |
|
1164 | + $this->raiseEvent('OnAuthenticationComplete', $this, null); |
|
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | /** |
@@ -1170,7 +1170,7 @@ discard block |
||
1170 | 1170 | */ |
1171 | 1171 | public function onAuthorization() |
1172 | 1172 | { |
1173 | - $this->raiseEvent('OnAuthorization',$this,null); |
|
1173 | + $this->raiseEvent('OnAuthorization', $this, null); |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | /** |
@@ -1179,7 +1179,7 @@ discard block |
||
1179 | 1179 | */ |
1180 | 1180 | public function onAuthorizationComplete() |
1181 | 1181 | { |
1182 | - $this->raiseEvent('OnAuthorizationComplete',$this,null); |
|
1182 | + $this->raiseEvent('OnAuthorizationComplete', $this, null); |
|
1183 | 1183 | } |
1184 | 1184 | |
1185 | 1185 | /** |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | public function onLoadState() |
1190 | 1190 | { |
1191 | 1191 | $this->loadGlobals(); |
1192 | - $this->raiseEvent('OnLoadState',$this,null); |
|
1192 | + $this->raiseEvent('OnLoadState', $this, null); |
|
1193 | 1193 | } |
1194 | 1194 | |
1195 | 1195 | /** |
@@ -1198,7 +1198,7 @@ discard block |
||
1198 | 1198 | */ |
1199 | 1199 | public function onLoadStateComplete() |
1200 | 1200 | { |
1201 | - $this->raiseEvent('OnLoadStateComplete',$this,null); |
|
1201 | + $this->raiseEvent('OnLoadStateComplete', $this, null); |
|
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | /** |
@@ -1207,7 +1207,7 @@ discard block |
||
1207 | 1207 | */ |
1208 | 1208 | public function onPreRunService() |
1209 | 1209 | { |
1210 | - $this->raiseEvent('OnPreRunService',$this,null); |
|
1210 | + $this->raiseEvent('OnPreRunService', $this, null); |
|
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | /** |
@@ -1215,7 +1215,7 @@ discard block |
||
1215 | 1215 | */ |
1216 | 1216 | public function runService() |
1217 | 1217 | { |
1218 | - if($this->_service) |
|
1218 | + if ($this->_service) |
|
1219 | 1219 | $this->_service->run(); |
1220 | 1220 | } |
1221 | 1221 | |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | */ |
1226 | 1226 | public function onSaveState() |
1227 | 1227 | { |
1228 | - $this->raiseEvent('OnSaveState',$this,null); |
|
1228 | + $this->raiseEvent('OnSaveState', $this, null); |
|
1229 | 1229 | $this->saveGlobals(); |
1230 | 1230 | } |
1231 | 1231 | |
@@ -1235,7 +1235,7 @@ discard block |
||
1235 | 1235 | */ |
1236 | 1236 | public function onSaveStateComplete() |
1237 | 1237 | { |
1238 | - $this->raiseEvent('OnSaveStateComplete',$this,null); |
|
1238 | + $this->raiseEvent('OnSaveStateComplete', $this, null); |
|
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | /** |
@@ -1244,7 +1244,7 @@ discard block |
||
1244 | 1244 | */ |
1245 | 1245 | public function onPreFlushOutput() |
1246 | 1246 | { |
1247 | - $this->raiseEvent('OnPreFlushOutput',$this,null); |
|
1247 | + $this->raiseEvent('OnPreFlushOutput', $this, null); |
|
1248 | 1248 | } |
1249 | 1249 | |
1250 | 1250 | /** |
@@ -1263,8 +1263,8 @@ discard block |
||
1263 | 1263 | public function onEndRequest() |
1264 | 1264 | { |
1265 | 1265 | $this->flushOutput(false); // flush all remaining content in the buffer |
1266 | - $this->saveGlobals(); // save global state |
|
1267 | - $this->raiseEvent('OnEndRequest',$this,null); |
|
1266 | + $this->saveGlobals(); // save global state |
|
1267 | + $this->raiseEvent('OnEndRequest', $this, null); |
|
1268 | 1268 | } |
1269 | 1269 | } |
1270 | 1270 | |
@@ -1283,10 +1283,10 @@ discard block |
||
1283 | 1283 | */ |
1284 | 1284 | class TApplicationMode extends TEnumerable |
1285 | 1285 | { |
1286 | - const Off='Off'; |
|
1287 | - const Debug='Debug'; |
|
1288 | - const Normal='Normal'; |
|
1289 | - const Performance='Performance'; |
|
1286 | + const Off = 'Off'; |
|
1287 | + const Debug = 'Debug'; |
|
1288 | + const Normal = 'Normal'; |
|
1289 | + const Performance = 'Performance'; |
|
1290 | 1290 | } |
1291 | 1291 | |
1292 | 1292 | |
@@ -1305,35 +1305,35 @@ discard block |
||
1305 | 1305 | /** |
1306 | 1306 | * @var array list of application initial property values, indexed by property names |
1307 | 1307 | */ |
1308 | - private $_properties=array(); |
|
1308 | + private $_properties = array(); |
|
1309 | 1309 | /** |
1310 | 1310 | * @var array list of namespaces to be used |
1311 | 1311 | */ |
1312 | - private $_usings=array(); |
|
1312 | + private $_usings = array(); |
|
1313 | 1313 | /** |
1314 | 1314 | * @var array list of path aliases, indexed by alias names |
1315 | 1315 | */ |
1316 | - private $_aliases=array(); |
|
1316 | + private $_aliases = array(); |
|
1317 | 1317 | /** |
1318 | 1318 | * @var array list of module configurations |
1319 | 1319 | */ |
1320 | - private $_modules=array(); |
|
1320 | + private $_modules = array(); |
|
1321 | 1321 | /** |
1322 | 1322 | * @var array list of service configurations |
1323 | 1323 | */ |
1324 | - private $_services=array(); |
|
1324 | + private $_services = array(); |
|
1325 | 1325 | /** |
1326 | 1326 | * @var array list of parameters |
1327 | 1327 | */ |
1328 | - private $_parameters=array(); |
|
1328 | + private $_parameters = array(); |
|
1329 | 1329 | /** |
1330 | 1330 | * @var array list of included configurations |
1331 | 1331 | */ |
1332 | - private $_includes=array(); |
|
1332 | + private $_includes = array(); |
|
1333 | 1333 | /** |
1334 | 1334 | * @var boolean whether this configuration contains actual stuff |
1335 | 1335 | */ |
1336 | - private $_empty=true; |
|
1336 | + private $_empty = true; |
|
1337 | 1337 | |
1338 | 1338 | /** |
1339 | 1339 | * Parses the application configuration file. |
@@ -1342,16 +1342,16 @@ discard block |
||
1342 | 1342 | */ |
1343 | 1343 | public function loadFromFile($fname) |
1344 | 1344 | { |
1345 | - if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
1345 | + if (Prado::getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
1346 | 1346 | { |
1347 | 1347 | $fcontent = include $fname; |
1348 | - $this->loadFromPhp($fcontent,dirname($fname)); |
|
1348 | + $this->loadFromPhp($fcontent, dirname($fname)); |
|
1349 | 1349 | } |
1350 | 1350 | else |
1351 | 1351 | { |
1352 | - $dom=new TXmlDocument; |
|
1352 | + $dom = new TXmlDocument; |
|
1353 | 1353 | $dom->loadFromFile($fname); |
1354 | - $this->loadFromXml($dom,dirname($fname)); |
|
1354 | + $this->loadFromXml($dom, dirname($fname)); |
|
1355 | 1355 | } |
1356 | 1356 | } |
1357 | 1357 | |
@@ -1371,29 +1371,29 @@ discard block |
||
1371 | 1371 | public function loadFromPhp($config, $configPath) |
1372 | 1372 | { |
1373 | 1373 | // application properties |
1374 | - if(isset($config['application'])) |
|
1374 | + if (isset($config['application'])) |
|
1375 | 1375 | { |
1376 | - foreach($config['application'] as $name=>$value) |
|
1376 | + foreach ($config['application'] as $name=>$value) |
|
1377 | 1377 | { |
1378 | - $this->_properties[$name]=$value; |
|
1378 | + $this->_properties[$name] = $value; |
|
1379 | 1379 | } |
1380 | 1380 | $this->_empty = false; |
1381 | 1381 | } |
1382 | 1382 | |
1383 | - if(isset($config['paths']) && is_array($config['paths'])) |
|
1384 | - $this->loadPathsPhp($config['paths'],$configPath); |
|
1383 | + if (isset($config['paths']) && is_array($config['paths'])) |
|
1384 | + $this->loadPathsPhp($config['paths'], $configPath); |
|
1385 | 1385 | |
1386 | - if(isset($config['modules']) && is_array($config['modules'])) |
|
1387 | - $this->loadModulesPhp($config['modules'],$configPath); |
|
1386 | + if (isset($config['modules']) && is_array($config['modules'])) |
|
1387 | + $this->loadModulesPhp($config['modules'], $configPath); |
|
1388 | 1388 | |
1389 | - if(isset($config['services']) && is_array($config['services'])) |
|
1390 | - $this->loadServicesPhp($config['services'],$configPath); |
|
1389 | + if (isset($config['services']) && is_array($config['services'])) |
|
1390 | + $this->loadServicesPhp($config['services'], $configPath); |
|
1391 | 1391 | |
1392 | - if(isset($config['parameters']) && is_array($config['parameters'])) |
|
1392 | + if (isset($config['parameters']) && is_array($config['parameters'])) |
|
1393 | 1393 | $this->loadParametersPhp($config['parameters'], $configPath); |
1394 | 1394 | |
1395 | - if(isset($config['includes']) && is_array($config['includes'])) |
|
1396 | - $this->loadExternalXml($config['includes'],$configPath); |
|
1395 | + if (isset($config['includes']) && is_array($config['includes'])) |
|
1396 | + $this->loadExternalXml($config['includes'], $configPath); |
|
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | /** |
@@ -1401,33 +1401,33 @@ discard block |
||
1401 | 1401 | * @param TXmlElement the XML element |
1402 | 1402 | * @param string the context path (for specifying relative paths) |
1403 | 1403 | */ |
1404 | - public function loadFromXml($dom,$configPath) |
|
1404 | + public function loadFromXml($dom, $configPath) |
|
1405 | 1405 | { |
1406 | 1406 | // application properties |
1407 | - foreach($dom->getAttributes() as $name=>$value) |
|
1407 | + foreach ($dom->getAttributes() as $name=>$value) |
|
1408 | 1408 | { |
1409 | - $this->_properties[$name]=$value; |
|
1410 | - $this->_empty=false; |
|
1409 | + $this->_properties[$name] = $value; |
|
1410 | + $this->_empty = false; |
|
1411 | 1411 | } |
1412 | 1412 | |
1413 | - foreach($dom->getElements() as $element) |
|
1413 | + foreach ($dom->getElements() as $element) |
|
1414 | 1414 | { |
1415 | - switch($element->getTagName()) |
|
1415 | + switch ($element->getTagName()) |
|
1416 | 1416 | { |
1417 | 1417 | case 'paths': |
1418 | - $this->loadPathsXml($element,$configPath); |
|
1418 | + $this->loadPathsXml($element, $configPath); |
|
1419 | 1419 | break; |
1420 | 1420 | case 'modules': |
1421 | - $this->loadModulesXml($element,$configPath); |
|
1421 | + $this->loadModulesXml($element, $configPath); |
|
1422 | 1422 | break; |
1423 | 1423 | case 'services': |
1424 | - $this->loadServicesXml($element,$configPath); |
|
1424 | + $this->loadServicesXml($element, $configPath); |
|
1425 | 1425 | break; |
1426 | 1426 | case 'parameters': |
1427 | - $this->loadParametersXml($element,$configPath); |
|
1427 | + $this->loadParametersXml($element, $configPath); |
|
1428 | 1428 | break; |
1429 | 1429 | case 'include': |
1430 | - $this->loadExternalXml($element,$configPath); |
|
1430 | + $this->loadExternalXml($element, $configPath); |
|
1431 | 1431 | break; |
1432 | 1432 | default: |
1433 | 1433 | //throw new TConfigurationException('appconfig_tag_invalid',$element->getTagName()); |
@@ -1443,26 +1443,26 @@ discard block |
||
1443 | 1443 | */ |
1444 | 1444 | protected function loadPathsPhp($pathsNode, $configPath) |
1445 | 1445 | { |
1446 | - if(isset($pathsNode['aliases']) && is_array($pathsNode['aliases'])) |
|
1446 | + if (isset($pathsNode['aliases']) && is_array($pathsNode['aliases'])) |
|
1447 | 1447 | { |
1448 | - foreach($pathsNode['aliases'] as $id=>$path) |
|
1448 | + foreach ($pathsNode['aliases'] as $id=>$path) |
|
1449 | 1449 | { |
1450 | - $path=str_replace('\\','/',$path); |
|
1451 | - if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) // if absolute path |
|
1452 | - $p=realpath($path); |
|
1450 | + $path = str_replace('\\', '/', $path); |
|
1451 | + if (preg_match('/^\\/|.:\\/|.:\\\\/', $path)) // if absolute path |
|
1452 | + $p = realpath($path); |
|
1453 | 1453 | else |
1454 | - $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
|
1455 | - if($p===false || !is_dir($p)) |
|
1456 | - throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
1457 | - if(isset($this->_aliases[$id])) |
|
1458 | - throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
1459 | - $this->_aliases[$id]=$p; |
|
1454 | + $p = realpath($configPath . DIRECTORY_SEPARATOR . $path); |
|
1455 | + if ($p === false || !is_dir($p)) |
|
1456 | + throw new TConfigurationException('appconfig_aliaspath_invalid', $id, $path); |
|
1457 | + if (isset($this->_aliases[$id])) |
|
1458 | + throw new TConfigurationException('appconfig_alias_redefined', $id); |
|
1459 | + $this->_aliases[$id] = $p; |
|
1460 | 1460 | } |
1461 | 1461 | } |
1462 | 1462 | |
1463 | - if(isset($pathsNode['using']) && is_array($pathsNode['using'])) |
|
1463 | + if (isset($pathsNode['using']) && is_array($pathsNode['using'])) |
|
1464 | 1464 | { |
1465 | - foreach($pathsNode['using'] as $namespace) |
|
1465 | + foreach ($pathsNode['using'] as $namespace) |
|
1466 | 1466 | { |
1467 | 1467 | $this->_usings[] = $namespace; |
1468 | 1468 | } |
@@ -1474,43 +1474,43 @@ discard block |
||
1474 | 1474 | * @param TXmlElement the paths XML node |
1475 | 1475 | * @param string the context path (for specifying relative paths) |
1476 | 1476 | */ |
1477 | - protected function loadPathsXml($pathsNode,$configPath) |
|
1477 | + protected function loadPathsXml($pathsNode, $configPath) |
|
1478 | 1478 | { |
1479 | - foreach($pathsNode->getElements() as $element) |
|
1479 | + foreach ($pathsNode->getElements() as $element) |
|
1480 | 1480 | { |
1481 | - switch($element->getTagName()) |
|
1481 | + switch ($element->getTagName()) |
|
1482 | 1482 | { |
1483 | 1483 | case 'alias': |
1484 | 1484 | { |
1485 | - if(($id=$element->getAttribute('id'))!==null && ($path=$element->getAttribute('path'))!==null) |
|
1485 | + if (($id = $element->getAttribute('id')) !== null && ($path = $element->getAttribute('path')) !== null) |
|
1486 | 1486 | { |
1487 | - $path=str_replace('\\','/',$path); |
|
1488 | - if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) // if absolute path |
|
1489 | - $p=realpath($path); |
|
1487 | + $path = str_replace('\\', '/', $path); |
|
1488 | + if (preg_match('/^\\/|.:\\/|.:\\\\/', $path)) // if absolute path |
|
1489 | + $p = realpath($path); |
|
1490 | 1490 | else |
1491 | - $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
|
1492 | - if($p===false || !is_dir($p)) |
|
1493 | - throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
1494 | - if(isset($this->_aliases[$id])) |
|
1495 | - throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
1496 | - $this->_aliases[$id]=$p; |
|
1491 | + $p = realpath($configPath . DIRECTORY_SEPARATOR . $path); |
|
1492 | + if ($p === false || !is_dir($p)) |
|
1493 | + throw new TConfigurationException('appconfig_aliaspath_invalid', $id, $path); |
|
1494 | + if (isset($this->_aliases[$id])) |
|
1495 | + throw new TConfigurationException('appconfig_alias_redefined', $id); |
|
1496 | + $this->_aliases[$id] = $p; |
|
1497 | 1497 | } |
1498 | 1498 | else |
1499 | 1499 | throw new TConfigurationException('appconfig_alias_invalid'); |
1500 | - $this->_empty=false; |
|
1500 | + $this->_empty = false; |
|
1501 | 1501 | break; |
1502 | 1502 | } |
1503 | 1503 | case 'using': |
1504 | 1504 | { |
1505 | - if(($namespace=$element->getAttribute('namespace'))!==null) |
|
1506 | - $this->_usings[]=$namespace; |
|
1505 | + if (($namespace = $element->getAttribute('namespace')) !== null) |
|
1506 | + $this->_usings[] = $namespace; |
|
1507 | 1507 | else |
1508 | 1508 | throw new TConfigurationException('appconfig_using_invalid'); |
1509 | - $this->_empty=false; |
|
1509 | + $this->_empty = false; |
|
1510 | 1510 | break; |
1511 | 1511 | } |
1512 | 1512 | default: |
1513 | - throw new TConfigurationException('appconfig_paths_invalid',$element->getTagName()); |
|
1513 | + throw new TConfigurationException('appconfig_paths_invalid', $element->getTagName()); |
|
1514 | 1514 | } |
1515 | 1515 | } |
1516 | 1516 | } |
@@ -1522,21 +1522,21 @@ discard block |
||
1522 | 1522 | */ |
1523 | 1523 | protected function loadModulesPhp($modulesNode, $configPath) |
1524 | 1524 | { |
1525 | - foreach($modulesNode as $id=>$module) |
|
1525 | + foreach ($modulesNode as $id=>$module) |
|
1526 | 1526 | { |
1527 | - if(!isset($module['class'])) |
|
1528 | - throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
1527 | + if (!isset($module['class'])) |
|
1528 | + throw new TConfigurationException('appconfig_moduletype_required', $id); |
|
1529 | 1529 | $type = $module['class']; |
1530 | 1530 | unset($module['class']); |
1531 | 1531 | $properties = array(); |
1532 | - if(isset($module['properties'])) |
|
1532 | + if (isset($module['properties'])) |
|
1533 | 1533 | { |
1534 | 1534 | $properties = $module['properties']; |
1535 | 1535 | unset($module['properties']); |
1536 | 1536 | } |
1537 | 1537 | $properties['id'] = $id; |
1538 | - $this->_modules[$id]=array($type,$properties,$module); |
|
1539 | - $this->_empty=false; |
|
1538 | + $this->_modules[$id] = array($type, $properties, $module); |
|
1539 | + $this->_empty = false; |
|
1540 | 1540 | } |
1541 | 1541 | } |
1542 | 1542 | |
@@ -1545,26 +1545,26 @@ discard block |
||
1545 | 1545 | * @param TXmlElement the modules XML node |
1546 | 1546 | * @param string the context path (for specifying relative paths) |
1547 | 1547 | */ |
1548 | - protected function loadModulesXml($modulesNode,$configPath) |
|
1548 | + protected function loadModulesXml($modulesNode, $configPath) |
|
1549 | 1549 | { |
1550 | - foreach($modulesNode->getElements() as $element) |
|
1550 | + foreach ($modulesNode->getElements() as $element) |
|
1551 | 1551 | { |
1552 | - if($element->getTagName()==='module') |
|
1552 | + if ($element->getTagName() === 'module') |
|
1553 | 1553 | { |
1554 | - $properties=$element->getAttributes(); |
|
1555 | - $id=$properties->itemAt('id'); |
|
1556 | - $type=$properties->remove('class'); |
|
1557 | - if($type===null) |
|
1558 | - throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
1554 | + $properties = $element->getAttributes(); |
|
1555 | + $id = $properties->itemAt('id'); |
|
1556 | + $type = $properties->remove('class'); |
|
1557 | + if ($type === null) |
|
1558 | + throw new TConfigurationException('appconfig_moduletype_required', $id); |
|
1559 | 1559 | $element->setParent(null); |
1560 | - if($id===null) |
|
1561 | - $this->_modules[]=array($type,$properties->toArray(),$element); |
|
1560 | + if ($id === null) |
|
1561 | + $this->_modules[] = array($type, $properties->toArray(), $element); |
|
1562 | 1562 | else |
1563 | - $this->_modules[$id]=array($type,$properties->toArray(),$element); |
|
1564 | - $this->_empty=false; |
|
1563 | + $this->_modules[$id] = array($type, $properties->toArray(), $element); |
|
1564 | + $this->_empty = false; |
|
1565 | 1565 | } |
1566 | 1566 | else |
1567 | - throw new TConfigurationException('appconfig_modules_invalid',$element->getTagName()); |
|
1567 | + throw new TConfigurationException('appconfig_modules_invalid', $element->getTagName()); |
|
1568 | 1568 | } |
1569 | 1569 | } |
1570 | 1570 | |
@@ -1573,17 +1573,17 @@ discard block |
||
1573 | 1573 | * @param array the services PHP array |
1574 | 1574 | * @param string the context path (for specifying relative paths) |
1575 | 1575 | */ |
1576 | - protected function loadServicesPhp($servicesNode,$configPath) |
|
1576 | + protected function loadServicesPhp($servicesNode, $configPath) |
|
1577 | 1577 | { |
1578 | - foreach($servicesNode as $id => $service) |
|
1578 | + foreach ($servicesNode as $id => $service) |
|
1579 | 1579 | { |
1580 | - if(!isset($service['class'])) |
|
1580 | + if (!isset($service['class'])) |
|
1581 | 1581 | throw new TConfigurationException('appconfig_servicetype_required'); |
1582 | 1582 | $type = $service['class']; |
1583 | 1583 | $properties = isset($service['properties']) ? $service['properties'] : array(); |
1584 | 1584 | unset($service['properties']); |
1585 | 1585 | $properties['id'] = $id; |
1586 | - $this->_services[$id] = array($type,$properties,$service); |
|
1586 | + $this->_services[$id] = array($type, $properties, $service); |
|
1587 | 1587 | $this->_empty = false; |
1588 | 1588 | } |
1589 | 1589 | } |
@@ -1593,23 +1593,23 @@ discard block |
||
1593 | 1593 | * @param TXmlElement the services XML node |
1594 | 1594 | * @param string the context path (for specifying relative paths) |
1595 | 1595 | */ |
1596 | - protected function loadServicesXml($servicesNode,$configPath) |
|
1596 | + protected function loadServicesXml($servicesNode, $configPath) |
|
1597 | 1597 | { |
1598 | - foreach($servicesNode->getElements() as $element) |
|
1598 | + foreach ($servicesNode->getElements() as $element) |
|
1599 | 1599 | { |
1600 | - if($element->getTagName()==='service') |
|
1600 | + if ($element->getTagName() === 'service') |
|
1601 | 1601 | { |
1602 | - $properties=$element->getAttributes(); |
|
1603 | - if(($id=$properties->itemAt('id'))===null) |
|
1602 | + $properties = $element->getAttributes(); |
|
1603 | + if (($id = $properties->itemAt('id')) === null) |
|
1604 | 1604 | throw new TConfigurationException('appconfig_serviceid_required'); |
1605 | - if(($type=$properties->remove('class'))===null) |
|
1606 | - throw new TConfigurationException('appconfig_servicetype_required',$id); |
|
1605 | + if (($type = $properties->remove('class')) === null) |
|
1606 | + throw new TConfigurationException('appconfig_servicetype_required', $id); |
|
1607 | 1607 | $element->setParent(null); |
1608 | - $this->_services[$id]=array($type,$properties->toArray(),$element); |
|
1609 | - $this->_empty=false; |
|
1608 | + $this->_services[$id] = array($type, $properties->toArray(), $element); |
|
1609 | + $this->_empty = false; |
|
1610 | 1610 | } |
1611 | 1611 | else |
1612 | - throw new TConfigurationException('appconfig_services_invalid',$element->getTagName()); |
|
1612 | + throw new TConfigurationException('appconfig_services_invalid', $element->getTagName()); |
|
1613 | 1613 | } |
1614 | 1614 | } |
1615 | 1615 | |
@@ -1618,19 +1618,19 @@ discard block |
||
1618 | 1618 | * @param array the parameters PHP array |
1619 | 1619 | * @param string the context path (for specifying relative paths) |
1620 | 1620 | */ |
1621 | - protected function loadParametersPhp($parametersNode,$configPath) |
|
1621 | + protected function loadParametersPhp($parametersNode, $configPath) |
|
1622 | 1622 | { |
1623 | - foreach($parametersNode as $id => $parameter) |
|
1623 | + foreach ($parametersNode as $id => $parameter) |
|
1624 | 1624 | { |
1625 | - if(is_array($parameter)) |
|
1625 | + if (is_array($parameter)) |
|
1626 | 1626 | { |
1627 | - if(isset($parameter['class'])) |
|
1627 | + if (isset($parameter['class'])) |
|
1628 | 1628 | { |
1629 | 1629 | $type = $parameter['class']; |
1630 | 1630 | unset($parameter['class']); |
1631 | 1631 | $properties = isset($service['properties']) ? $service['properties'] : array(); |
1632 | 1632 | $properties['id'] = $id; |
1633 | - $this->_parameters[$id] = array($type,$properties); |
|
1633 | + $this->_parameters[$id] = array($type, $properties); |
|
1634 | 1634 | } |
1635 | 1635 | } |
1636 | 1636 | else |
@@ -1645,28 +1645,28 @@ discard block |
||
1645 | 1645 | * @param TXmlElement the parameters XML node |
1646 | 1646 | * @param string the context path (for specifying relative paths) |
1647 | 1647 | */ |
1648 | - protected function loadParametersXml($parametersNode,$configPath) |
|
1648 | + protected function loadParametersXml($parametersNode, $configPath) |
|
1649 | 1649 | { |
1650 | - foreach($parametersNode->getElements() as $element) |
|
1650 | + foreach ($parametersNode->getElements() as $element) |
|
1651 | 1651 | { |
1652 | - if($element->getTagName()==='parameter') |
|
1652 | + if ($element->getTagName() === 'parameter') |
|
1653 | 1653 | { |
1654 | - $properties=$element->getAttributes(); |
|
1655 | - if(($id=$properties->remove('id'))===null) |
|
1654 | + $properties = $element->getAttributes(); |
|
1655 | + if (($id = $properties->remove('id')) === null) |
|
1656 | 1656 | throw new TConfigurationException('appconfig_parameterid_required'); |
1657 | - if(($type=$properties->remove('class'))===null) |
|
1657 | + if (($type = $properties->remove('class')) === null) |
|
1658 | 1658 | { |
1659 | - if(($value=$properties->remove('value'))===null) |
|
1660 | - $this->_parameters[$id]=$element; |
|
1659 | + if (($value = $properties->remove('value')) === null) |
|
1660 | + $this->_parameters[$id] = $element; |
|
1661 | 1661 | else |
1662 | - $this->_parameters[$id]=$value; |
|
1662 | + $this->_parameters[$id] = $value; |
|
1663 | 1663 | } |
1664 | 1664 | else |
1665 | - $this->_parameters[$id]=array($type,$properties->toArray()); |
|
1666 | - $this->_empty=false; |
|
1665 | + $this->_parameters[$id] = array($type, $properties->toArray()); |
|
1666 | + $this->_empty = false; |
|
1667 | 1667 | } |
1668 | 1668 | else |
1669 | - throw new TConfigurationException('appconfig_parameters_invalid',$element->getTagName()); |
|
1669 | + throw new TConfigurationException('appconfig_parameters_invalid', $element->getTagName()); |
|
1670 | 1670 | } |
1671 | 1671 | } |
1672 | 1672 | |
@@ -1675,19 +1675,19 @@ discard block |
||
1675 | 1675 | * @param array the application PHP array |
1676 | 1676 | * @param string the context path (for specifying relative paths) |
1677 | 1677 | */ |
1678 | - protected function loadExternalPhp($includeNode,$configPath) |
|
1678 | + protected function loadExternalPhp($includeNode, $configPath) |
|
1679 | 1679 | { |
1680 | - foreach($includeNode as $include) |
|
1680 | + foreach ($includeNode as $include) |
|
1681 | 1681 | { |
1682 | - $when = isset($include['when'])?true:false; |
|
1683 | - if(!isset($include['file'])) |
|
1682 | + $when = isset($include['when']) ?true:false; |
|
1683 | + if (!isset($include['file'])) |
|
1684 | 1684 | throw new TConfigurationException('appconfig_includefile_required'); |
1685 | 1685 | $filePath = $include['file']; |
1686 | - if(isset($this->_includes[$filePath])) |
|
1687 | - $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')'; |
|
1686 | + if (isset($this->_includes[$filePath])) |
|
1687 | + $this->_includes[$filePath] = '(' . $this->_includes[$filePath] . ') || (' . $when . ')'; |
|
1688 | 1688 | else |
1689 | - $$this->_includes[$filePath]=$when; |
|
1690 | - $this->_empty=false; |
|
1689 | + $$this->_includes[$filePath] = $when; |
|
1690 | + $this->_empty = false; |
|
1691 | 1691 | } |
1692 | 1692 | } |
1693 | 1693 | |
@@ -1696,17 +1696,17 @@ discard block |
||
1696 | 1696 | * @param TXmlElement the application DOM element |
1697 | 1697 | * @param string the context path (for specifying relative paths) |
1698 | 1698 | */ |
1699 | - protected function loadExternalXml($includeNode,$configPath) |
|
1699 | + protected function loadExternalXml($includeNode, $configPath) |
|
1700 | 1700 | { |
1701 | - if(($when=$includeNode->getAttribute('when'))===null) |
|
1702 | - $when=true; |
|
1703 | - if(($filePath=$includeNode->getAttribute('file'))===null) |
|
1701 | + if (($when = $includeNode->getAttribute('when')) === null) |
|
1702 | + $when = true; |
|
1703 | + if (($filePath = $includeNode->getAttribute('file')) === null) |
|
1704 | 1704 | throw new TConfigurationException('appconfig_includefile_required'); |
1705 | - if(isset($this->_includes[$filePath])) |
|
1706 | - $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')'; |
|
1705 | + if (isset($this->_includes[$filePath])) |
|
1706 | + $this->_includes[$filePath] = '(' . $this->_includes[$filePath] . ') || (' . $when . ')'; |
|
1707 | 1707 | else |
1708 | - $this->_includes[$filePath]=$when; |
|
1709 | - $this->_empty=false; |
|
1708 | + $this->_includes[$filePath] = $when; |
|
1709 | + $this->_empty = false; |
|
1710 | 1710 | } |
1711 | 1711 | |
1712 | 1712 | /** |
@@ -1813,7 +1813,7 @@ discard block |
||
1813 | 1813 | /** |
1814 | 1814 | * Name of the value stored in cache |
1815 | 1815 | */ |
1816 | - const CACHE_NAME='prado:appstate'; |
|
1816 | + const CACHE_NAME = 'prado:appstate'; |
|
1817 | 1817 | |
1818 | 1818 | /** |
1819 | 1819 | * Initializes module. |
@@ -1829,7 +1829,7 @@ discard block |
||
1829 | 1829 | */ |
1830 | 1830 | protected function getStateFilePath() |
1831 | 1831 | { |
1832 | - return $this->getApplication()->getRuntimePath().'/global.cache'; |
|
1832 | + return $this->getApplication()->getRuntimePath() . '/global.cache'; |
|
1833 | 1833 | } |
1834 | 1834 | |
1835 | 1835 | /** |
@@ -1838,11 +1838,11 @@ discard block |
||
1838 | 1838 | */ |
1839 | 1839 | public function load() |
1840 | 1840 | { |
1841 | - if(($cache=$this->getApplication()->getCache())!==null && ($value=$cache->get(self::CACHE_NAME))!==false) |
|
1841 | + if (($cache = $this->getApplication()->getCache()) !== null && ($value = $cache->get(self::CACHE_NAME)) !== false) |
|
1842 | 1842 | return unserialize($value); |
1843 | 1843 | else |
1844 | 1844 | { |
1845 | - if(($content=@file_get_contents($this->getStateFilePath()))!==false) |
|
1845 | + if (($content = @file_get_contents($this->getStateFilePath())) !== false) |
|
1846 | 1846 | return unserialize($content); |
1847 | 1847 | else |
1848 | 1848 | return null; |
@@ -1855,19 +1855,19 @@ discard block |
||
1855 | 1855 | */ |
1856 | 1856 | public function save($state) |
1857 | 1857 | { |
1858 | - $content=serialize($state); |
|
1859 | - $saveFile=true; |
|
1860 | - if(($cache=$this->getApplication()->getCache())!==null) |
|
1858 | + $content = serialize($state); |
|
1859 | + $saveFile = true; |
|
1860 | + if (($cache = $this->getApplication()->getCache()) !== null) |
|
1861 | 1861 | { |
1862 | - if($cache->get(self::CACHE_NAME)===$content) |
|
1863 | - $saveFile=false; |
|
1862 | + if ($cache->get(self::CACHE_NAME) === $content) |
|
1863 | + $saveFile = false; |
|
1864 | 1864 | else |
1865 | - $cache->set(self::CACHE_NAME,$content); |
|
1865 | + $cache->set(self::CACHE_NAME, $content); |
|
1866 | 1866 | } |
1867 | - if($saveFile) |
|
1867 | + if ($saveFile) |
|
1868 | 1868 | { |
1869 | - $fileName=$this->getStateFilePath(); |
|
1870 | - file_put_contents($fileName,$content,LOCK_EX); |
|
1869 | + $fileName = $this->getStateFilePath(); |
|
1870 | + file_put_contents($fileName, $content, LOCK_EX); |
|
1871 | 1871 | } |
1872 | 1872 | } |
1873 | 1873 |
@@ -404,7 +404,7 @@ |
||
404 | 404 | if($this->_requestCompleted) |
405 | 405 | break; |
406 | 406 | $method=self::$_steps[$this->_step]; |
407 | - Prado::trace("Executing $method()",'System.TApplication'); |
|
407 | + Prado::trace("executing $method()",'System.TApplication'); |
|
408 | 408 | $this->$method(); |
409 | 409 | $this->_step++; |
410 | 410 | } |
@@ -49,6 +49,7 @@ |
||
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @param string id of this service |
52 | + * @param string $value |
|
52 | 53 | */ |
53 | 54 | public function setID($value) |
54 | 55 | { |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @var boolean whether the service is enabled |
30 | 30 | */ |
31 | - private $_enabled=true; |
|
31 | + private $_enabled = true; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Initializes the service and attaches {@link run} to the RunService event of application. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function setID($value) |
54 | 54 | { |
55 | - $this->_id=$value; |
|
55 | + $this->_id = $value; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setEnabled($value) |
70 | 70 | { |
71 | - $this->_enabled=TPropertyValue::ensureBoolean($value); |
|
71 | + $this->_enabled = TPropertyValue::ensureBoolean($value); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -98,6 +98,7 @@ |
||
98 | 98 | * @param integer level filter |
99 | 99 | * @param array category filter |
100 | 100 | * @param array control filter |
101 | + * @param integer $levels |
|
101 | 102 | * @return array list of messages. Each array elements represents one message |
102 | 103 | * with the following structure: |
103 | 104 | * array( |
@@ -25,17 +25,17 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * Log levels. |
27 | 27 | */ |
28 | - const DEBUG=0x01; |
|
29 | - const INFO=0x02; |
|
30 | - const NOTICE=0x04; |
|
31 | - const WARNING=0x08; |
|
32 | - const ERROR=0x10; |
|
33 | - const ALERT=0x20; |
|
34 | - const FATAL=0x40; |
|
28 | + const DEBUG = 0x01; |
|
29 | + const INFO = 0x02; |
|
30 | + const NOTICE = 0x04; |
|
31 | + const WARNING = 0x08; |
|
32 | + const ERROR = 0x10; |
|
33 | + const ALERT = 0x20; |
|
34 | + const FATAL = 0x40; |
|
35 | 35 | /** |
36 | 36 | * @var array log messages |
37 | 37 | */ |
38 | - private $_logs=array(); |
|
38 | + private $_logs = array(); |
|
39 | 39 | /** |
40 | 40 | * @var integer log levels (bits) to be filtered |
41 | 41 | */ |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | * @param string category of the message |
64 | 64 | * @param string|TControl control of the message |
65 | 65 | */ |
66 | - public function log($message,$level,$category='Uncategorized', $ctl=null) |
|
66 | + public function log($message, $level, $category = 'Uncategorized', $ctl = null) |
|
67 | 67 | { |
68 | - if($ctl) { |
|
69 | - if($ctl instanceof TControl) |
|
68 | + if ($ctl) { |
|
69 | + if ($ctl instanceof TControl) |
|
70 | 70 | $ctl = $ctl->ClientId; |
71 | - else if(!is_string($ctl)) |
|
71 | + else if (!is_string($ctl)) |
|
72 | 72 | $ctl = null; |
73 | 73 | } else |
74 | 74 | $ctl = null; |
75 | - $this->_logs[]=array($message,$level,$category,microtime(true),memory_get_usage(),$ctl); |
|
75 | + $this->_logs[] = array($message, $level, $category, microtime(true), memory_get_usage(), $ctl); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | * [4] => memory in bytes |
109 | 109 | * [5] => control client id |
110 | 110 | */ |
111 | - public function getLogs($levels=null,$categories=null,$controls=null,$timestamp=null) |
|
111 | + public function getLogs($levels = null, $categories = null, $controls = null, $timestamp = null) |
|
112 | 112 | { |
113 | - $this->_levels=$levels; |
|
114 | - $this->_categories=$categories; |
|
115 | - $this->_controls=$controls; |
|
116 | - $this->_timestamp=$timestamp; |
|
117 | - if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp)) |
|
113 | + $this->_levels = $levels; |
|
114 | + $this->_categories = $categories; |
|
115 | + $this->_controls = $controls; |
|
116 | + $this->_timestamp = $timestamp; |
|
117 | + if (empty($levels) && empty($categories) && empty($controls) && is_null($timestamp)) |
|
118 | 118 | return $this->_logs; |
119 | 119 | $logs = $this->_logs; |
120 | - if(!empty($levels)) |
|
121 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByLevels')) )); |
|
122 | - if(!empty($categories)) |
|
123 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByCategories')) )); |
|
124 | - if(!empty($controls)) |
|
125 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByControl')) )); |
|
126 | - if(!is_null($timestamp)) |
|
127 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByTimeStamp')) )); |
|
120 | + if (!empty($levels)) |
|
121 | + $logs = array_values(array_filter(array_filter($logs, array($this, 'filterByLevels')))); |
|
122 | + if (!empty($categories)) |
|
123 | + $logs = array_values(array_filter(array_filter($logs, array($this, 'filterByCategories')))); |
|
124 | + if (!empty($controls)) |
|
125 | + $logs = array_values(array_filter(array_filter($logs, array($this, 'filterByControl')))); |
|
126 | + if (!is_null($timestamp)) |
|
127 | + $logs = array_values(array_filter(array_filter($logs, array($this, 'filterByTimeStamp')))); |
|
128 | 128 | return $logs; |
129 | 129 | } |
130 | 130 | |
@@ -152,27 +152,27 @@ discard block |
||
152 | 152 | * @param array category filter |
153 | 153 | * @param array control filter |
154 | 154 | */ |
155 | - public function deleteLogs($levels=null,$categories=null,$controls=null,$timestamp=null) |
|
155 | + public function deleteLogs($levels = null, $categories = null, $controls = null, $timestamp = null) |
|
156 | 156 | { |
157 | - $this->_levels=$levels; |
|
158 | - $this->_categories=$categories; |
|
159 | - $this->_controls=$controls; |
|
160 | - $this->_timestamp=$timestamp; |
|
161 | - if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp)) |
|
157 | + $this->_levels = $levels; |
|
158 | + $this->_categories = $categories; |
|
159 | + $this->_controls = $controls; |
|
160 | + $this->_timestamp = $timestamp; |
|
161 | + if (empty($levels) && empty($categories) && empty($controls) && is_null($timestamp)) |
|
162 | 162 | { |
163 | - $this->_logs=array(); |
|
163 | + $this->_logs = array(); |
|
164 | 164 | return; |
165 | 165 | } |
166 | 166 | $logs = $this->_logs; |
167 | - if(!empty($levels)) |
|
168 | - $logs = array_filter( array_filter($logs,array($this,'filterByLevels')) ); |
|
169 | - if(!empty($categories)) |
|
170 | - $logs = array_filter( array_filter($logs,array($this,'filterByCategories')) ); |
|
171 | - if(!empty($controls)) |
|
172 | - $logs = array_filter( array_filter($logs,array($this,'filterByControl')) ); |
|
173 | - if(!is_null($timestamp)) |
|
174 | - $logs = array_filter( array_filter($logs,array($this,'filterByTimeStamp')) ); |
|
175 | - $this->_logs = array_values( array_diff_key($this->_logs, $logs) ); |
|
167 | + if (!empty($levels)) |
|
168 | + $logs = array_filter(array_filter($logs, array($this, 'filterByLevels'))); |
|
169 | + if (!empty($categories)) |
|
170 | + $logs = array_filter(array_filter($logs, array($this, 'filterByCategories'))); |
|
171 | + if (!empty($controls)) |
|
172 | + $logs = array_filter(array_filter($logs, array($this, 'filterByControl'))); |
|
173 | + if (!is_null($timestamp)) |
|
174 | + $logs = array_filter(array_filter($logs, array($this, 'filterByTimeStamp'))); |
|
175 | + $this->_logs = array_values(array_diff_key($this->_logs, $logs)); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | */ |
182 | 182 | private function filterByCategories($value) |
183 | 183 | { |
184 | - foreach($this->_categories as $category) |
|
184 | + foreach ($this->_categories as $category) |
|
185 | 185 | { |
186 | 186 | // element 2 is the category |
187 | - if($value[2]===$category || strpos($value[2],$category.'.')===0) |
|
187 | + if ($value[2] === $category || strpos($value[2], $category . '.') === 0) |
|
188 | 188 | return $value; |
189 | 189 | } |
190 | 190 | return false; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | private function filterByLevels($value) |
198 | 198 | { |
199 | 199 | // element 1 are the levels |
200 | - if($value[1] & $this->_levels) |
|
200 | + if ($value[1] & $this->_levels) |
|
201 | 201 | return $value; |
202 | 202 | else |
203 | 203 | return false; |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | private function filterByControl($value) |
211 | 211 | { |
212 | 212 | // element 5 are the control client ids |
213 | - foreach($this->_controls as $control) |
|
213 | + foreach ($this->_controls as $control) |
|
214 | 214 | { |
215 | - if($value[5]===$control || strpos($value[5],$control)===0) |
|
215 | + if ($value[5] === $control || strpos($value[5], $control) === 0) |
|
216 | 216 | return $value; |
217 | 217 | } |
218 | 218 | return false; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | private function filterByTimeStamp($value) |
226 | 226 | { |
227 | 227 | // element 3 is the timestamp |
228 | - if($value[3] <= $this->_timestamp) |
|
228 | + if ($value[3] <= $this->_timestamp) |
|
229 | 229 | return $value; |
230 | 230 | else |
231 | 231 | return false; |
@@ -105,6 +105,9 @@ |
||
105 | 105 | * @param string RPC server URL |
106 | 106 | * @param array payload data |
107 | 107 | * @param string request mime type |
108 | + * @param string $serverUrl |
|
109 | + * @param string $mimeType |
|
110 | + * @return string |
|
108 | 111 | */ |
109 | 112 | protected function performRequest($serverUrl, $payload, $mimeType) |
110 | 113 | { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public static function create($type, $serverUrl, $isNotification = false) |
80 | 80 | { |
81 | - if(($_handler = constant('TRpcClientTypesEnumerable::'.strtoupper($type))) === null) |
|
81 | + if (($_handler = constant('TRpcClientTypesEnumerable::' . strtoupper($type))) === null) |
|
82 | 82 | throw new TApplicationException('rpcclient_unsupported_handler'); |
83 | 83 | |
84 | 84 | return new $_handler($serverUrl, $isNotification); |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function performRequest($serverUrl, $payload, $mimeType) |
110 | 110 | { |
111 | - if(($_response = @file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType))) === false) |
|
112 | - throw new TRpcClientRequestException('Request failed ("'.$http_response_header[0].'")'); |
|
111 | + if (($_response = @file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType))) === false) |
|
112 | + throw new TRpcClientRequestException('Request failed ("' . $http_response_header[0] . '")'); |
|
113 | 113 | |
114 | 114 | return $_response; |
115 | 115 | } |
@@ -242,15 +242,15 @@ discard block |
||
242 | 242 | $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'application/json'); |
243 | 243 | |
244 | 244 | // skip response handling if the request was just a notification request |
245 | - if($this->isNotification) |
|
245 | + if ($this->isNotification) |
|
246 | 246 | return true; |
247 | 247 | |
248 | 248 | // decode response |
249 | - if(($_response = json_decode($_response, true)) === null) |
|
249 | + if (($_response = json_decode($_response, true)) === null) |
|
250 | 250 | throw new TRpcClientResponseException('Empty response received'); |
251 | 251 | |
252 | 252 | // handle error response |
253 | - if(!is_null($_response['error'])) |
|
253 | + if (!is_null($_response['error'])) |
|
254 | 254 | throw new TRpcClientResponseException($_response['error']); |
255 | 255 | |
256 | 256 | return $_response['result']; |
@@ -320,15 +320,15 @@ discard block |
||
320 | 320 | $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'text/xml'); |
321 | 321 | |
322 | 322 | // skip response handling if the request was just a notification request |
323 | - if($this->isNotification) |
|
323 | + if ($this->isNotification) |
|
324 | 324 | return true; |
325 | 325 | |
326 | 326 | // decode response |
327 | - if(($_response = xmlrpc_decode($_response)) === null) |
|
327 | + if (($_response = xmlrpc_decode($_response)) === null) |
|
328 | 328 | throw new TRpcClientResponseException('Empty response received'); |
329 | 329 | |
330 | 330 | // handle error response |
331 | - if(xmlrpc_is_fault($_response)) |
|
331 | + if (xmlrpc_is_fault($_response)) |
|
332 | 332 | throw new TRpcClientResponseException($_response['faultString'], $_response['faultCode']); |
333 | 333 | |
334 | 334 | return $_response; |
@@ -73,6 +73,9 @@ discard block |
||
73 | 73 | |
74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
75 | 75 | |
76 | + /** |
|
77 | + * @param integer $d |
|
78 | + */ |
|
76 | 79 | protected function action($d) { |
77 | 80 | switch($d) { |
78 | 81 | case 1: |
@@ -132,6 +135,9 @@ discard block |
||
132 | 135 | } |
133 | 136 | } |
134 | 137 | |
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
135 | 141 | protected function get() { |
136 | 142 | $c = $this->lookAhead; |
137 | 143 | $this->lookAhead = null; |
@@ -156,6 +162,9 @@ discard block |
||
156 | 162 | return ' '; |
157 | 163 | } |
158 | 164 | |
165 | + /** |
|
166 | + * @param string $c |
|
167 | + */ |
|
159 | 168 | protected function isAlphaNum($c) { |
160 | 169 | return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
161 | 170 | } |
@@ -60,229 +60,229 @@ |
||
60 | 60 | // -- Public Static Methods -------------------------------------------------- |
61 | 61 | |
62 | 62 | public static function minify($js) { |
63 | - $jsmin = new JSMin($js); |
|
64 | - return $jsmin->min(); |
|
63 | + $jsmin = new JSMin($js); |
|
64 | + return $jsmin->min(); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // -- Public Instance Methods ------------------------------------------------ |
68 | 68 | |
69 | 69 | public function __construct($input) { |
70 | - $this->input = str_replace("\r\n", "\n", $input); |
|
71 | - $this->inputLength = strlen($this->input); |
|
70 | + $this->input = str_replace("\r\n", "\n", $input); |
|
71 | + $this->inputLength = strlen($this->input); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
75 | 75 | |
76 | 76 | protected function action($d) { |
77 | - switch($d) { |
|
78 | - case 1: |
|
79 | - $this->output .= $this->a; |
|
80 | - |
|
81 | - case 2: |
|
82 | - $this->a = $this->b; |
|
83 | - |
|
84 | - if ($this->a === "'" || $this->a === '"') { |
|
85 | - for (;;) { |
|
86 | - $this->output .= $this->a; |
|
87 | - $this->a = $this->get(); |
|
88 | - |
|
89 | - if ($this->a === $this->b) { |
|
90 | - break; |
|
91 | - } |
|
92 | - |
|
93 | - if (ord($this->a) <= self::ORD_LF) { |
|
94 | - throw new JSMinException('Unterminated string literal.'); |
|
95 | - } |
|
96 | - |
|
97 | - if ($this->a === '\\') { |
|
98 | - $this->output .= $this->a; |
|
99 | - $this->a = $this->get(); |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - case 3: |
|
105 | - $this->b = $this->next(); |
|
106 | - |
|
107 | - if ($this->b === '/' && ( |
|
108 | - $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
109 | - $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
110 | - $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
111 | - |
|
112 | - $this->output .= $this->a . $this->b; |
|
113 | - |
|
114 | - for (;;) { |
|
115 | - $this->a = $this->get(); |
|
116 | - |
|
117 | - if ($this->a === '/') { |
|
118 | - break; |
|
119 | - } elseif ($this->a === '\\') { |
|
120 | - $this->output .= $this->a; |
|
121 | - $this->a = $this->get(); |
|
122 | - } elseif (ord($this->a) <= self::ORD_LF) { |
|
123 | - throw new JSMinException('Unterminated regular expression '. |
|
124 | - 'literal.'); |
|
125 | - } |
|
126 | - |
|
127 | - $this->output .= $this->a; |
|
128 | - } |
|
129 | - |
|
130 | - $this->b = $this->next(); |
|
131 | - } |
|
132 | - } |
|
77 | + switch($d) { |
|
78 | + case 1: |
|
79 | + $this->output .= $this->a; |
|
80 | + |
|
81 | + case 2: |
|
82 | + $this->a = $this->b; |
|
83 | + |
|
84 | + if ($this->a === "'" || $this->a === '"') { |
|
85 | + for (;;) { |
|
86 | + $this->output .= $this->a; |
|
87 | + $this->a = $this->get(); |
|
88 | + |
|
89 | + if ($this->a === $this->b) { |
|
90 | + break; |
|
91 | + } |
|
92 | + |
|
93 | + if (ord($this->a) <= self::ORD_LF) { |
|
94 | + throw new JSMinException('Unterminated string literal.'); |
|
95 | + } |
|
96 | + |
|
97 | + if ($this->a === '\\') { |
|
98 | + $this->output .= $this->a; |
|
99 | + $this->a = $this->get(); |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + case 3: |
|
105 | + $this->b = $this->next(); |
|
106 | + |
|
107 | + if ($this->b === '/' && ( |
|
108 | + $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
109 | + $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
110 | + $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
111 | + |
|
112 | + $this->output .= $this->a . $this->b; |
|
113 | + |
|
114 | + for (;;) { |
|
115 | + $this->a = $this->get(); |
|
116 | + |
|
117 | + if ($this->a === '/') { |
|
118 | + break; |
|
119 | + } elseif ($this->a === '\\') { |
|
120 | + $this->output .= $this->a; |
|
121 | + $this->a = $this->get(); |
|
122 | + } elseif (ord($this->a) <= self::ORD_LF) { |
|
123 | + throw new JSMinException('Unterminated regular expression '. |
|
124 | + 'literal.'); |
|
125 | + } |
|
126 | + |
|
127 | + $this->output .= $this->a; |
|
128 | + } |
|
129 | + |
|
130 | + $this->b = $this->next(); |
|
131 | + } |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | protected function get() { |
136 | - $c = $this->lookAhead; |
|
137 | - $this->lookAhead = null; |
|
138 | - |
|
139 | - if ($c === null) { |
|
140 | - if ($this->inputIndex < $this->inputLength) { |
|
141 | - $c = $this->input[$this->inputIndex]; |
|
142 | - $this->inputIndex += 1; |
|
143 | - } else { |
|
144 | - $c = null; |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - if ($c === "\r") { |
|
149 | - return "\n"; |
|
150 | - } |
|
151 | - |
|
152 | - if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
153 | - return $c; |
|
154 | - } |
|
155 | - |
|
156 | - return ' '; |
|
136 | + $c = $this->lookAhead; |
|
137 | + $this->lookAhead = null; |
|
138 | + |
|
139 | + if ($c === null) { |
|
140 | + if ($this->inputIndex < $this->inputLength) { |
|
141 | + $c = $this->input[$this->inputIndex]; |
|
142 | + $this->inputIndex += 1; |
|
143 | + } else { |
|
144 | + $c = null; |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + if ($c === "\r") { |
|
149 | + return "\n"; |
|
150 | + } |
|
151 | + |
|
152 | + if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
153 | + return $c; |
|
154 | + } |
|
155 | + |
|
156 | + return ' '; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | protected function isAlphaNum($c) { |
160 | - return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
160 | + return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | protected function min() { |
164 | - $this->a = "\n"; |
|
165 | - $this->action(3); |
|
166 | - |
|
167 | - while ($this->a !== null) { |
|
168 | - switch ($this->a) { |
|
169 | - case ' ': |
|
170 | - if ($this->isAlphaNum($this->b)) { |
|
171 | - $this->action(1); |
|
172 | - } else { |
|
173 | - $this->action(2); |
|
174 | - } |
|
175 | - break; |
|
176 | - |
|
177 | - case "\n": |
|
178 | - switch ($this->b) { |
|
179 | - case '{': |
|
180 | - case '[': |
|
181 | - case '(': |
|
182 | - case '+': |
|
183 | - case '-': |
|
184 | - $this->action(1); |
|
185 | - break; |
|
186 | - |
|
187 | - case ' ': |
|
188 | - $this->action(3); |
|
189 | - break; |
|
190 | - |
|
191 | - default: |
|
192 | - if ($this->isAlphaNum($this->b)) { |
|
193 | - $this->action(1); |
|
194 | - } |
|
195 | - else { |
|
196 | - $this->action(2); |
|
197 | - } |
|
198 | - } |
|
199 | - break; |
|
200 | - |
|
201 | - default: |
|
202 | - switch ($this->b) { |
|
203 | - case ' ': |
|
204 | - if ($this->isAlphaNum($this->a)) { |
|
205 | - $this->action(1); |
|
206 | - break; |
|
207 | - } |
|
208 | - |
|
209 | - $this->action(3); |
|
210 | - break; |
|
211 | - |
|
212 | - case "\n": |
|
213 | - switch ($this->a) { |
|
214 | - case '}': |
|
215 | - case ']': |
|
216 | - case ')': |
|
217 | - case '+': |
|
218 | - case '-': |
|
219 | - case '"': |
|
220 | - case "'": |
|
221 | - $this->action(1); |
|
222 | - break; |
|
223 | - |
|
224 | - default: |
|
225 | - if ($this->isAlphaNum($this->a)) { |
|
226 | - $this->action(1); |
|
227 | - } |
|
228 | - else { |
|
229 | - $this->action(3); |
|
230 | - } |
|
231 | - } |
|
232 | - break; |
|
233 | - |
|
234 | - default: |
|
235 | - $this->action(1); |
|
236 | - break; |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - return $this->output; |
|
164 | + $this->a = "\n"; |
|
165 | + $this->action(3); |
|
166 | + |
|
167 | + while ($this->a !== null) { |
|
168 | + switch ($this->a) { |
|
169 | + case ' ': |
|
170 | + if ($this->isAlphaNum($this->b)) { |
|
171 | + $this->action(1); |
|
172 | + } else { |
|
173 | + $this->action(2); |
|
174 | + } |
|
175 | + break; |
|
176 | + |
|
177 | + case "\n": |
|
178 | + switch ($this->b) { |
|
179 | + case '{': |
|
180 | + case '[': |
|
181 | + case '(': |
|
182 | + case '+': |
|
183 | + case '-': |
|
184 | + $this->action(1); |
|
185 | + break; |
|
186 | + |
|
187 | + case ' ': |
|
188 | + $this->action(3); |
|
189 | + break; |
|
190 | + |
|
191 | + default: |
|
192 | + if ($this->isAlphaNum($this->b)) { |
|
193 | + $this->action(1); |
|
194 | + } |
|
195 | + else { |
|
196 | + $this->action(2); |
|
197 | + } |
|
198 | + } |
|
199 | + break; |
|
200 | + |
|
201 | + default: |
|
202 | + switch ($this->b) { |
|
203 | + case ' ': |
|
204 | + if ($this->isAlphaNum($this->a)) { |
|
205 | + $this->action(1); |
|
206 | + break; |
|
207 | + } |
|
208 | + |
|
209 | + $this->action(3); |
|
210 | + break; |
|
211 | + |
|
212 | + case "\n": |
|
213 | + switch ($this->a) { |
|
214 | + case '}': |
|
215 | + case ']': |
|
216 | + case ')': |
|
217 | + case '+': |
|
218 | + case '-': |
|
219 | + case '"': |
|
220 | + case "'": |
|
221 | + $this->action(1); |
|
222 | + break; |
|
223 | + |
|
224 | + default: |
|
225 | + if ($this->isAlphaNum($this->a)) { |
|
226 | + $this->action(1); |
|
227 | + } |
|
228 | + else { |
|
229 | + $this->action(3); |
|
230 | + } |
|
231 | + } |
|
232 | + break; |
|
233 | + |
|
234 | + default: |
|
235 | + $this->action(1); |
|
236 | + break; |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + return $this->output; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | protected function next() { |
245 | - $c = $this->get(); |
|
246 | - |
|
247 | - if ($c === '/') { |
|
248 | - switch($this->peek()) { |
|
249 | - case '/': |
|
250 | - for (;;) { |
|
251 | - $c = $this->get(); |
|
252 | - |
|
253 | - if (ord($c) <= self::ORD_LF) { |
|
254 | - return $c; |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - case '*': |
|
259 | - $this->get(); |
|
260 | - |
|
261 | - for (;;) { |
|
262 | - switch($this->get()) { |
|
263 | - case '*': |
|
264 | - if ($this->peek() === '/') { |
|
265 | - $this->get(); |
|
266 | - return ' '; |
|
267 | - } |
|
268 | - break; |
|
269 | - |
|
270 | - case null: |
|
271 | - throw new JSMinException('Unterminated comment.'); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - default: |
|
276 | - return $c; |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - return $c; |
|
245 | + $c = $this->get(); |
|
246 | + |
|
247 | + if ($c === '/') { |
|
248 | + switch($this->peek()) { |
|
249 | + case '/': |
|
250 | + for (;;) { |
|
251 | + $c = $this->get(); |
|
252 | + |
|
253 | + if (ord($c) <= self::ORD_LF) { |
|
254 | + return $c; |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + case '*': |
|
259 | + $this->get(); |
|
260 | + |
|
261 | + for (;;) { |
|
262 | + switch($this->get()) { |
|
263 | + case '*': |
|
264 | + if ($this->peek() === '/') { |
|
265 | + $this->get(); |
|
266 | + return ' '; |
|
267 | + } |
|
268 | + break; |
|
269 | + |
|
270 | + case null: |
|
271 | + throw new JSMinException('Unterminated comment.'); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + default: |
|
276 | + return $c; |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + return $c; |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | protected function peek() { |
284 | - $this->lookAhead = $this->get(); |
|
285 | - return $this->lookAhead; |
|
284 | + $this->lookAhead = $this->get(); |
|
285 | + return $this->lookAhead; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
75 | 75 | |
76 | 76 | protected function action($d) { |
77 | - switch($d) { |
|
77 | + switch ($d) { |
|
78 | 78 | case 1: |
79 | 79 | $this->output .= $this->a; |
80 | 80 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $this->output .= $this->a; |
121 | 121 | $this->a = $this->get(); |
122 | 122 | } elseif (ord($this->a) <= self::ORD_LF) { |
123 | - throw new JSMinException('Unterminated regular expression '. |
|
123 | + throw new JSMinException('Unterminated regular expression ' . |
|
124 | 124 | 'literal.'); |
125 | 125 | } |
126 | 126 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | $c = $this->get(); |
246 | 246 | |
247 | 247 | if ($c === '/') { |
248 | - switch($this->peek()) { |
|
248 | + switch ($this->peek()) { |
|
249 | 249 | case '/': |
250 | 250 | for (;;) { |
251 | 251 | $c = $this->get(); |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $this->get(); |
260 | 260 | |
261 | 261 | for (;;) { |
262 | - switch($this->get()) { |
|
262 | + switch ($this->get()) { |
|
263 | 263 | case '*': |
264 | 264 | if ($this->peek() === '/') { |
265 | 265 | $this->get(); |
@@ -191,8 +191,7 @@ discard block |
||
191 | 191 | default: |
192 | 192 | if ($this->isAlphaNum($this->b)) { |
193 | 193 | $this->action(1); |
194 | - } |
|
195 | - else { |
|
194 | + } else { |
|
196 | 195 | $this->action(2); |
197 | 196 | } |
198 | 197 | } |
@@ -224,8 +223,7 @@ discard block |
||
224 | 223 | default: |
225 | 224 | if ($this->isAlphaNum($this->a)) { |
226 | 225 | $this->action(1); |
227 | - } |
|
228 | - else { |
|
226 | + } else { |
|
229 | 227 | $this->action(3); |
230 | 228 | } |
231 | 229 | } |