@@ -38,6 +38,7 @@ |
||
38 | 38 | /** |
39 | 39 | * Writes a string. |
40 | 40 | * @param string string to be written |
41 | + * @param string $str |
|
41 | 42 | */ |
42 | 43 | public function write($str) |
43 | 44 | { |
@@ -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( |
@@ -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 | 68 | if($ctl) { |
69 | 69 | if($ctl instanceof TControl) |
70 | - $ctl = $ctl->ClientId; |
|
70 | + $ctl=$ctl->ClientId; |
|
71 | 71 | else if(!is_string($ctl)) |
72 | - $ctl = null; |
|
72 | + $ctl=null; |
|
73 | 73 | } else |
74 | - $ctl = null; |
|
75 | - $this->_logs[]=array($message,$level,$category,microtime(true),memory_get_usage(),$ctl); |
|
74 | + $ctl=null; |
|
75 | + $this->_logs[]=array($message, $level, $category, microtime(true), memory_get_usage(), $ctl); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -108,7 +108,7 @@ 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 | 113 | $this->_levels=$levels; |
114 | 114 | $this->_categories=$categories; |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | $this->_timestamp=$timestamp; |
117 | 117 | if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp)) |
118 | 118 | return $this->_logs; |
119 | - $logs = $this->_logs; |
|
119 | + $logs=$this->_logs; |
|
120 | 120 | if(!empty($levels)) |
121 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByLevels')) )); |
|
121 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByLevels')))); |
|
122 | 122 | if(!empty($categories)) |
123 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByCategories')) )); |
|
123 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByCategories')))); |
|
124 | 124 | if(!empty($controls)) |
125 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByControl')) )); |
|
125 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByControl')))); |
|
126 | 126 | if(!is_null($timestamp)) |
127 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByTimeStamp')) )); |
|
127 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByTimeStamp')))); |
|
128 | 128 | return $logs; |
129 | 129 | } |
130 | 130 | |
@@ -152,7 +152,7 @@ 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 | 157 | $this->_levels=$levels; |
158 | 158 | $this->_categories=$categories; |
@@ -163,16 +163,16 @@ discard block |
||
163 | 163 | $this->_logs=array(); |
164 | 164 | return; |
165 | 165 | } |
166 | - $logs = $this->_logs; |
|
166 | + $logs=$this->_logs; |
|
167 | 167 | if(!empty($levels)) |
168 | - $logs = array_filter( array_filter($logs,array($this,'filterByLevels')) ); |
|
168 | + $logs=array_filter(array_filter($logs, array($this, 'filterByLevels'))); |
|
169 | 169 | if(!empty($categories)) |
170 | - $logs = array_filter( array_filter($logs,array($this,'filterByCategories')) ); |
|
170 | + $logs=array_filter(array_filter($logs, array($this, 'filterByCategories'))); |
|
171 | 171 | if(!empty($controls)) |
172 | - $logs = array_filter( array_filter($logs,array($this,'filterByControl')) ); |
|
172 | + $logs=array_filter(array_filter($logs, array($this, 'filterByControl'))); |
|
173 | 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) ); |
|
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 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 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; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | // element 5 are the control client ids |
213 | 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; |
@@ -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 | { |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * @var boolean whether the request is a notification and therefore should not care about the result (default: false) |
59 | 59 | */ |
60 | - private $_isNotification = false; |
|
60 | + private $_isNotification=false; |
|
61 | 61 | |
62 | 62 | // magics |
63 | 63 | |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | * @param string url to RPC server |
66 | 66 | * @param boolean whether requests are considered to be notifications (completely ignoring the response) (default: false) |
67 | 67 | */ |
68 | - public function __construct($serverUrl, $isNotification = false) |
|
68 | + public function __construct($serverUrl, $isNotification=false) |
|
69 | 69 | { |
70 | - $this->_serverUrl = $serverUrl; |
|
71 | - $this->_isNotification = TPropertyValue::ensureBoolean($isNotification); |
|
70 | + $this->_serverUrl=$serverUrl; |
|
71 | + $this->_isNotification=TPropertyValue::ensureBoolean($isNotification); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // methods |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | * @return TRpcClient instance |
79 | 79 | * @throws TApplicationException if an unsupported RPC client type was specified |
80 | 80 | */ |
81 | - public static function create($type, $serverUrl, $isNotification = false) |
|
81 | + public static function create($type, $serverUrl, $isNotification=false) |
|
82 | 82 | { |
83 | - if(($_handler = constant('TRpcClientTypesEnumerable::'.strtoupper($type))) === null) |
|
83 | + if(($_handler=constant('TRpcClientTypesEnumerable::'.strtoupper($type)))===null) |
|
84 | 84 | throw new TApplicationException('rpcclient_unsupported_handler'); |
85 | 85 | |
86 | 86 | return new $_handler($serverUrl, $isNotification); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | protected function performRequest($serverUrl, $payload, $mimeType) |
112 | 112 | { |
113 | - if(($_response = @file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType))) === false) |
|
113 | + if(($_response=@file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType)))===false) |
|
114 | 114 | throw new TRpcClientRequestException('Request failed ("'.$http_response_header[0].'")'); |
115 | 115 | |
116 | 116 | return $_response; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function setIsNotification($bool) |
133 | 133 | { |
134 | - $this->_isNotification = TPropertyValue::ensureBoolean($bool); |
|
134 | + $this->_isNotification=TPropertyValue::ensureBoolean($bool); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -147,6 +147,6 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function setServerUrl($value) |
149 | 149 | { |
150 | - $this->_serverUrl = $value; |
|
150 | + $this->_serverUrl=$value; |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | \ No newline at end of file |
@@ -60,6 +60,7 @@ discard block |
||
60 | 60 | * Constructor, create a new date time formatter. |
61 | 61 | * @param string formatting pattern. |
62 | 62 | * @param string pattern and value charset |
63 | + * @param string $pattern |
|
63 | 64 | */ |
64 | 65 | public function __construct($pattern, $charset='UTF-8') |
65 | 66 | { |
@@ -93,6 +94,7 @@ discard block |
||
93 | 94 | |
94 | 95 | /** |
95 | 96 | * @param string formatting charset. |
97 | + * @param string $charset |
|
96 | 98 | */ |
97 | 99 | public function setCharset($charset) |
98 | 100 | { |
@@ -313,6 +315,7 @@ discard block |
||
313 | 315 | |
314 | 316 | /** |
315 | 317 | * Calculate the length of a string, may be consider iconv_strlen? |
318 | + * @param string $string |
|
316 | 319 | */ |
317 | 320 | private function length($string) |
318 | 321 | { |
@@ -338,6 +341,9 @@ discard block |
||
338 | 341 | |
339 | 342 | /** |
340 | 343 | * Returns true if char at position equals a particular char. |
344 | + * @param string $string |
|
345 | + * @param integer $pos |
|
346 | + * @param string $char |
|
341 | 347 | */ |
342 | 348 | private function charEqual($string, $pos, $char) |
343 | 349 | { |
@@ -350,6 +356,10 @@ discard block |
||
350 | 356 | * @param int starting position |
351 | 357 | * @param int minimum integer length |
352 | 358 | * @param int maximum integer length |
359 | + * @param string $str |
|
360 | + * @param integer $i |
|
361 | + * @param integer|null $minlength |
|
362 | + * @param integer|null $maxlength |
|
353 | 363 | * @return string integer portion of the string, null otherwise |
354 | 364 | */ |
355 | 365 | private function getInteger($str,$i,$minlength,$maxlength) |
@@ -225,8 +225,7 @@ discard block |
||
225 | 225 | $year = "{$date['year']}"; |
226 | 226 | $month = $date['mon']; |
227 | 227 | $day = $date['mday']; |
228 | - } |
|
229 | - else |
|
228 | + } else |
|
230 | 229 | { |
231 | 230 | $year = null; |
232 | 231 | $month = null; |
@@ -262,8 +261,7 @@ discard block |
||
262 | 261 | $year = $iYear + 2000; |
263 | 262 | } |
264 | 263 | $year = (int)$year; |
265 | - } |
|
266 | - elseif($token=='MM' || $token=='M') |
|
264 | + } elseif($token=='MM' || $token=='M') |
|
267 | 265 | { |
268 | 266 | $month=$this->getInteger($value,$i_val, |
269 | 267 | $this->length($token),2); |
@@ -273,8 +271,7 @@ discard block |
||
273 | 271 | //throw new TInvalidDataValueException('Invalid month', $value); |
274 | 272 | $i_val += strlen($month); |
275 | 273 | $month = $iMonth; |
276 | - } |
|
277 | - elseif ($token=='dd' || $token=='d') |
|
274 | + } elseif ($token=='dd' || $token=='d') |
|
278 | 275 | { |
279 | 276 | $day = $this->getInteger($value,$i_val, |
280 | 277 | $this->length($token), 2); |
@@ -284,8 +281,7 @@ discard block |
||
284 | 281 | //throw new TInvalidDataValueException('Invalid day', $value); |
285 | 282 | $i_val += strlen($day); |
286 | 283 | $day = $iDay; |
287 | - } |
|
288 | - else |
|
284 | + } else |
|
289 | 285 | { |
290 | 286 | if($this->substring($value, $i_val, $this->length($token)) != $token) |
291 | 287 | return null; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * Charset, default is 'UTF-8' |
61 | 61 | * @var string |
62 | 62 | */ |
63 | - private $charset = 'UTF-8'; |
|
63 | + private $charset='UTF-8'; |
|
64 | 64 | |
65 | 65 | /** |
66 | 66 | * Constructor, create a new date time formatter. |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function setPattern($pattern) |
88 | 88 | { |
89 | - $this->pattern = $pattern; |
|
89 | + $this->pattern=$pattern; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function setCharset($charset) |
104 | 104 | { |
105 | - $this->charset = $charset; |
|
105 | + $this->charset=$charset; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,17 +112,17 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function format($value) |
114 | 114 | { |
115 | - $date = $this->getDate($value); |
|
116 | - $bits['yyyy'] = $date['year']; |
|
117 | - $bits['yy'] = substr("{$date['year']}", -2); |
|
115 | + $date=$this->getDate($value); |
|
116 | + $bits['yyyy']=$date['year']; |
|
117 | + $bits['yy']=substr("{$date['year']}", -2); |
|
118 | 118 | |
119 | - $bits['MM'] = str_pad("{$date['mon']}", 2, '0', STR_PAD_LEFT); |
|
120 | - $bits['M'] = $date['mon']; |
|
119 | + $bits['MM']=str_pad("{$date['mon']}", 2, '0', STR_PAD_LEFT); |
|
120 | + $bits['M']=$date['mon']; |
|
121 | 121 | |
122 | - $bits['dd'] = str_pad("{$date['mday']}", 2, '0', STR_PAD_LEFT); |
|
123 | - $bits['d'] = $date['mday']; |
|
122 | + $bits['dd']=str_pad("{$date['mday']}", 2, '0', STR_PAD_LEFT); |
|
123 | + $bits['d']=$date['mday']; |
|
124 | 124 | |
125 | - $pattern = preg_replace('/M{3,4}/', 'MM', $this->pattern); |
|
125 | + $pattern=preg_replace('/M{3,4}/', 'MM', $this->pattern); |
|
126 | 126 | return str_replace(array_keys($bits), $bits, $pattern); |
127 | 127 | } |
128 | 128 | |
@@ -159,13 +159,13 @@ discard block |
||
159 | 159 | |
160 | 160 | public function getDayMonthYearOrdering() |
161 | 161 | { |
162 | - $ordering = array(); |
|
163 | - if(is_int($day= strpos($this->pattern, 'd'))) |
|
164 | - $ordering['day'] = $day; |
|
165 | - if(is_int($month= strpos($this->pattern, 'M'))) |
|
166 | - $ordering['month'] = $month; |
|
167 | - if(is_int($year= strpos($this->pattern, 'yy'))) |
|
168 | - $ordering['year'] = $year; |
|
162 | + $ordering=array(); |
|
163 | + if(is_int($day=strpos($this->pattern, 'd'))) |
|
164 | + $ordering['day']=$day; |
|
165 | + if(is_int($month=strpos($this->pattern, 'M'))) |
|
166 | + $ordering['month']=$month; |
|
167 | + if(is_int($year=strpos($this->pattern, 'yy'))) |
|
168 | + $ordering['year']=$year; |
|
169 | 169 | asort($ordering); |
170 | 170 | return array_keys($ordering); |
171 | 171 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | private function getDate($value) |
179 | 179 | { |
180 | - $s = new TDateTimeStamp; |
|
180 | + $s=new TDateTimeStamp; |
|
181 | 181 | if(is_numeric($value)) |
182 | 182 | return $s->getDate($value); |
183 | 183 | else |
@@ -189,10 +189,10 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function isValidDate($value) |
191 | 191 | { |
192 | - if($value === null) { |
|
192 | + if($value===null) { |
|
193 | 193 | return false; |
194 | 194 | } else { |
195 | - return $this->parse($value, false) !== null; |
|
195 | + return $this->parse($value, false)!==null; |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return int date time stamp |
203 | 203 | * @throws TInvalidDataValueException if date string is malformed. |
204 | 204 | */ |
205 | - public function parse($value,$defaultToCurrentTime=true) |
|
205 | + public function parse($value, $defaultToCurrentTime=true) |
|
206 | 206 | { |
207 | 207 | if(is_int($value) || is_float($value)) |
208 | 208 | return $value; |
@@ -211,108 +211,108 @@ discard block |
||
211 | 211 | |
212 | 212 | if(empty($this->pattern)) return time(); |
213 | 213 | |
214 | - $date = time(); |
|
214 | + $date=time(); |
|
215 | 215 | |
216 | 216 | if($this->length(trim($value)) < 1) |
217 | 217 | return $defaultToCurrentTime ? $date : null; |
218 | 218 | |
219 | - $pattern = $this->pattern; |
|
219 | + $pattern=$this->pattern; |
|
220 | 220 | |
221 | - $i_val = 0; |
|
222 | - $i_format = 0; |
|
223 | - $pattern_length = $this->length($pattern); |
|
224 | - $c = ''; |
|
221 | + $i_val=0; |
|
222 | + $i_format=0; |
|
223 | + $pattern_length=$this->length($pattern); |
|
224 | + $c=''; |
|
225 | 225 | $token=''; |
226 | 226 | $x=null; $y=null; |
227 | 227 | |
228 | 228 | |
229 | 229 | if($defaultToCurrentTime) |
230 | 230 | { |
231 | - $year = "{$date['year']}"; |
|
232 | - $month = $date['mon']; |
|
233 | - $day = $date['mday']; |
|
231 | + $year="{$date['year']}"; |
|
232 | + $month=$date['mon']; |
|
233 | + $day=$date['mday']; |
|
234 | 234 | } |
235 | 235 | else |
236 | 236 | { |
237 | - $year = null; |
|
238 | - $month = null; |
|
239 | - $day = null; |
|
237 | + $year=null; |
|
238 | + $month=null; |
|
239 | + $day=null; |
|
240 | 240 | } |
241 | 241 | |
242 | - while ($i_format < $pattern_length) |
|
242 | + while($i_format < $pattern_length) |
|
243 | 243 | { |
244 | - $c = $this->charAt($pattern,$i_format); |
|
244 | + $c=$this->charAt($pattern, $i_format); |
|
245 | 245 | $token=''; |
246 | - while ($this->charEqual($pattern, $i_format, $c) |
|
246 | + while($this->charEqual($pattern, $i_format, $c) |
|
247 | 247 | && ($i_format < $pattern_length)) |
248 | 248 | { |
249 | - $token .= $this->charAt($pattern, $i_format++); |
|
249 | + $token.=$this->charAt($pattern, $i_format++); |
|
250 | 250 | } |
251 | 251 | |
252 | - if ($token=='yyyy' || $token=='yy' || $token=='y') |
|
252 | + if($token=='yyyy' || $token=='yy' || $token=='y') |
|
253 | 253 | { |
254 | - if ($token=='yyyy') { $x=4;$y=4; } |
|
255 | - if ($token=='yy') { $x=2;$y=2; } |
|
256 | - if ($token=='y') { $x=2;$y=4; } |
|
257 | - $year = $this->getInteger($value,$i_val,$x,$y); |
|
258 | - if($year === null) |
|
254 | + if($token=='yyyy') { $x=4; $y=4; } |
|
255 | + if($token=='yy') { $x=2; $y=2; } |
|
256 | + if($token=='y') { $x=2; $y=4; } |
|
257 | + $year=$this->getInteger($value, $i_val, $x, $y); |
|
258 | + if($year===null) |
|
259 | 259 | return null; |
260 | 260 | //throw new TInvalidDataValueException('Invalid year', $value); |
261 | - $i_val += strlen($year); |
|
262 | - if(strlen($year) == 2) |
|
261 | + $i_val+=strlen($year); |
|
262 | + if(strlen($year)==2) |
|
263 | 263 | { |
264 | - $iYear = (int)$year; |
|
264 | + $iYear=(int) $year; |
|
265 | 265 | if($iYear > 70) |
266 | - $year = $iYear + 1900; |
|
266 | + $year=$iYear + 1900; |
|
267 | 267 | else |
268 | - $year = $iYear + 2000; |
|
268 | + $year=$iYear + 2000; |
|
269 | 269 | } |
270 | - $year = (int)$year; |
|
270 | + $year=(int) $year; |
|
271 | 271 | } |
272 | 272 | elseif($token=='MM' || $token=='M') |
273 | 273 | { |
274 | - $month=$this->getInteger($value,$i_val, |
|
275 | - $this->length($token),2); |
|
276 | - $iMonth = (int)$month; |
|
277 | - if($month === null || $iMonth < 1 || $iMonth > 12 ) |
|
274 | + $month=$this->getInteger($value, $i_val, |
|
275 | + $this->length($token), 2); |
|
276 | + $iMonth=(int) $month; |
|
277 | + if($month===null || $iMonth < 1 || $iMonth > 12) |
|
278 | 278 | return null; |
279 | 279 | //throw new TInvalidDataValueException('Invalid month', $value); |
280 | - $i_val += strlen($month); |
|
281 | - $month = $iMonth; |
|
280 | + $i_val+=strlen($month); |
|
281 | + $month=$iMonth; |
|
282 | 282 | } |
283 | - elseif ($token=='dd' || $token=='d') |
|
283 | + elseif($token=='dd' || $token=='d') |
|
284 | 284 | { |
285 | - $day = $this->getInteger($value,$i_val, |
|
285 | + $day=$this->getInteger($value, $i_val, |
|
286 | 286 | $this->length($token), 2); |
287 | - $iDay = (int)$day; |
|
288 | - if($day === null || $iDay < 1 || $iDay >31) |
|
287 | + $iDay=(int) $day; |
|
288 | + if($day===null || $iDay < 1 || $iDay > 31) |
|
289 | 289 | return null; |
290 | 290 | //throw new TInvalidDataValueException('Invalid day', $value); |
291 | - $i_val += strlen($day); |
|
292 | - $day = $iDay; |
|
291 | + $i_val+=strlen($day); |
|
292 | + $day=$iDay; |
|
293 | 293 | } |
294 | 294 | else |
295 | 295 | { |
296 | - if($this->substring($value, $i_val, $this->length($token)) != $token) |
|
296 | + if($this->substring($value, $i_val, $this->length($token))!=$token) |
|
297 | 297 | return null; |
298 | 298 | //throw new TInvalidDataValueException("Subpattern '{$this->pattern}' mismatch", $value); |
299 | 299 | else |
300 | - $i_val += $this->length($token); |
|
300 | + $i_val+=$this->length($token); |
|
301 | 301 | } |
302 | 302 | } |
303 | - if ($i_val != $this->length($value)) |
|
303 | + if($i_val!=$this->length($value)) |
|
304 | 304 | return null; |
305 | 305 | //throw new TInvalidDataValueException("Pattern '{$this->pattern}' mismatch", $value); |
306 | - if(!$defaultToCurrentTime && ($month === null || $day === null || $year === null)) |
|
306 | + if(!$defaultToCurrentTime && ($month===null || $day===null || $year===null)) |
|
307 | 307 | return null; |
308 | 308 | else |
309 | 309 | { |
310 | 310 | if(empty($year)) { |
311 | - $year = date('Y'); |
|
311 | + $year=date('Y'); |
|
312 | 312 | } |
313 | - $day = (int)$day <= 0 ? 1 : (int)$day; |
|
314 | - $month = (int)$month <= 0 ? 1 : (int)$month; |
|
315 | - $s = new TDateTimeStamp; |
|
313 | + $day=(int) $day <= 0 ? 1 : (int) $day; |
|
314 | + $month=(int) $month <= 0 ? 1 : (int) $month; |
|
315 | + $s=new TDateTimeStamp; |
|
316 | 316 | return $s->getTimeStamp(0, 0, 0, $month, $day, $year); |
317 | 317 | } |
318 | 318 | } |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | */ |
348 | 348 | private function charEqual($string, $pos, $char) |
349 | 349 | { |
350 | - return $this->charAt($string, $pos) == $char; |
|
350 | + return $this->charAt($string, $pos)==$char; |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -358,15 +358,15 @@ discard block |
||
358 | 358 | * @param int maximum integer length |
359 | 359 | * @return string integer portion of the string, null otherwise |
360 | 360 | */ |
361 | - private function getInteger($str,$i,$minlength,$maxlength) |
|
361 | + private function getInteger($str, $i, $minlength, $maxlength) |
|
362 | 362 | { |
363 | 363 | //match for digits backwards |
364 | - for ($x = $maxlength; $x >= $minlength; $x--) |
|
364 | + for($x=$maxlength; $x >= $minlength; $x--) |
|
365 | 365 | { |
366 | - $token= $this->substring($str, $i,$x); |
|
367 | - if ($this->length($token) < $minlength) |
|
366 | + $token=$this->substring($str, $i, $x); |
|
367 | + if($this->length($token) < $minlength) |
|
368 | 368 | return null; |
369 | - if (preg_match('/^\d+$/', $token)) |
|
369 | + if(preg_match('/^\d+$/', $token)) |
|
370 | 370 | return $token; |
371 | 371 | } |
372 | 372 | return null; |
@@ -55,6 +55,9 @@ |
||
55 | 55 | return self::$_output; |
56 | 56 | } |
57 | 57 | |
58 | + /** |
|
59 | + * @param integer $level |
|
60 | + */ |
|
58 | 61 | private static function dumpInternal($var,$level) |
59 | 62 | { |
60 | 63 | switch(gettype($var)) |
@@ -58,8 +58,7 @@ |
||
58 | 58 | if ($this->sourcepath === NULL) |
59 | 59 | { |
60 | 60 | $this->sourcepath = $sourcepath; |
61 | - } |
|
62 | - else |
|
61 | + } else |
|
63 | 62 | { |
64 | 63 | $this->sourcepath->append($sourcepath); |
65 | 64 | } |
@@ -40,27 +40,27 @@ discard block |
||
40 | 40 | * @param integer maximum depth that the dumper should go into the variable. Defaults to 10. |
41 | 41 | * @return string the string representation of the variable |
42 | 42 | */ |
43 | - public static function dump($var,$depth=10,$highlight=false) |
|
43 | + public static function dump($var, $depth=10, $highlight=false) |
|
44 | 44 | { |
45 | 45 | self::$_output=''; |
46 | 46 | self::$_objects=array(); |
47 | 47 | self::$_depth=$depth; |
48 | - self::dumpInternal($var,0); |
|
48 | + self::dumpInternal($var, 0); |
|
49 | 49 | if($highlight) |
50 | 50 | { |
51 | - $result=highlight_string("<?php\n".self::$_output,true); |
|
52 | - return preg_replace('/<\\?php<br \\/>/','',$result,1); |
|
51 | + $result=highlight_string("<?php\n".self::$_output, true); |
|
52 | + return preg_replace('/<\\?php<br \\/>/', '', $result, 1); |
|
53 | 53 | } |
54 | 54 | else |
55 | 55 | return self::$_output; |
56 | 56 | } |
57 | 57 | |
58 | - private static function dumpInternal($var,$level) |
|
58 | + private static function dumpInternal($var, $level) |
|
59 | 59 | { |
60 | 60 | switch(gettype($var)) |
61 | 61 | { |
62 | 62 | case 'boolean': |
63 | - self::$_output.=$var?'true':'false'; |
|
63 | + self::$_output.=$var ? 'true' : 'false'; |
|
64 | 64 | break; |
65 | 65 | case 'integer': |
66 | 66 | self::$_output.="$var"; |
@@ -81,41 +81,41 @@ discard block |
||
81 | 81 | self::$_output.='{unknown}'; |
82 | 82 | break; |
83 | 83 | case 'array': |
84 | - if(self::$_depth<=$level) |
|
84 | + if(self::$_depth <= $level) |
|
85 | 85 | self::$_output.='array(...)'; |
86 | 86 | else if(empty($var)) |
87 | 87 | self::$_output.='array()'; |
88 | 88 | else |
89 | 89 | { |
90 | 90 | $keys=array_keys($var); |
91 | - $spaces=str_repeat(' ',$level*4); |
|
91 | + $spaces=str_repeat(' ', $level * 4); |
|
92 | 92 | self::$_output.="array\n".$spaces.'('; |
93 | 93 | foreach($keys as $key) |
94 | 94 | { |
95 | 95 | self::$_output.="\n".$spaces." [$key] => "; |
96 | - self::$_output.=self::dumpInternal($var[$key],$level+1); |
|
96 | + self::$_output.=self::dumpInternal($var[$key], $level + 1); |
|
97 | 97 | } |
98 | 98 | self::$_output.="\n".$spaces.')'; |
99 | 99 | } |
100 | 100 | break; |
101 | 101 | case 'object': |
102 | - if(($id=array_search($var,self::$_objects,true))!==false) |
|
103 | - self::$_output.=get_class($var).'#'.($id+1).'(...)'; |
|
104 | - else if(self::$_depth<=$level) |
|
102 | + if(($id=array_search($var, self::$_objects, true))!==false) |
|
103 | + self::$_output.=get_class($var).'#'.($id + 1).'(...)'; |
|
104 | + else if(self::$_depth <= $level) |
|
105 | 105 | self::$_output.=get_class($var).'(...)'; |
106 | 106 | else |
107 | 107 | { |
108 | - $id=array_push(self::$_objects,$var); |
|
108 | + $id=array_push(self::$_objects, $var); |
|
109 | 109 | $className=get_class($var); |
110 | - $members=(array)$var; |
|
110 | + $members=(array) $var; |
|
111 | 111 | $keys=array_keys($members); |
112 | - $spaces=str_repeat(' ',$level*4); |
|
112 | + $spaces=str_repeat(' ', $level * 4); |
|
113 | 113 | self::$_output.="$className#$id\n".$spaces.'('; |
114 | 114 | foreach($keys as $key) |
115 | 115 | { |
116 | - $keyDisplay=strtr(trim($key),array("\0"=>':')); |
|
116 | + $keyDisplay=strtr(trim($key), array("\0"=>':')); |
|
117 | 117 | self::$_output.="\n".$spaces." [$keyDisplay] => "; |
118 | - self::$_output.=self::dumpInternal($members[$key],$level+1); |
|
118 | + self::$_output.=self::dumpInternal($members[$key], $level + 1); |
|
119 | 119 | } |
120 | 120 | self::$_output.="\n".$spaces.')'; |
121 | 121 | } |
@@ -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 | } |
@@ -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 | } |
@@ -59,228 +59,228 @@ |
||
59 | 59 | // -- Public Static Methods -------------------------------------------------- |
60 | 60 | |
61 | 61 | public static function minify($js) { |
62 | - $jsmin = new JSMin($js); |
|
63 | - return $jsmin->min(); |
|
62 | + $jsmin = new JSMin($js); |
|
63 | + return $jsmin->min(); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // -- Public Instance Methods ------------------------------------------------ |
67 | 67 | |
68 | 68 | public function __construct($input) { |
69 | - $this->input = str_replace("\r\n", "\n", $input); |
|
70 | - $this->inputLength = strlen($this->input); |
|
69 | + $this->input = str_replace("\r\n", "\n", $input); |
|
70 | + $this->inputLength = strlen($this->input); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // -- Protected Instance Methods --------------------------------------------- |
74 | 74 | |
75 | 75 | protected function action($d) { |
76 | - switch($d) { |
|
77 | - case 1: |
|
78 | - $this->output .= $this->a; |
|
79 | - |
|
80 | - case 2: |
|
81 | - $this->a = $this->b; |
|
82 | - |
|
83 | - if ($this->a === "'" || $this->a === '"') { |
|
84 | - for (;;) { |
|
85 | - $this->output .= $this->a; |
|
86 | - $this->a = $this->get(); |
|
87 | - |
|
88 | - if ($this->a === $this->b) { |
|
89 | - break; |
|
90 | - } |
|
91 | - |
|
92 | - if (ord($this->a) <= self::ORD_LF) { |
|
93 | - throw new JSMinException('Unterminated string literal.'); |
|
94 | - } |
|
95 | - |
|
96 | - if ($this->a === '\\') { |
|
97 | - $this->output .= $this->a; |
|
98 | - $this->a = $this->get(); |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - case 3: |
|
104 | - $this->b = $this->next(); |
|
105 | - |
|
106 | - if ($this->b === '/' && ( |
|
107 | - $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
108 | - $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
109 | - $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
110 | - |
|
111 | - $this->output .= $this->a . $this->b; |
|
112 | - |
|
113 | - for (;;) { |
|
114 | - $this->a = $this->get(); |
|
115 | - |
|
116 | - if ($this->a === '/') { |
|
117 | - break; |
|
118 | - } elseif ($this->a === '\\') { |
|
119 | - $this->output .= $this->a; |
|
120 | - $this->a = $this->get(); |
|
121 | - } elseif (ord($this->a) <= self::ORD_LF) { |
|
122 | - throw new JSMinException('Unterminated regular expression '. |
|
123 | - 'literal.'); |
|
124 | - } |
|
125 | - |
|
126 | - $this->output .= $this->a; |
|
127 | - } |
|
128 | - |
|
129 | - $this->b = $this->next(); |
|
130 | - } |
|
131 | - } |
|
76 | + switch($d) { |
|
77 | + case 1: |
|
78 | + $this->output .= $this->a; |
|
79 | + |
|
80 | + case 2: |
|
81 | + $this->a = $this->b; |
|
82 | + |
|
83 | + if ($this->a === "'" || $this->a === '"') { |
|
84 | + for (;;) { |
|
85 | + $this->output .= $this->a; |
|
86 | + $this->a = $this->get(); |
|
87 | + |
|
88 | + if ($this->a === $this->b) { |
|
89 | + break; |
|
90 | + } |
|
91 | + |
|
92 | + if (ord($this->a) <= self::ORD_LF) { |
|
93 | + throw new JSMinException('Unterminated string literal.'); |
|
94 | + } |
|
95 | + |
|
96 | + if ($this->a === '\\') { |
|
97 | + $this->output .= $this->a; |
|
98 | + $this->a = $this->get(); |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + case 3: |
|
104 | + $this->b = $this->next(); |
|
105 | + |
|
106 | + if ($this->b === '/' && ( |
|
107 | + $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
108 | + $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
109 | + $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
110 | + |
|
111 | + $this->output .= $this->a . $this->b; |
|
112 | + |
|
113 | + for (;;) { |
|
114 | + $this->a = $this->get(); |
|
115 | + |
|
116 | + if ($this->a === '/') { |
|
117 | + break; |
|
118 | + } elseif ($this->a === '\\') { |
|
119 | + $this->output .= $this->a; |
|
120 | + $this->a = $this->get(); |
|
121 | + } elseif (ord($this->a) <= self::ORD_LF) { |
|
122 | + throw new JSMinException('Unterminated regular expression '. |
|
123 | + 'literal.'); |
|
124 | + } |
|
125 | + |
|
126 | + $this->output .= $this->a; |
|
127 | + } |
|
128 | + |
|
129 | + $this->b = $this->next(); |
|
130 | + } |
|
131 | + } |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | protected function get() { |
135 | - $c = $this->lookAhead; |
|
136 | - $this->lookAhead = null; |
|
137 | - |
|
138 | - if ($c === null) { |
|
139 | - if ($this->inputIndex < $this->inputLength) { |
|
140 | - $c = $this->input[$this->inputIndex]; |
|
141 | - $this->inputIndex += 1; |
|
142 | - } else { |
|
143 | - $c = null; |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - if ($c === "\r") { |
|
148 | - return "\n"; |
|
149 | - } |
|
150 | - |
|
151 | - if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
152 | - return $c; |
|
153 | - } |
|
154 | - |
|
155 | - return ' '; |
|
135 | + $c = $this->lookAhead; |
|
136 | + $this->lookAhead = null; |
|
137 | + |
|
138 | + if ($c === null) { |
|
139 | + if ($this->inputIndex < $this->inputLength) { |
|
140 | + $c = $this->input[$this->inputIndex]; |
|
141 | + $this->inputIndex += 1; |
|
142 | + } else { |
|
143 | + $c = null; |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + if ($c === "\r") { |
|
148 | + return "\n"; |
|
149 | + } |
|
150 | + |
|
151 | + if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
152 | + return $c; |
|
153 | + } |
|
154 | + |
|
155 | + return ' '; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | protected function isAlphaNum($c) { |
159 | - return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
159 | + return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | protected function min() { |
163 | - $this->a = "\n"; |
|
164 | - $this->action(3); |
|
165 | - |
|
166 | - while ($this->a !== null) { |
|
167 | - switch ($this->a) { |
|
168 | - case ' ': |
|
169 | - if ($this->isAlphaNum($this->b)) { |
|
170 | - $this->action(1); |
|
171 | - } else { |
|
172 | - $this->action(2); |
|
173 | - } |
|
174 | - break; |
|
175 | - |
|
176 | - case "\n": |
|
177 | - switch ($this->b) { |
|
178 | - case '{': |
|
179 | - case '[': |
|
180 | - case '(': |
|
181 | - case '+': |
|
182 | - case '-': |
|
183 | - $this->action(1); |
|
184 | - break; |
|
185 | - |
|
186 | - case ' ': |
|
187 | - $this->action(3); |
|
188 | - break; |
|
189 | - |
|
190 | - default: |
|
191 | - if ($this->isAlphaNum($this->b)) { |
|
192 | - $this->action(1); |
|
193 | - } |
|
194 | - else { |
|
195 | - $this->action(2); |
|
196 | - } |
|
197 | - } |
|
198 | - break; |
|
199 | - |
|
200 | - default: |
|
201 | - switch ($this->b) { |
|
202 | - case ' ': |
|
203 | - if ($this->isAlphaNum($this->a)) { |
|
204 | - $this->action(1); |
|
205 | - break; |
|
206 | - } |
|
207 | - |
|
208 | - $this->action(3); |
|
209 | - break; |
|
210 | - |
|
211 | - case "\n": |
|
212 | - switch ($this->a) { |
|
213 | - case '}': |
|
214 | - case ']': |
|
215 | - case ')': |
|
216 | - case '+': |
|
217 | - case '-': |
|
218 | - case '"': |
|
219 | - case "'": |
|
220 | - $this->action(1); |
|
221 | - break; |
|
222 | - |
|
223 | - default: |
|
224 | - if ($this->isAlphaNum($this->a)) { |
|
225 | - $this->action(1); |
|
226 | - } |
|
227 | - else { |
|
228 | - $this->action(3); |
|
229 | - } |
|
230 | - } |
|
231 | - break; |
|
232 | - |
|
233 | - default: |
|
234 | - $this->action(1); |
|
235 | - break; |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - return $this->output; |
|
163 | + $this->a = "\n"; |
|
164 | + $this->action(3); |
|
165 | + |
|
166 | + while ($this->a !== null) { |
|
167 | + switch ($this->a) { |
|
168 | + case ' ': |
|
169 | + if ($this->isAlphaNum($this->b)) { |
|
170 | + $this->action(1); |
|
171 | + } else { |
|
172 | + $this->action(2); |
|
173 | + } |
|
174 | + break; |
|
175 | + |
|
176 | + case "\n": |
|
177 | + switch ($this->b) { |
|
178 | + case '{': |
|
179 | + case '[': |
|
180 | + case '(': |
|
181 | + case '+': |
|
182 | + case '-': |
|
183 | + $this->action(1); |
|
184 | + break; |
|
185 | + |
|
186 | + case ' ': |
|
187 | + $this->action(3); |
|
188 | + break; |
|
189 | + |
|
190 | + default: |
|
191 | + if ($this->isAlphaNum($this->b)) { |
|
192 | + $this->action(1); |
|
193 | + } |
|
194 | + else { |
|
195 | + $this->action(2); |
|
196 | + } |
|
197 | + } |
|
198 | + break; |
|
199 | + |
|
200 | + default: |
|
201 | + switch ($this->b) { |
|
202 | + case ' ': |
|
203 | + if ($this->isAlphaNum($this->a)) { |
|
204 | + $this->action(1); |
|
205 | + break; |
|
206 | + } |
|
207 | + |
|
208 | + $this->action(3); |
|
209 | + break; |
|
210 | + |
|
211 | + case "\n": |
|
212 | + switch ($this->a) { |
|
213 | + case '}': |
|
214 | + case ']': |
|
215 | + case ')': |
|
216 | + case '+': |
|
217 | + case '-': |
|
218 | + case '"': |
|
219 | + case "'": |
|
220 | + $this->action(1); |
|
221 | + break; |
|
222 | + |
|
223 | + default: |
|
224 | + if ($this->isAlphaNum($this->a)) { |
|
225 | + $this->action(1); |
|
226 | + } |
|
227 | + else { |
|
228 | + $this->action(3); |
|
229 | + } |
|
230 | + } |
|
231 | + break; |
|
232 | + |
|
233 | + default: |
|
234 | + $this->action(1); |
|
235 | + break; |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + return $this->output; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | protected function next() { |
244 | - $c = $this->get(); |
|
245 | - |
|
246 | - if ($c === '/') { |
|
247 | - switch($this->peek()) { |
|
248 | - case '/': |
|
249 | - for (;;) { |
|
250 | - $c = $this->get(); |
|
251 | - |
|
252 | - if (ord($c) <= self::ORD_LF) { |
|
253 | - return $c; |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - case '*': |
|
258 | - $this->get(); |
|
259 | - |
|
260 | - for (;;) { |
|
261 | - switch($this->get()) { |
|
262 | - case '*': |
|
263 | - if ($this->peek() === '/') { |
|
264 | - $this->get(); |
|
265 | - return ' '; |
|
266 | - } |
|
267 | - break; |
|
268 | - |
|
269 | - case null: |
|
270 | - throw new JSMinException('Unterminated comment.'); |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - default: |
|
275 | - return $c; |
|
276 | - } |
|
277 | - } |
|
278 | - |
|
279 | - return $c; |
|
244 | + $c = $this->get(); |
|
245 | + |
|
246 | + if ($c === '/') { |
|
247 | + switch($this->peek()) { |
|
248 | + case '/': |
|
249 | + for (;;) { |
|
250 | + $c = $this->get(); |
|
251 | + |
|
252 | + if (ord($c) <= self::ORD_LF) { |
|
253 | + return $c; |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + case '*': |
|
258 | + $this->get(); |
|
259 | + |
|
260 | + for (;;) { |
|
261 | + switch($this->get()) { |
|
262 | + case '*': |
|
263 | + if ($this->peek() === '/') { |
|
264 | + $this->get(); |
|
265 | + return ' '; |
|
266 | + } |
|
267 | + break; |
|
268 | + |
|
269 | + case null: |
|
270 | + throw new JSMinException('Unterminated comment.'); |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + default: |
|
275 | + return $c; |
|
276 | + } |
|
277 | + } |
|
278 | + |
|
279 | + return $c; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | protected function peek() { |
283 | - $this->lookAhead = $this->get(); |
|
284 | - return $this->lookAhead; |
|
283 | + $this->lookAhead = $this->get(); |
|
284 | + return $this->lookAhead; |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | \ No newline at end of file |
@@ -45,29 +45,29 @@ discard block |
||
45 | 45 | */ |
46 | 46 | |
47 | 47 | class JSMin { |
48 | - const ORD_LF = 10; |
|
49 | - const ORD_SPACE = 32; |
|
48 | + const ORD_LF=10; |
|
49 | + const ORD_SPACE=32; |
|
50 | 50 | |
51 | - protected $a = ''; |
|
52 | - protected $b = ''; |
|
53 | - protected $input = ''; |
|
54 | - protected $inputIndex = 0; |
|
55 | - protected $inputLength = 0; |
|
56 | - protected $lookAhead = null; |
|
57 | - protected $output = ''; |
|
51 | + protected $a=''; |
|
52 | + protected $b=''; |
|
53 | + protected $input=''; |
|
54 | + protected $inputIndex=0; |
|
55 | + protected $inputLength=0; |
|
56 | + protected $lookAhead=null; |
|
57 | + protected $output=''; |
|
58 | 58 | |
59 | 59 | // -- Public Static Methods -------------------------------------------------- |
60 | 60 | |
61 | 61 | public static function minify($js) { |
62 | - $jsmin = new JSMin($js); |
|
62 | + $jsmin=new JSMin($js); |
|
63 | 63 | return $jsmin->min(); |
64 | 64 | } |
65 | 65 | |
66 | 66 | // -- Public Instance Methods ------------------------------------------------ |
67 | 67 | |
68 | 68 | public function __construct($input) { |
69 | - $this->input = str_replace("\r\n", "\n", $input); |
|
70 | - $this->inputLength = strlen($this->input); |
|
69 | + $this->input=str_replace("\r\n", "\n", $input); |
|
70 | + $this->inputLength=strlen($this->input); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // -- Protected Instance Methods --------------------------------------------- |
@@ -75,80 +75,80 @@ discard block |
||
75 | 75 | protected function action($d) { |
76 | 76 | switch($d) { |
77 | 77 | case 1: |
78 | - $this->output .= $this->a; |
|
78 | + $this->output.=$this->a; |
|
79 | 79 | |
80 | 80 | case 2: |
81 | - $this->a = $this->b; |
|
81 | + $this->a=$this->b; |
|
82 | 82 | |
83 | - if ($this->a === "'" || $this->a === '"') { |
|
84 | - for (;;) { |
|
85 | - $this->output .= $this->a; |
|
86 | - $this->a = $this->get(); |
|
83 | + if($this->a==="'" || $this->a==='"') { |
|
84 | + for(;;) { |
|
85 | + $this->output.=$this->a; |
|
86 | + $this->a=$this->get(); |
|
87 | 87 | |
88 | - if ($this->a === $this->b) { |
|
88 | + if($this->a===$this->b) { |
|
89 | 89 | break; |
90 | 90 | } |
91 | 91 | |
92 | - if (ord($this->a) <= self::ORD_LF) { |
|
92 | + if(ord($this->a) <= self::ORD_LF) { |
|
93 | 93 | throw new JSMinException('Unterminated string literal.'); |
94 | 94 | } |
95 | 95 | |
96 | - if ($this->a === '\\') { |
|
97 | - $this->output .= $this->a; |
|
98 | - $this->a = $this->get(); |
|
96 | + if($this->a==='\\') { |
|
97 | + $this->output.=$this->a; |
|
98 | + $this->a=$this->get(); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | 103 | case 3: |
104 | - $this->b = $this->next(); |
|
104 | + $this->b=$this->next(); |
|
105 | 105 | |
106 | - if ($this->b === '/' && ( |
|
107 | - $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
108 | - $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
109 | - $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
106 | + if($this->b==='/' && ( |
|
107 | + $this->a==='(' || $this->a===',' || $this->a==='=' || |
|
108 | + $this->a===':' || $this->a==='[' || $this->a==='!' || |
|
109 | + $this->a==='&' || $this->a==='|' || $this->a==='?')) { |
|
110 | 110 | |
111 | - $this->output .= $this->a . $this->b; |
|
111 | + $this->output.=$this->a.$this->b; |
|
112 | 112 | |
113 | - for (;;) { |
|
114 | - $this->a = $this->get(); |
|
113 | + for(;;) { |
|
114 | + $this->a=$this->get(); |
|
115 | 115 | |
116 | - if ($this->a === '/') { |
|
116 | + if($this->a==='/') { |
|
117 | 117 | break; |
118 | - } elseif ($this->a === '\\') { |
|
119 | - $this->output .= $this->a; |
|
120 | - $this->a = $this->get(); |
|
121 | - } elseif (ord($this->a) <= self::ORD_LF) { |
|
118 | + } elseif($this->a==='\\') { |
|
119 | + $this->output.=$this->a; |
|
120 | + $this->a=$this->get(); |
|
121 | + } elseif(ord($this->a) <= self::ORD_LF) { |
|
122 | 122 | throw new JSMinException('Unterminated regular expression '. |
123 | 123 | 'literal.'); |
124 | 124 | } |
125 | 125 | |
126 | - $this->output .= $this->a; |
|
126 | + $this->output.=$this->a; |
|
127 | 127 | } |
128 | 128 | |
129 | - $this->b = $this->next(); |
|
129 | + $this->b=$this->next(); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
134 | 134 | protected function get() { |
135 | - $c = $this->lookAhead; |
|
136 | - $this->lookAhead = null; |
|
135 | + $c=$this->lookAhead; |
|
136 | + $this->lookAhead=null; |
|
137 | 137 | |
138 | - if ($c === null) { |
|
139 | - if ($this->inputIndex < $this->inputLength) { |
|
140 | - $c = $this->input[$this->inputIndex]; |
|
141 | - $this->inputIndex += 1; |
|
138 | + if($c===null) { |
|
139 | + if($this->inputIndex < $this->inputLength) { |
|
140 | + $c=$this->input[$this->inputIndex]; |
|
141 | + $this->inputIndex+=1; |
|
142 | 142 | } else { |
143 | - $c = null; |
|
143 | + $c=null; |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - if ($c === "\r") { |
|
147 | + if($c==="\r") { |
|
148 | 148 | return "\n"; |
149 | 149 | } |
150 | 150 | |
151 | - if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
151 | + if($c===null || $c==="\n" || ord($c) >= self::ORD_SPACE) { |
|
152 | 152 | return $c; |
153 | 153 | } |
154 | 154 | |
@@ -156,17 +156,17 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | protected function isAlphaNum($c) { |
159 | - return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
159 | + return ord($c) > 126 || $c==='\\' || preg_match('/^[\w\$]$/', $c)===1; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | protected function min() { |
163 | - $this->a = "\n"; |
|
163 | + $this->a="\n"; |
|
164 | 164 | $this->action(3); |
165 | 165 | |
166 | - while ($this->a !== null) { |
|
167 | - switch ($this->a) { |
|
166 | + while($this->a!==null) { |
|
167 | + switch($this->a) { |
|
168 | 168 | case ' ': |
169 | - if ($this->isAlphaNum($this->b)) { |
|
169 | + if($this->isAlphaNum($this->b)) { |
|
170 | 170 | $this->action(1); |
171 | 171 | } else { |
172 | 172 | $this->action(2); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | break; |
175 | 175 | |
176 | 176 | case "\n": |
177 | - switch ($this->b) { |
|
177 | + switch($this->b) { |
|
178 | 178 | case '{': |
179 | 179 | case '[': |
180 | 180 | case '(': |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | break; |
189 | 189 | |
190 | 190 | default: |
191 | - if ($this->isAlphaNum($this->b)) { |
|
191 | + if($this->isAlphaNum($this->b)) { |
|
192 | 192 | $this->action(1); |
193 | 193 | } |
194 | 194 | else { |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | break; |
199 | 199 | |
200 | 200 | default: |
201 | - switch ($this->b) { |
|
201 | + switch($this->b) { |
|
202 | 202 | case ' ': |
203 | - if ($this->isAlphaNum($this->a)) { |
|
203 | + if($this->isAlphaNum($this->a)) { |
|
204 | 204 | $this->action(1); |
205 | 205 | break; |
206 | 206 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | break; |
210 | 210 | |
211 | 211 | case "\n": |
212 | - switch ($this->a) { |
|
212 | + switch($this->a) { |
|
213 | 213 | case '}': |
214 | 214 | case ']': |
215 | 215 | case ')': |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | break; |
222 | 222 | |
223 | 223 | default: |
224 | - if ($this->isAlphaNum($this->a)) { |
|
224 | + if($this->isAlphaNum($this->a)) { |
|
225 | 225 | $this->action(1); |
226 | 226 | } |
227 | 227 | else { |
@@ -241,15 +241,15 @@ discard block |
||
241 | 241 | } |
242 | 242 | |
243 | 243 | protected function next() { |
244 | - $c = $this->get(); |
|
244 | + $c=$this->get(); |
|
245 | 245 | |
246 | - if ($c === '/') { |
|
246 | + if($c==='/') { |
|
247 | 247 | switch($this->peek()) { |
248 | 248 | case '/': |
249 | - for (;;) { |
|
250 | - $c = $this->get(); |
|
249 | + for(;;) { |
|
250 | + $c=$this->get(); |
|
251 | 251 | |
252 | - if (ord($c) <= self::ORD_LF) { |
|
252 | + if(ord($c) <= self::ORD_LF) { |
|
253 | 253 | return $c; |
254 | 254 | } |
255 | 255 | } |
@@ -257,10 +257,10 @@ discard block |
||
257 | 257 | case '*': |
258 | 258 | $this->get(); |
259 | 259 | |
260 | - for (;;) { |
|
260 | + for(;;) { |
|
261 | 261 | switch($this->get()) { |
262 | 262 | case '*': |
263 | - if ($this->peek() === '/') { |
|
263 | + if($this->peek()==='/') { |
|
264 | 264 | $this->get(); |
265 | 265 | return ' '; |
266 | 266 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | } |
281 | 281 | |
282 | 282 | protected function peek() { |
283 | - $this->lookAhead = $this->get(); |
|
283 | + $this->lookAhead=$this->get(); |
|
284 | 284 | return $this->lookAhead; |
285 | 285 | } |
286 | 286 | } |
287 | 287 | \ No newline at end of file |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | - * @return Marks a string as a javascript function. Once marke, the string is considered as a |
|
96 | + * @return TJavaScriptLiteral a string as a javascript function. Once marke, the string is considered as a |
|
97 | 97 | * raw javascript function that is not supposed to be encoded by {@link encode} |
98 | 98 | */ |
99 | 99 | public static function quoteJsLiteral($js) |
@@ -256,6 +256,7 @@ discard block |
||
256 | 256 | * @param string string to be decoded |
257 | 257 | * @param bool whether to convert returned objects to associative arrays |
258 | 258 | * @param int recursion depth |
259 | + * @param string $value |
|
259 | 260 | * @return mixed decoded variable |
260 | 261 | */ |
261 | 262 | public static function jsonDecode($value, $assoc = false, $depth = 512) |
@@ -298,7 +299,8 @@ discard block |
||
298 | 299 | * Minimize the size of a javascript script. |
299 | 300 | * This method is based on Douglas Crockford's JSMin. |
300 | 301 | * @param string code that you want to minimzie |
301 | - * @return minimized version of the code |
|
302 | + * @param string $code |
|
303 | + * @return string version of the code |
|
302 | 304 | */ |
303 | 305 | public static function JSMin($code) |
304 | 306 | { |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | $str=''; |
32 | 32 | foreach($files as $file) |
33 | - $str.= self::renderScriptFile($file); |
|
33 | + $str.=self::renderScriptFile($file); |
|
34 | 34 | return $str; |
35 | 35 | } |
36 | 36 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public static function renderScriptBlocks($scripts) |
53 | 53 | { |
54 | 54 | if(count($scripts)) |
55 | - return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n",$scripts)."\n/*]]>*/\n</script>\n"; |
|
55 | + return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n", $scripts)."\n/*]]>*/\n</script>\n"; |
|
56 | 56 | else |
57 | 57 | return ''; |
58 | 58 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | public static function renderScriptBlocksCallback($scripts) |
66 | 66 | { |
67 | 67 | if(count($scripts)) |
68 | - return implode("\n",$scripts)."\n"; |
|
68 | + return implode("\n", $scripts)."\n"; |
|
69 | 69 | else |
70 | 70 | return ''; |
71 | 71 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public static function quoteString($js) |
91 | 91 | { |
92 | - return self::jsonEncode($js,JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG); |
|
92 | + return self::jsonEncode($js, JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | * @param boolean wether to encode empty strings too. Default to false for BC. |
151 | 151 | * @return string the encoded string |
152 | 152 | */ |
153 | - public static function encode($value,$toMap=true,$encodeEmptyStrings=false) |
|
153 | + public static function encode($value, $toMap=true, $encodeEmptyStrings=false) |
|
154 | 154 | { |
155 | 155 | if(is_string($value)) |
156 | 156 | return self::quoteString($value); |
157 | 157 | else if(is_bool($value)) |
158 | - return $value?'true':'false'; |
|
158 | + return $value ? 'true' : 'false'; |
|
159 | 159 | else if(is_array($value)) |
160 | 160 | { |
161 | 161 | $results=''; |
162 | - if(($n=count($value))>0 && array_keys($value)!==range(0,$n-1)) |
|
162 | + if(($n=count($value)) > 0 && array_keys($value)!==range(0, $n - 1)) |
|
163 | 163 | { |
164 | 164 | foreach($value as $k=>$v) |
165 | 165 | { |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | { |
168 | 168 | if($results!=='') |
169 | 169 | $results.=','; |
170 | - $results.="'$k':".self::encode($v,$toMap,$encodeEmptyStrings); |
|
170 | + $results.="'$k':".self::encode($v, $toMap, $encodeEmptyStrings); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | return '{'.$results.'}'; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | if($results!=='') |
182 | 182 | $results.=','; |
183 | - $results.=self::encode($v,$toMap, $encodeEmptyStrings); |
|
183 | + $results.=self::encode($v, $toMap, $encodeEmptyStrings); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | return '['.$results.']'; |
@@ -208,10 +208,10 @@ discard block |
||
208 | 208 | } |
209 | 209 | } |
210 | 210 | else if(is_object($value)) |
211 | - if ($value instanceof TJavaScriptLiteral) |
|
211 | + if($value instanceof TJavaScriptLiteral) |
|
212 | 212 | return $value->toJavaScriptLiteral(); |
213 | 213 | else |
214 | - return self::encode(get_object_vars($value),$toMap); |
|
214 | + return self::encode(get_object_vars($value), $toMap); |
|
215 | 215 | else if($value===null) |
216 | 216 | return 'null'; |
217 | 217 | else |
@@ -223,14 +223,14 @@ discard block |
||
223 | 223 | * @param mixed variable to be encoded |
224 | 224 | * @return string encoded string |
225 | 225 | */ |
226 | - public static function jsonEncode($value, $options = 0) |
|
226 | + public static function jsonEncode($value, $options=0) |
|
227 | 227 | { |
228 | - if (($g=Prado::getApplication()->getGlobalization(false))!==null && |
|
228 | + if(($g=Prado::getApplication()->getGlobalization(false))!==null && |
|
229 | 229 | strtoupper($enc=$g->getCharset())!='UTF-8') { |
230 | 230 | self::convertToUtf8($value, $enc); |
231 | 231 | } |
232 | 232 | |
233 | - $s = @json_encode($value,$options); |
|
233 | + $s=@json_encode($value, $options); |
|
234 | 234 | self::checkJsonError(); |
235 | 235 | return $s; |
236 | 236 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | private static function convertToUtf8(&$value, $sourceEncoding) { |
244 | 244 | if(is_string($value)) |
245 | 245 | $value=iconv($sourceEncoding, 'UTF-8', $value); |
246 | - else if (is_array($value)) |
|
246 | + else if(is_array($value)) |
|
247 | 247 | { |
248 | 248 | foreach($value as &$element) |
249 | 249 | self::convertToUtf8($element, $sourceEncoding); |
@@ -258,37 +258,37 @@ discard block |
||
258 | 258 | * @param int recursion depth |
259 | 259 | * @return mixed decoded variable |
260 | 260 | */ |
261 | - public static function jsonDecode($value, $assoc = false, $depth = 512) |
|
261 | + public static function jsonDecode($value, $assoc=false, $depth=512) |
|
262 | 262 | { |
263 | - $s= @json_decode($value, $assoc, $depth); |
|
263 | + $s=@json_decode($value, $assoc, $depth); |
|
264 | 264 | self::checkJsonError(); |
265 | 265 | return $s; |
266 | 266 | } |
267 | 267 | |
268 | 268 | private static function checkJsonError() |
269 | 269 | { |
270 | - switch ($err = json_last_error()) |
|
270 | + switch($err=json_last_error()) |
|
271 | 271 | { |
272 | 272 | case JSON_ERROR_NONE: |
273 | 273 | return; |
274 | 274 | break; |
275 | 275 | case JSON_ERROR_DEPTH: |
276 | - $msg = 'Maximum stack depth exceeded'; |
|
276 | + $msg='Maximum stack depth exceeded'; |
|
277 | 277 | break; |
278 | 278 | case JSON_ERROR_STATE_MISMATCH: |
279 | - $msg = 'Underflow or the modes mismatch'; |
|
279 | + $msg='Underflow or the modes mismatch'; |
|
280 | 280 | break; |
281 | 281 | case JSON_ERROR_CTRL_CHAR: |
282 | - $msg = 'Unexpected control character found'; |
|
282 | + $msg='Unexpected control character found'; |
|
283 | 283 | break; |
284 | 284 | case JSON_ERROR_SYNTAX: |
285 | - $msg = 'Syntax error, malformed JSON'; |
|
285 | + $msg='Syntax error, malformed JSON'; |
|
286 | 286 | break; |
287 | 287 | case JSON_ERROR_UTF8: |
288 | - $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
288 | + $msg='Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
289 | 289 | break; |
290 | 290 | default: |
291 | - $msg = 'Unknown error'; |
|
291 | + $msg='Unknown error'; |
|
292 | 292 | break; |
293 | 293 | } |
294 | 294 | throw new Exception("JSON error ($err): $msg"); |
@@ -171,8 +171,7 @@ discard block |
||
171 | 171 | } |
172 | 172 | } |
173 | 173 | return '{'.$results.'}'; |
174 | - } |
|
175 | - else |
|
174 | + } else |
|
176 | 175 | { |
177 | 176 | foreach($value as $v) |
178 | 177 | { |
@@ -185,8 +184,7 @@ discard block |
||
185 | 184 | } |
186 | 185 | return '['.$results.']'; |
187 | 186 | } |
188 | - } |
|
189 | - else if(is_integer($value)) |
|
187 | + } else if(is_integer($value)) |
|
190 | 188 | return "$value"; |
191 | 189 | else if(is_float($value)) |
192 | 190 | { |
@@ -206,8 +204,7 @@ discard block |
||
206 | 204 | return str_replace($locale['decimal_point'], '.', "$value"); |
207 | 205 | break; |
208 | 206 | } |
209 | - } |
|
210 | - else if(is_object($value)) |
|
207 | + } else if(is_object($value)) |
|
211 | 208 | if ($value instanceof TJavaScriptLiteral) |
212 | 209 | return $value->toJavaScriptLiteral(); |
213 | 210 | else |
@@ -140,6 +140,7 @@ |
||
140 | 140 | /** |
141 | 141 | * Renders content provided by TJsonResponse::getJsonContent() as |
142 | 142 | * javascript in JSON format. |
143 | + * @param TJsonResponse $service |
|
143 | 144 | */ |
144 | 145 | protected function createJsonResponse($service,$properties,$config) |
145 | 146 | { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | if(is_array($config)) |
78 | 78 | { |
79 | 79 | foreach($config['json'] as $id => $json) |
80 | - $this->_services[$id] = $json; |
|
80 | + $this->_services[$id]=$json; |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | else |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | $service=Prado::createComponent($serviceConfig['class']); |
110 | 110 | if($service instanceof TJsonResponse) |
111 | 111 | { |
112 | - $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array(); |
|
113 | - $this->createJsonResponse($service,$properties,$serviceConfig); |
|
112 | + $properties=isset($serviceConfig['properties']) ? $serviceConfig['properties'] : array(); |
|
113 | + $this->createJsonResponse($service, $properties, $serviceConfig); |
|
114 | 114 | } |
115 | 115 | else |
116 | - throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
116 | + throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
117 | 117 | } |
118 | 118 | else |
119 | - throw new TConfigurationException('jsonservice_class_required',$id); |
|
119 | + throw new TConfigurationException('jsonservice_class_required', $id); |
|
120 | 120 | } |
121 | 121 | else |
122 | 122 | { |
@@ -125,33 +125,33 @@ discard block |
||
125 | 125 | { |
126 | 126 | $service=Prado::createComponent($class); |
127 | 127 | if($service instanceof TJsonResponse) |
128 | - $this->createJsonResponse($service,$properties,$serviceConfig); |
|
128 | + $this->createJsonResponse($service, $properties, $serviceConfig); |
|
129 | 129 | else |
130 | - throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
130 | + throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
131 | 131 | } |
132 | 132 | else |
133 | - throw new TConfigurationException('jsonservice_class_required',$id); |
|
133 | + throw new TConfigurationException('jsonservice_class_required', $id); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | else |
137 | - throw new THttpException(404,'jsonservice_provider_unknown',$id); |
|
137 | + throw new THttpException(404, 'jsonservice_provider_unknown', $id); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Renders content provided by TJsonResponse::getJsonContent() as |
142 | 142 | * javascript in JSON format. |
143 | 143 | */ |
144 | - protected function createJsonResponse($service,$properties,$config) |
|
144 | + protected function createJsonResponse($service, $properties, $config) |
|
145 | 145 | { |
146 | 146 | // init service properties |
147 | 147 | foreach($properties as $name=>$value) |
148 | - $service->setSubproperty($name,$value); |
|
148 | + $service->setSubproperty($name, $value); |
|
149 | 149 | $service->init($config); |
150 | 150 | |
151 | 151 | //send content if not null |
152 | 152 | if(($content=$service->getJsonContent())!==null) |
153 | 153 | { |
154 | - $response = $this->getResponse(); |
|
154 | + $response=$this->getResponse(); |
|
155 | 155 | $response->setContentType('application/json'); |
156 | 156 | $response->setCharset('UTF-8'); |
157 | 157 | //send content |
@@ -79,8 +79,7 @@ discard block |
||
79 | 79 | foreach($config['json'] as $id => $json) |
80 | 80 | $this->_services[$id] = $json; |
81 | 81 | } |
82 | - } |
|
83 | - else |
|
82 | + } else |
|
84 | 83 | { |
85 | 84 | foreach($config->getElementsByTagName('json') as $json) |
86 | 85 | { |
@@ -111,14 +110,11 @@ discard block |
||
111 | 110 | { |
112 | 111 | $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array(); |
113 | 112 | $this->createJsonResponse($service,$properties,$serviceConfig); |
114 | - } |
|
115 | - else |
|
113 | + } else |
|
116 | 114 | throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
117 | - } |
|
118 | - else |
|
115 | + } else |
|
119 | 116 | throw new TConfigurationException('jsonservice_class_required',$id); |
120 | - } |
|
121 | - else |
|
117 | + } else |
|
122 | 118 | { |
123 | 119 | $properties=$serviceConfig->getAttributes(); |
124 | 120 | if(($class=$properties->remove('class'))!==null) |
@@ -128,12 +124,10 @@ discard block |
||
128 | 124 | $this->createJsonResponse($service,$properties,$serviceConfig); |
129 | 125 | else |
130 | 126 | throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
131 | - } |
|
132 | - else |
|
127 | + } else |
|
133 | 128 | throw new TConfigurationException('jsonservice_class_required',$id); |
134 | 129 | } |
135 | - } |
|
136 | - else |
|
130 | + } else |
|
137 | 131 | throw new THttpException(404,'jsonservice_provider_unknown',$id); |
138 | 132 | } |
139 | 133 |
@@ -31,6 +31,7 @@ |
||
31 | 31 | /** |
32 | 32 | * Constructor. Attach a response to be adapted. |
33 | 33 | * @param THttpResponse the response object the adapter is to attach to. |
34 | + * @param THttpResponse $response |
|
34 | 35 | */ |
35 | 36 | public function __construct($response) |
36 | 37 | { |
@@ -71,7 +71,7 @@ |
||
71 | 71 | */ |
72 | 72 | public function createNewHtmlWriter($type, $writer) |
73 | 73 | { |
74 | - return $this->_response->createNewHtmlWriter($type,$writer); |
|
74 | + return $this->_response->createNewHtmlWriter($type, $writer); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 |