@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @since 3.1.7 |
87 | 87 | */ |
88 | - const DEFAULT_TRANSACTION_CLASS = 'System.Data.TDbTransaction'; |
|
88 | + const DEFAULT_TRANSACTION_CLASS='System.Data.TDbTransaction'; |
|
89 | 89 | |
90 | 90 | private $_dsn=''; |
91 | 91 | private $_username=''; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | /** |
100 | 100 | * @var TDbMetaData |
101 | 101 | */ |
102 | - private $_dbMeta = null; |
|
102 | + private $_dbMeta=null; |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @var string |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @param string Charset used for DB Connection (MySql & pgsql only). If not set, will use the default charset of your database server |
121 | 121 | * @see http://www.php.net/manual/en/function.PDO-construct.php |
122 | 122 | */ |
123 | - public function __construct($dsn='',$username='',$password='', $charset='') |
|
123 | + public function __construct($dsn='', $username='', $password='', $charset='') |
|
124 | 124 | { |
125 | 125 | $this->_dsn=$dsn; |
126 | 126 | $this->_username=$username; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | public function __sleep() |
135 | 135 | { |
136 | 136 | // $this->close(); - DO NOT CLOSE the current connection as serializing doesn't neccessarily mean we don't this connection anymore in the current session |
137 | - return array_diff(parent::__sleep(),array("\0TDbConnection\0_pdo","\0TDbConnection\0_active")); |
|
137 | + return array_diff(parent::__sleep(), array("\0TDbConnection\0_pdo", "\0TDbConnection\0_active")); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | { |
182 | 182 | try |
183 | 183 | { |
184 | - $this->_pdo=new PDO($this->getConnectionString(),$this->getUsername(), |
|
185 | - $this->getPassword(),$this->_attributes); |
|
184 | + $this->_pdo=new PDO($this->getConnectionString(), $this->getUsername(), |
|
185 | + $this->getPassword(), $this->_attributes); |
|
186 | 186 | // This attribute is only useful for PDO::MySql driver. |
187 | 187 | // Ignore the warning if a driver doesn't understand this. |
188 | 188 | @$this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | } |
193 | 193 | catch(PDOException $e) |
194 | 194 | { |
195 | - throw new TDbException('dbconnection_open_failed',$e->getMessage()); |
|
195 | + throw new TDbException('dbconnection_open_failed', $e->getMessage()); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
@@ -214,16 +214,16 @@ discard block |
||
214 | 214 | */ |
215 | 215 | protected function setConnectionCharset() |
216 | 216 | { |
217 | - if ($this->_charset === '' || $this->_active === false) |
|
217 | + if($this->_charset==='' || $this->_active===false) |
|
218 | 218 | return; |
219 | - switch ($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) |
|
219 | + switch($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) |
|
220 | 220 | { |
221 | 221 | case 'mysql': |
222 | 222 | case 'sqlite': |
223 | - $stmt = $this->_pdo->prepare('SET NAMES ?'); |
|
223 | + $stmt=$this->_pdo->prepare('SET NAMES ?'); |
|
224 | 224 | break; |
225 | 225 | case 'pgsql': |
226 | - $stmt = $this->_pdo->prepare('SET client_encoding TO ?'); |
|
226 | + $stmt=$this->_pdo->prepare('SET client_encoding TO ?'); |
|
227 | 227 | break; |
228 | 228 | default: |
229 | 229 | throw new TDbException('dbconnection_unsupported_driver_charset', $driver); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | /** |
284 | 284 | * @return string the charset used for database connection. Defaults to emtpy string. |
285 | 285 | */ |
286 | - public function getCharset () |
|
286 | + public function getCharset() |
|
287 | 287 | { |
288 | 288 | return $this->_charset; |
289 | 289 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | /** |
292 | 292 | * @param string the charset used for database connection |
293 | 293 | */ |
294 | - public function setCharset ($value) |
|
294 | + public function setCharset($value) |
|
295 | 295 | { |
296 | 296 | $this->_charset=$value; |
297 | 297 | $this->setConnectionCharset(); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | public function createCommand($sql) |
315 | 315 | { |
316 | 316 | if($this->getActive()) |
317 | - return new TDbCommand($this,$sql); |
|
317 | + return new TDbCommand($this, $sql); |
|
318 | 318 | else |
319 | 319 | throw new TDbException('dbconnection_connection_inactive'); |
320 | 320 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | */ |
365 | 365 | public function setTransactionClass($value) |
366 | 366 | { |
367 | - $this->_transactionClass = (string)$value; |
|
367 | + $this->_transactionClass=(string) $value; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | if($this->_dbMeta===null) |
434 | 434 | { |
435 | 435 | Prado::using('System.Data.Common.TDbMetaData'); |
436 | - $this->_dbMeta = TDbMetaData::getInstance($this); |
|
436 | + $this->_dbMeta=TDbMetaData::getInstance($this); |
|
437 | 437 | } |
438 | 438 | return $this->_dbMeta; |
439 | 439 | } |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | */ |
460 | 460 | public function setColumnCase($value) |
461 | 461 | { |
462 | - switch(TPropertyValue::ensureEnum($value,'TDbColumnCaseMode')) |
|
462 | + switch(TPropertyValue::ensureEnum($value, 'TDbColumnCaseMode')) |
|
463 | 463 | { |
464 | 464 | case TDbColumnCaseMode::Preserved: |
465 | 465 | $value=PDO::CASE_NATURAL; |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | $value=PDO::CASE_UPPER; |
472 | 472 | break; |
473 | 473 | } |
474 | - $this->setAttribute(PDO::ATTR_CASE,$value); |
|
474 | + $this->setAttribute(PDO::ATTR_CASE, $value); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | */ |
496 | 496 | public function setNullConversion($value) |
497 | 497 | { |
498 | - switch(TPropertyValue::ensureEnum($value,'TDbNullConversionMode')) |
|
498 | + switch(TPropertyValue::ensureEnum($value, 'TDbNullConversionMode')) |
|
499 | 499 | { |
500 | 500 | case TDbNullConversionMode::Preserved: |
501 | 501 | $value=PDO::NULL_NATURAL; |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | $value=PDO::NULL_TO_STRING; |
508 | 508 | break; |
509 | 509 | } |
510 | - $this->setAttribute(PDO::ATTR_ORACLE_NULLS,$value); |
|
510 | + $this->setAttribute(PDO::ATTR_ORACLE_NULLS, $value); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | */ |
526 | 526 | public function setAutoCommit($value) |
527 | 527 | { |
528 | - $this->setAttribute(PDO::ATTR_AUTOCOMMIT,TPropertyValue::ensureBoolean($value)); |
|
528 | + $this->setAttribute(PDO::ATTR_AUTOCOMMIT, TPropertyValue::ensureBoolean($value)); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | */ |
544 | 544 | public function setPersistent($value) |
545 | 545 | { |
546 | - return $this->setAttribute(PDO::ATTR_PERSISTENT,TPropertyValue::ensureBoolean($value)); |
|
546 | + return $this->setAttribute(PDO::ATTR_PERSISTENT, TPropertyValue::ensureBoolean($value)); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -623,10 +623,10 @@ discard block |
||
623 | 623 | * @param mixed the attribute value |
624 | 624 | * @see http://www.php.net/manual/en/function.PDO-setAttribute.php |
625 | 625 | */ |
626 | - public function setAttribute($name,$value) |
|
626 | + public function setAttribute($name, $value) |
|
627 | 627 | { |
628 | 628 | if($this->_pdo instanceof PDO) |
629 | - $this->_pdo->setAttribute($name,$value); |
|
629 | + $this->_pdo->setAttribute($name, $value); |
|
630 | 630 | else |
631 | 631 | $this->_attributes[$name]=$value; |
632 | 632 | } |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | public function __construct($condition=null, $parameters=array()) |
49 | 49 | { |
50 | 50 | if(!is_array($parameters) && func_num_args() > 1) |
51 | - $parameters = array_slice(func_get_args(),1); |
|
51 | + $parameters=array_slice(func_get_args(), 1); |
|
52 | 52 | $this->_parameters=new TAttributeCollection; |
53 | 53 | $this->_parameters->setCaseSensitive(true); |
54 | - $this->_parameters->copyFrom((array)$parameters); |
|
54 | + $this->_parameters->copyFrom((array) $parameters); |
|
55 | 55 | $this->_ordersBy=new TAttributeCollection; |
56 | 56 | $this->_ordersBy->setCaseSensitive(true); |
57 | 57 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function setSelect($value) |
111 | 111 | { |
112 | - $this->_select = $value; |
|
112 | + $this->_select=$value; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | { |
129 | 129 | if(empty($value)) { |
130 | 130 | // reset the condition |
131 | - $this->_condition = null; |
|
131 | + $this->_condition=null; |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | if(preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) { |
142 | 142 | // condition contains ORDER BY |
143 | - $value = str_replace($matches[0], '', $value); |
|
143 | + $value=str_replace($matches[0], '', $value); |
|
144 | 144 | if(strlen($matches[1]) > 0) { |
145 | 145 | $this->setOrdersBy($matches[1]); |
146 | 146 | } else if(strlen($matches[2]) > 0) { |
@@ -150,23 +150,23 @@ discard block |
||
150 | 150 | |
151 | 151 | if(preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) { |
152 | 152 | // condition contains limit |
153 | - $value = str_replace($matches[0], '', $value); // remove limit from query |
|
153 | + $value=str_replace($matches[0], '', $value); // remove limit from query |
|
154 | 154 | if(strpos($matches[1], ',')) { // both offset and limit given |
155 | - list($offset, $limit) = explode(',', $matches[1]); |
|
156 | - $this->_limit = (int)$limit; |
|
157 | - $this->_offset = (int)$offset; |
|
155 | + list($offset, $limit)=explode(',', $matches[1]); |
|
156 | + $this->_limit=(int) $limit; |
|
157 | + $this->_offset=(int) $offset; |
|
158 | 158 | } else { // only limit given |
159 | - $this->_limit = (int)$matches[1]; |
|
159 | + $this->_limit=(int) $matches[1]; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | if(preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) { |
164 | 164 | // condition contains offset |
165 | - $value = str_replace($matches[0], '', $value); // remove offset from query |
|
166 | - $this->_offset = (int)$matches[1]; // set offset in criteria |
|
165 | + $value=str_replace($matches[0], '', $value); // remove offset from query |
|
166 | + $this->_offset=(int) $matches[1]; // set offset in criteria |
|
167 | 167 | } |
168 | 168 | |
169 | - $this->_condition = trim($value); |
|
169 | + $this->_condition=trim($value); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -213,12 +213,12 @@ discard block |
||
213 | 213 | $this->_ordersBy->copyFrom($value); |
214 | 214 | else |
215 | 215 | { |
216 | - $value=trim(preg_replace('/\s+/',' ',(string)$value)); |
|
216 | + $value=trim(preg_replace('/\s+/', ' ', (string) $value)); |
|
217 | 217 | $orderBys=array(); |
218 | - foreach(explode(',',$value) as $orderBy) |
|
218 | + foreach(explode(',', $value) as $orderBy) |
|
219 | 219 | { |
220 | - $vs=explode(' ',trim($orderBy)); |
|
221 | - $orderBys[$vs[0]]=isset($vs[1])?$vs[1]:'asc'; |
|
220 | + $vs=explode(' ', trim($orderBy)); |
|
221 | + $orderBys[$vs[0]]=isset($vs[1]) ? $vs[1] : 'asc'; |
|
222 | 222 | } |
223 | 223 | $this->_ordersBy->copyFrom($orderBys); |
224 | 224 | } |
@@ -261,23 +261,23 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function __toString() |
263 | 263 | { |
264 | - $str = ''; |
|
265 | - if(strlen((string)$this->getCondition()) > 0) |
|
266 | - $str .= '"'.(string)$this->getCondition().'"'; |
|
267 | - $params = array(); |
|
264 | + $str=''; |
|
265 | + if(strlen((string) $this->getCondition()) > 0) |
|
266 | + $str.='"'.(string) $this->getCondition().'"'; |
|
267 | + $params=array(); |
|
268 | 268 | foreach($this->getParameters() as $k=>$v) |
269 | - $params[] = "{$k} => ${v}"; |
|
269 | + $params[]="{$k} => ${v}"; |
|
270 | 270 | if(count($params) > 0) |
271 | - $str .= ', "'.implode(', ',$params).'"'; |
|
272 | - $orders = array(); |
|
271 | + $str.=', "'.implode(', ', $params).'"'; |
|
272 | + $orders=array(); |
|
273 | 273 | foreach($this->getOrdersBy() as $k=>$v) |
274 | - $orders[] = "{$k} => ${v}"; |
|
274 | + $orders[]="{$k} => ${v}"; |
|
275 | 275 | if(count($orders) > 0) |
276 | - $str .= ', "'.implode(', ',$orders).'"'; |
|
277 | - if($this->_limit !==null) |
|
278 | - $str .= ', '.$this->_limit; |
|
279 | - if($this->_offset !== null) |
|
280 | - $str .= ', '.$this->_offset; |
|
276 | + $str.=', "'.implode(', ', $orders).'"'; |
|
277 | + if($this->_limit!==null) |
|
278 | + $str.=', '.$this->_limit; |
|
279 | + if($this->_offset!==null) |
|
280 | + $str.=', '.$this->_offset; |
|
281 | 281 | return $str; |
282 | 282 | } |
283 | 283 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param string|TDbTableInfo table or view name or table information. |
88 | 88 | * @param TDbConnection database connection. |
89 | 89 | */ |
90 | - public function __construct($table,$connection) |
|
90 | + public function __construct($table, $connection) |
|
91 | 91 | { |
92 | 92 | $this->_connection=$connection; |
93 | 93 | if(is_string($table)) |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function setTableInfo($tableInfo) |
105 | 105 | { |
106 | - $builder = $tableInfo->createCommandBuilder($this->getDbConnection()); |
|
106 | + $builder=$tableInfo->createCommandBuilder($this->getDbConnection()); |
|
107 | 107 | $this->initCommandBuilder($builder); |
108 | 108 | } |
109 | 109 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | protected function setTableName($tableName) |
115 | 115 | { |
116 | 116 | Prado::using('System.Data.Common.TDbMetaData'); |
117 | - $meta = TDbMetaData::getInstance($this->getDbConnection()); |
|
117 | + $meta=TDbMetaData::getInstance($this->getDbConnection()); |
|
118 | 118 | $this->initCommandBuilder($meta->createCommandBuilder($tableName)); |
119 | 119 | } |
120 | 120 | |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function initCommandBuilder($builder) |
135 | 135 | { |
136 | - $this->_command = new TDataGatewayCommand($builder); |
|
137 | - $this->_command->OnCreateCommand[] = array($this, 'onCreateCommand'); |
|
138 | - $this->_command->OnExecuteCommand[] = array($this, 'onExecuteCommand'); |
|
136 | + $this->_command=new TDataGatewayCommand($builder); |
|
137 | + $this->_command->OnCreateCommand[]=array($this, 'onCreateCommand'); |
|
138 | + $this->_command->OnExecuteCommand[]=array($this, 'onExecuteCommand'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function findBySql($sql, $parameters=array()) |
191 | 191 | { |
192 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
193 | - $criteria = $this->getCriteria($sql,$parameters, $args); |
|
192 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
193 | + $criteria=$this->getCriteria($sql, $parameters, $args); |
|
194 | 194 | return $this->getCommand()->findBySql($criteria); |
195 | 195 | } |
196 | 196 | |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | */ |
203 | 203 | public function findAllBySql($sql, $parameters=array()) |
204 | 204 | { |
205 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
206 | - $criteria = $this->getCriteria($sql,$parameters, $args); |
|
205 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
206 | + $criteria=$this->getCriteria($sql, $parameters, $args); |
|
207 | 207 | return $this->getCommand()->findAllBySql($criteria); |
208 | 208 | } |
209 | 209 | |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function find($criteria, $parameters=array()) |
228 | 228 | { |
229 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
230 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
229 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
230 | + $criteria=$this->getCriteria($criteria, $parameters, $args); |
|
231 | 231 | return $this->getCommand()->find($criteria); |
232 | 232 | } |
233 | 233 | |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function findAll($criteria=null, $parameters=array()) |
241 | 241 | { |
242 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
242 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
243 | 243 | if($criteria!==null) |
244 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
244 | + $criteria=$this->getCriteria($criteria, $parameters, $args); |
|
245 | 245 | return $this->getCommand()->findAll($criteria); |
246 | 246 | } |
247 | 247 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | public function findByPk($keys) |
261 | 261 | { |
262 | 262 | if(func_num_args() > 1) |
263 | - $keys = func_get_args(); |
|
263 | + $keys=func_get_args(); |
|
264 | 264 | return $this->getCommand()->findByPk($keys); |
265 | 265 | } |
266 | 266 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | public function findAllByPks($keys) |
285 | 285 | { |
286 | 286 | if(func_num_args() > 1) |
287 | - $keys = func_get_args(); |
|
287 | + $keys=func_get_args(); |
|
288 | 288 | return $this->getCommand()->findAllByPk($keys); |
289 | 289 | } |
290 | 290 | |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | */ |
302 | 302 | public function deleteAll($criteria, $parameters=array()) |
303 | 303 | { |
304 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
305 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
304 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
305 | + $criteria=$this->getCriteria($criteria, $parameters, $args); |
|
306 | 306 | return $this->getCommand()->delete($criteria); |
307 | 307 | } |
308 | 308 | |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | public function deleteByPk($keys) |
333 | 333 | { |
334 | 334 | if(func_num_args() > 1) |
335 | - $keys = func_get_args(); |
|
335 | + $keys=func_get_args(); |
|
336 | 336 | return $this->getCommand()->deleteByPk($keys); |
337 | 337 | } |
338 | 338 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | public function deleteAllByPks($keys) |
343 | 343 | { |
344 | 344 | if(func_num_args() > 1) |
345 | - $keys = func_get_args(); |
|
345 | + $keys=func_get_args(); |
|
346 | 346 | return $this->deleteByPk($keys); |
347 | 347 | } |
348 | 348 | |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | * @param mixed parameter values. |
353 | 353 | * @return int number of records. |
354 | 354 | */ |
355 | - public function count($criteria=null,$parameters=array()) |
|
355 | + public function count($criteria=null, $parameters=array()) |
|
356 | 356 | { |
357 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
357 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
358 | 358 | if($criteria!==null) |
359 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
359 | + $criteria=$this->getCriteria($criteria, $parameters, $args); |
|
360 | 360 | return $this->getCommand()->count($criteria); |
361 | 361 | } |
362 | 362 | |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | */ |
377 | 377 | public function update($data, $criteria, $parameters=array()) |
378 | 378 | { |
379 | - $args = func_num_args() > 2 ? array_slice(func_get_args(),2) : null; |
|
380 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
379 | + $args=func_num_args() > 2 ? array_slice(func_get_args(), 2) : null; |
|
380 | + $criteria=$this->getCriteria($criteria, $parameters, $args); |
|
381 | 381 | return $this->getCommand()->update($data, $criteria); |
382 | 382 | } |
383 | 383 | |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | { |
415 | 415 | if(is_string($criteria)) |
416 | 416 | { |
417 | - $useArgs = !is_array($parameters) && is_array($args); |
|
418 | - return new TSqlCriteria($criteria,$useArgs ? $args : $parameters); |
|
417 | + $useArgs=!is_array($parameters) && is_array($args); |
|
418 | + return new TSqlCriteria($criteria, $useArgs ? $args : $parameters); |
|
419 | 419 | } |
420 | 420 | else if($criteria instanceof TSqlCriteria) |
421 | 421 | return $criteria; |
@@ -452,21 +452,21 @@ discard block |
||
452 | 452 | * @return mixed single record if method name starts with "findBy", 0 or more records |
453 | 453 | * if method name starts with "findAllBy" |
454 | 454 | */ |
455 | - public function __call($method,$args) |
|
455 | + public function __call($method, $args) |
|
456 | 456 | { |
457 | - $delete =false; |
|
458 | - if($findOne = substr(strtolower($method),0,6)==='findby') |
|
459 | - $condition = $method[6]==='_' ? substr($method,7) : substr($method,6); |
|
460 | - else if(substr(strtolower($method),0,9)==='findallby') |
|
461 | - $condition = $method[9]==='_' ? substr($method,10) : substr($method,9); |
|
462 | - else if($delete = substr(strtolower($method),0,8)==='deleteby') |
|
463 | - $condition = $method[8]==='_' ? substr($method,9) : substr($method,8); |
|
464 | - else if($delete = substr(strtolower($method),0,11)==='deleteallby') |
|
465 | - $condition = $method[11]==='_' ? substr($method,12) : substr($method,11); |
|
457 | + $delete=false; |
|
458 | + if($findOne=substr(strtolower($method), 0, 6)==='findby') |
|
459 | + $condition=$method[6]==='_' ? substr($method, 7) : substr($method, 6); |
|
460 | + else if(substr(strtolower($method), 0, 9)==='findallby') |
|
461 | + $condition=$method[9]==='_' ? substr($method, 10) : substr($method, 9); |
|
462 | + else if($delete=substr(strtolower($method), 0, 8)==='deleteby') |
|
463 | + $condition=$method[8]==='_' ? substr($method, 9) : substr($method, 8); |
|
464 | + else if($delete=substr(strtolower($method), 0, 11)==='deleteallby') |
|
465 | + $condition=$method[11]==='_' ? substr($method, 12) : substr($method, 11); |
|
466 | 466 | else |
467 | 467 | return null; |
468 | 468 | |
469 | - $criteria = $this->getCommand()->createCriteriaFromString($method, $condition, $args); |
|
469 | + $criteria=$this->getCommand()->createCriteriaFromString($method, $condition, $args); |
|
470 | 470 | if($delete) |
471 | 471 | return $this->deleteAll($criteria); |
472 | 472 | else |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function __construct($builder) |
45 | 45 | { |
46 | - $this->_builder = $builder; |
|
46 | + $this->_builder=$builder; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function delete($criteria) |
79 | 79 | { |
80 | - $where = $criteria->getCondition(); |
|
81 | - $parameters = $criteria->getParameters()->toArray(); |
|
82 | - $command = $this->getBuilder()->createDeleteCommand($where, $parameters); |
|
83 | - $this->onCreateCommand($command,$criteria); |
|
80 | + $where=$criteria->getCondition(); |
|
81 | + $parameters=$criteria->getParameters()->toArray(); |
|
82 | + $command=$this->getBuilder()->createDeleteCommand($where, $parameters); |
|
83 | + $this->onCreateCommand($command, $criteria); |
|
84 | 84 | $command->prepare(); |
85 | 85 | return $command->execute(); |
86 | 86 | } |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function update($data, $criteria) |
95 | 95 | { |
96 | - $where = $criteria->getCondition(); |
|
97 | - $parameters = $criteria->getParameters()->toArray(); |
|
98 | - $command = $this->getBuilder()->createUpdateCommand($data,$where, $parameters); |
|
99 | - $this->onCreateCommand($command,$criteria); |
|
96 | + $where=$criteria->getCondition(); |
|
97 | + $parameters=$criteria->getParameters()->toArray(); |
|
98 | + $command=$this->getBuilder()->createUpdateCommand($data, $where, $parameters); |
|
99 | + $this->onCreateCommand($command, $criteria); |
|
100 | 100 | $command->prepare(); |
101 | 101 | return $this->onExecuteCommand($command, $command->execute()); |
102 | 102 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function updateByPk($data, $keys) |
110 | 110 | { |
111 | - list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); |
|
111 | + list($where, $parameters)=$this->getPrimaryKeyCondition((array) $keys); |
|
112 | 112 | return $this->update($data, new TSqlCriteria($where, $parameters)); |
113 | 113 | } |
114 | 114 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function find($criteria) |
121 | 121 | { |
122 | - $command = $this->getFindCommand($criteria); |
|
122 | + $command=$this->getFindCommand($criteria); |
|
123 | 123 | return $this->onExecuteCommand($command, $command->queryRow()); |
124 | 124 | } |
125 | 125 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function findAll($criteria) |
132 | 132 | { |
133 | - $command = $this->getFindCommand($criteria); |
|
133 | + $command=$this->getFindCommand($criteria); |
|
134 | 134 | return $this->onExecuteCommand($command, $command->query()); |
135 | 135 | } |
136 | 136 | |
@@ -143,13 +143,13 @@ discard block |
||
143 | 143 | { |
144 | 144 | if($criteria===null) |
145 | 145 | return $this->getBuilder()->createFindCommand(); |
146 | - $where = $criteria->getCondition(); |
|
147 | - $parameters = $criteria->getParameters()->toArray(); |
|
148 | - $ordering = $criteria->getOrdersBy(); |
|
149 | - $limit = $criteria->getLimit(); |
|
150 | - $offset = $criteria->getOffset(); |
|
151 | - $select = $criteria->getSelect(); |
|
152 | - $command = $this->getBuilder()->createFindCommand($where,$parameters,$ordering,$limit,$offset,$select); |
|
146 | + $where=$criteria->getCondition(); |
|
147 | + $parameters=$criteria->getParameters()->toArray(); |
|
148 | + $ordering=$criteria->getOrdersBy(); |
|
149 | + $limit=$criteria->getLimit(); |
|
150 | + $offset=$criteria->getOffset(); |
|
151 | + $select=$criteria->getSelect(); |
|
152 | + $command=$this->getBuilder()->createFindCommand($where, $parameters, $ordering, $limit, $offset, $select); |
|
153 | 153 | $this->onCreateCommand($command, $criteria); |
154 | 154 | return $command; |
155 | 155 | } |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | { |
163 | 163 | if($keys===null) |
164 | 164 | return null; |
165 | - list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); |
|
166 | - $command = $this->getBuilder()->createFindCommand($where, $parameters); |
|
167 | - $this->onCreateCommand($command, new TSqlCriteria($where,$parameters)); |
|
165 | + list($where, $parameters)=$this->getPrimaryKeyCondition((array) $keys); |
|
166 | + $command=$this->getBuilder()->createFindCommand($where, $parameters); |
|
167 | + $this->onCreateCommand($command, new TSqlCriteria($where, $parameters)); |
|
168 | 168 | return $this->onExecuteCommand($command, $command->queryRow()); |
169 | 169 | } |
170 | 170 | |
@@ -174,22 +174,22 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function findAllByPk($keys) |
176 | 176 | { |
177 | - $where = $this->getCompositeKeyCondition((array)$keys); |
|
178 | - $command = $this->getBuilder()->createFindCommand($where); |
|
179 | - $this->onCreateCommand($command, new TSqlCriteria($where,$keys)); |
|
180 | - return $this->onExecuteCommand($command,$command->query()); |
|
177 | + $where=$this->getCompositeKeyCondition((array) $keys); |
|
178 | + $command=$this->getBuilder()->createFindCommand($where); |
|
179 | + $this->onCreateCommand($command, new TSqlCriteria($where, $keys)); |
|
180 | + return $this->onExecuteCommand($command, $command->query()); |
|
181 | 181 | } |
182 | 182 | |
183 | - public function findAllByIndex($criteria,$fields,$values) |
|
183 | + public function findAllByIndex($criteria, $fields, $values) |
|
184 | 184 | { |
185 | - $index = $this->getIndexKeyCondition($this->getTableInfo(),$fields,$values); |
|
186 | - if(strlen($where = $criteria->getCondition())>0) |
|
185 | + $index=$this->getIndexKeyCondition($this->getTableInfo(), $fields, $values); |
|
186 | + if(strlen($where=$criteria->getCondition()) > 0) |
|
187 | 187 | $criteria->setCondition("({$index}) AND ({$where})"); |
188 | 188 | else |
189 | 189 | $criteria->setCondition($index); |
190 | - $command = $this->getFindCommand($criteria); |
|
190 | + $command=$this->getFindCommand($criteria); |
|
191 | 191 | $this->onCreateCommand($command, $criteria); |
192 | - return $this->onExecuteCommand($command,$command->query()); |
|
192 | + return $this->onExecuteCommand($command, $command->query()); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -200,22 +200,22 @@ discard block |
||
200 | 200 | { |
201 | 201 | if(count($keys)==0) |
202 | 202 | return 0; |
203 | - $where = $this->getCompositeKeyCondition((array)$keys); |
|
204 | - $command = $this->getBuilder()->createDeleteCommand($where); |
|
205 | - $this->onCreateCommand($command, new TSqlCriteria($where,$keys)); |
|
203 | + $where=$this->getCompositeKeyCondition((array) $keys); |
|
204 | + $command=$this->getBuilder()->createDeleteCommand($where); |
|
205 | + $this->onCreateCommand($command, new TSqlCriteria($where, $keys)); |
|
206 | 206 | $command->prepare(); |
207 | - return $this->onExecuteCommand($command,$command->execute()); |
|
207 | + return $this->onExecuteCommand($command, $command->execute()); |
|
208 | 208 | } |
209 | 209 | |
210 | - public function getIndexKeyCondition($table,$fields,$values) |
|
210 | + public function getIndexKeyCondition($table, $fields, $values) |
|
211 | 211 | { |
212 | - if (!count($values)) |
|
212 | + if(!count($values)) |
|
213 | 213 | return 'FALSE'; |
214 | - $columns = array(); |
|
215 | - $tableName = $table->getTableFullName(); |
|
214 | + $columns=array(); |
|
215 | + $tableName=$table->getTableFullName(); |
|
216 | 216 | foreach($fields as $field) |
217 | - $columns[] = $tableName.'.'.$table->getColumn($field)->getColumnName(); |
|
218 | - return '('.implode(', ',$columns).') IN '.$this->quoteTuple($values); |
|
217 | + $columns[]=$tableName.'.'.$table->getColumn($field)->getColumnName(); |
|
218 | + return '('.implode(', ', $columns).') IN '.$this->quoteTuple($values); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -225,26 +225,26 @@ discard block |
||
225 | 225 | */ |
226 | 226 | protected function getCompositeKeyCondition($values) |
227 | 227 | { |
228 | - $primary = $this->getTableInfo()->getPrimaryKeys(); |
|
229 | - $count = count($primary); |
|
228 | + $primary=$this->getTableInfo()->getPrimaryKeys(); |
|
229 | + $count=count($primary); |
|
230 | 230 | if($count===0) |
231 | 231 | { |
232 | 232 | throw new TDbException('dbtablegateway_no_primary_key_found', |
233 | 233 | $this->getTableInfo()->getTableFullName()); |
234 | 234 | } |
235 | - if(!is_array($values) || count($values) === 0) |
|
235 | + if(!is_array($values) || count($values)===0) |
|
236 | 236 | { |
237 | 237 | throw new TDbException('dbtablegateway_missing_pk_values', |
238 | 238 | $this->getTableInfo()->getTableFullName()); |
239 | 239 | } |
240 | - if($count>1 && (!isset($values[0]) || !is_array($values[0]))) |
|
241 | - $values = array($values); |
|
242 | - if($count > 1 && count($values[0]) !== $count) |
|
240 | + if($count > 1 && (!isset($values[0]) || !is_array($values[0]))) |
|
241 | + $values=array($values); |
|
242 | + if($count > 1 && count($values[0])!==$count) |
|
243 | 243 | { |
244 | 244 | throw new TDbException('dbtablegateway_pk_value_count_mismatch', |
245 | 245 | $this->getTableInfo()->getTableFullName()); |
246 | 246 | } |
247 | - return $this->getIndexKeyCondition($this->getTableInfo(),$primary, $values); |
|
247 | + return $this->getIndexKeyCondition($this->getTableInfo(), $primary, $values); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -254,10 +254,10 @@ discard block |
||
254 | 254 | */ |
255 | 255 | protected function quoteTuple($array) |
256 | 256 | { |
257 | - $conn = $this->getDbConnection(); |
|
258 | - $data = array(); |
|
257 | + $conn=$this->getDbConnection(); |
|
258 | + $data=array(); |
|
259 | 259 | foreach($array as $k=>$v) |
260 | - $data[] = is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v); |
|
260 | + $data[]=is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v); |
|
261 | 261 | return '('.implode(', ', $data).')'; |
262 | 262 | } |
263 | 263 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | protected function getPrimaryKeyCondition($values) |
270 | 270 | { |
271 | - $primary = $this->getTableInfo()->getPrimaryKeys(); |
|
271 | + $primary=$this->getTableInfo()->getPrimaryKeys(); |
|
272 | 272 | if(count($primary)===0) |
273 | 273 | { |
274 | 274 | throw new TDbException('dbtablegateway_no_primary_key_found', |
@@ -276,12 +276,12 @@ discard block |
||
276 | 276 | } |
277 | 277 | $criteria=array(); |
278 | 278 | $bindings=array(); |
279 | - $i = 0; |
|
279 | + $i=0; |
|
280 | 280 | foreach($primary as $key) |
281 | 281 | { |
282 | - $column = $this->getTableInfo()->getColumn($key)->getColumnName(); |
|
283 | - $criteria[] = $column.' = :'.$key; |
|
284 | - $bindings[$key] = isset($values[$key])?$values[$key]:$values[$i++]; |
|
282 | + $column=$this->getTableInfo()->getColumn($key)->getColumnName(); |
|
283 | + $criteria[]=$column.' = :'.$key; |
|
284 | + $bindings[$key]=isset($values[$key]) ? $values[$key] : $values[$i++]; |
|
285 | 285 | } |
286 | 286 | return array(implode(' AND ', $criteria), $bindings); |
287 | 287 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | */ |
294 | 294 | public function findBySql($criteria) |
295 | 295 | { |
296 | - $command = $this->getSqlCommand($criteria); |
|
296 | + $command=$this->getSqlCommand($criteria); |
|
297 | 297 | return $this->onExecuteCommand($command, $command->queryRow()); |
298 | 298 | } |
299 | 299 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function findAllBySql($criteria) |
306 | 306 | { |
307 | - $command = $this->getSqlCommand($criteria); |
|
307 | + $command=$this->getSqlCommand($criteria); |
|
308 | 308 | return $this->onExecuteCommand($command, $command->query()); |
309 | 309 | } |
310 | 310 | |
@@ -315,15 +315,15 @@ discard block |
||
315 | 315 | */ |
316 | 316 | protected function getSqlCommand($criteria) |
317 | 317 | { |
318 | - $sql = $criteria->getCondition(); |
|
319 | - $ordering = $criteria->getOrdersBy(); |
|
320 | - $limit = $criteria->getLimit(); |
|
321 | - $offset = $criteria->getOffset(); |
|
318 | + $sql=$criteria->getCondition(); |
|
319 | + $ordering=$criteria->getOrdersBy(); |
|
320 | + $limit=$criteria->getLimit(); |
|
321 | + $offset=$criteria->getOffset(); |
|
322 | 322 | if(count($ordering) > 0) |
323 | - $sql = $this->getBuilder()->applyOrdering($sql, $ordering); |
|
324 | - if($limit>=0 || $offset>=0) |
|
325 | - $sql = $this->getBuilder()->applyLimitOffset($sql, $limit, $offset); |
|
326 | - $command = $this->getBuilder()->createCommand($sql); |
|
323 | + $sql=$this->getBuilder()->applyOrdering($sql, $ordering); |
|
324 | + if($limit >= 0 || $offset >= 0) |
|
325 | + $sql=$this->getBuilder()->applyLimitOffset($sql, $limit, $offset); |
|
326 | + $command=$this->getBuilder()->createCommand($sql); |
|
327 | 327 | $this->getBuilder()->bindArrayValues($command, $criteria->getParameters()->toArray()); |
328 | 328 | $this->onCreateCommand($command, $criteria); |
329 | 329 | return $command; |
@@ -336,15 +336,15 @@ discard block |
||
336 | 336 | public function count($criteria) |
337 | 337 | { |
338 | 338 | if($criteria===null) |
339 | - return (int)$this->getBuilder()->createCountCommand()->queryScalar(); |
|
340 | - $where = $criteria->getCondition(); |
|
341 | - $parameters = $criteria->getParameters()->toArray(); |
|
342 | - $ordering = $criteria->getOrdersBy(); |
|
343 | - $limit = $criteria->getLimit(); |
|
344 | - $offset = $criteria->getOffset(); |
|
345 | - $command = $this->getBuilder()->createCountCommand($where,$parameters,$ordering,$limit,$offset); |
|
339 | + return (int) $this->getBuilder()->createCountCommand()->queryScalar(); |
|
340 | + $where=$criteria->getCondition(); |
|
341 | + $parameters=$criteria->getParameters()->toArray(); |
|
342 | + $ordering=$criteria->getOrdersBy(); |
|
343 | + $limit=$criteria->getLimit(); |
|
344 | + $offset=$criteria->getOffset(); |
|
345 | + $command=$this->getBuilder()->createCountCommand($where, $parameters, $ordering, $limit, $offset); |
|
346 | 346 | $this->onCreateCommand($command, $criteria); |
347 | - return $this->onExecuteCommand($command, (int)$command->queryScalar()); |
|
347 | + return $this->onExecuteCommand($command, (int) $command->queryScalar()); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -357,12 +357,12 @@ discard block |
||
357 | 357 | public function insert($data) |
358 | 358 | { |
359 | 359 | $command=$this->getBuilder()->createInsertCommand($data); |
360 | - $this->onCreateCommand($command, new TSqlCriteria(null,$data)); |
|
360 | + $this->onCreateCommand($command, new TSqlCriteria(null, $data)); |
|
361 | 361 | $command->prepare(); |
362 | 362 | if($this->onExecuteCommand($command, $command->execute()) > 0) |
363 | 363 | { |
364 | - $value = $this->getLastInsertId(); |
|
365 | - return $value !== null ? $value : true; |
|
364 | + $value=$this->getLastInsertId(); |
|
365 | + return $value!==null ? $value : true; |
|
366 | 366 | } |
367 | 367 | return false; |
368 | 368 | } |
@@ -385,14 +385,14 @@ discard block |
||
385 | 385 | */ |
386 | 386 | public function createCriteriaFromString($method, $condition, $args) |
387 | 387 | { |
388 | - $fields = $this->extractMatchingConditions($method, $condition); |
|
389 | - $args=count($args) === 1 && is_array($args[0]) ? $args[0] : $args; |
|
390 | - if(count($fields)>count($args)) |
|
388 | + $fields=$this->extractMatchingConditions($method, $condition); |
|
389 | + $args=count($args)===1 && is_array($args[0]) ? $args[0] : $args; |
|
390 | + if(count($fields) > count($args)) |
|
391 | 391 | { |
392 | 392 | throw new TDbException('dbtablegateway_mismatch_args_exception', |
393 | - $method,count($fields),count($args)); |
|
393 | + $method, count($fields), count($args)); |
|
394 | 394 | } |
395 | - return new TSqlCriteria(implode(' ',$fields), $args); |
|
395 | + return new TSqlCriteria(implode(' ', $fields), $args); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -404,25 +404,25 @@ discard block |
||
404 | 404 | */ |
405 | 405 | protected function extractMatchingConditions($method, $condition) |
406 | 406 | { |
407 | - $table = $this->getTableInfo(); |
|
408 | - $columns = $table->getLowerCaseColumnNames(); |
|
409 | - $regexp = '/('.implode('|', array_keys($columns)).')(and|_and_|or|_or_)?/i'; |
|
410 | - $matches = array(); |
|
411 | - if(!preg_match_all($regexp, strtolower($condition), $matches,PREG_SET_ORDER)) |
|
407 | + $table=$this->getTableInfo(); |
|
408 | + $columns=$table->getLowerCaseColumnNames(); |
|
409 | + $regexp='/('.implode('|', array_keys($columns)).')(and|_and_|or|_or_)?/i'; |
|
410 | + $matches=array(); |
|
411 | + if(!preg_match_all($regexp, strtolower($condition), $matches, PREG_SET_ORDER)) |
|
412 | 412 | { |
413 | 413 | throw new TDbException('dbtablegateway_mismatch_column_name', |
414 | 414 | $method, implode(', ', $columns), $table->getTableFullName()); |
415 | 415 | } |
416 | 416 | |
417 | - $fields = array(); |
|
417 | + $fields=array(); |
|
418 | 418 | foreach($matches as $match) |
419 | 419 | { |
420 | - $key = $columns[$match[1]]; |
|
421 | - $column = $table->getColumn($key)->getColumnName(); |
|
422 | - $sql = $column . ' = ? '; |
|
420 | + $key=$columns[$match[1]]; |
|
421 | + $column=$table->getColumn($key)->getColumnName(); |
|
422 | + $sql=$column.' = ? '; |
|
423 | 423 | if(count($match) > 2) |
424 | - $sql .= strtoupper(str_replace('_', '', $match[2])); |
|
425 | - $fields[] = $sql; |
|
424 | + $sql.=strtoupper(str_replace('_', '', $match[2])); |
|
425 | + $fields[]=$sql; |
|
426 | 426 | } |
427 | 427 | return $fields; |
428 | 428 | } |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public function onCreateCommand($command, $criteria) |
439 | 439 | { |
440 | - $this->raiseEvent('OnCreateCommand', $this, new TDataGatewayEventParameter($command,$criteria)); |
|
440 | + $this->raiseEvent('OnCreateCommand', $this, new TDataGatewayEventParameter($command, $criteria)); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | */ |
452 | 452 | public function onExecuteCommand($command, $result) |
453 | 453 | { |
454 | - $parameter = new TDataGatewayResultEventParameter($command, $result); |
|
454 | + $parameter=new TDataGatewayResultEventParameter($command, $result); |
|
455 | 455 | $this->raiseEvent('OnExecuteCommand', $this, $parameter); |
456 | 456 | return $parameter->getResult(); |
457 | 457 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | private $_command; |
472 | 472 | private $_criteria; |
473 | 473 | |
474 | - public function __construct($command,$criteria) |
|
474 | + public function __construct($command, $criteria) |
|
475 | 475 | { |
476 | 476 | $this->_command=$command; |
477 | 477 | $this->_criteria=$criteria; |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | private $_command; |
512 | 512 | private $_result; |
513 | 513 | |
514 | - public function __construct($command,$result) |
|
514 | + public function __construct($command, $result) |
|
515 | 515 | { |
516 | 516 | $this->_command=$command; |
517 | 517 | $this->_result=$result; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | /** |
134 | 134 | * Configuration file type, application.xml and config.xml |
135 | 135 | */ |
136 | - const CONFIG_TYPE_XML = 'xml'; |
|
136 | + const CONFIG_TYPE_XML='xml'; |
|
137 | 137 | /** |
138 | 138 | * Application configuration file name |
139 | 139 | */ |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * Configuration file type, application.php and config.php |
147 | 147 | */ |
148 | - const CONFIG_TYPE_PHP = 'php'; |
|
148 | + const CONFIG_TYPE_PHP='php'; |
|
149 | 149 | /** |
150 | 150 | * Runtime directory name |
151 | 151 | */ |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | /** |
299 | 299 | * @var string Customizable page service ID |
300 | 300 | */ |
301 | - private $_pageServiceID = self::PAGE_SERVICE_ID; |
|
301 | + private $_pageServiceID=self::PAGE_SERVICE_ID; |
|
302 | 302 | |
303 | 303 | /** |
304 | 304 | * Constructor. |
@@ -318,7 +318,7 @@ 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); |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | // generates unique ID by hashing the runtime path |
332 | 332 | $this->_uniqueID=md5($this->_runtimePath); |
333 | 333 | $this->_parameters=new TMap; |
334 | - $this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null)); |
|
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 | /** |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | { |
351 | 351 | // determine configuration path and file |
352 | 352 | if(empty($basePath) || ($basePath=realpath($basePath))===false) |
353 | - throw new TConfigurationException('application_basepath_invalid',$basePath); |
|
353 | + throw new TConfigurationException('application_basepath_invalid', $basePath); |
|
354 | 354 | if(is_dir($basePath) && is_file($basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName())) |
355 | 355 | $configFile=$basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName(); |
356 | 356 | else if(is_file($basePath)) |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | if(!is_dir($runtimePath)) |
372 | 372 | { |
373 | 373 | if(@mkdir($runtimePath)===false) |
374 | - throw new TConfigurationException('application_runtimepath_failed',$runtimePath); |
|
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 | |
@@ -397,14 +397,14 @@ discard block |
||
397 | 397 | $n=count(self::$_steps); |
398 | 398 | $this->_step=0; |
399 | 399 | $this->_requestCompleted=false; |
400 | - while($this->_step<$n) |
|
400 | + while($this->_step < $n) |
|
401 | 401 | { |
402 | 402 | if($this->_mode===self::STATE_OFF) |
403 | - throw new THttpException(503,'application_unavailable'); |
|
403 | + throw new THttpException(503, 'application_unavailable'); |
|
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 | } |
@@ -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,7 +457,7 @@ 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 | 462 | $this->_stateChanged=true; |
463 | 463 | if($value===$defaultValue) |
@@ -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 | /** |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | */ |
606 | 606 | public function setConfigurationType($value) |
607 | 607 | { |
608 | - $this->_configType = $value; |
|
608 | + $this->_configType=$value; |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | /** |
@@ -618,10 +618,10 @@ discard block |
||
618 | 618 | switch($this->_configType) |
619 | 619 | { |
620 | 620 | case TApplication::CONFIG_TYPE_PHP: |
621 | - $this->_configFileExt = TApplication::CONFIG_FILE_EXT_PHP; |
|
621 | + $this->_configFileExt=TApplication::CONFIG_FILE_EXT_PHP; |
|
622 | 622 | break; |
623 | 623 | default: |
624 | - $this->_configFileExt = TApplication::CONFIG_FILE_EXT_XML; |
|
624 | + $this->_configFileExt=TApplication::CONFIG_FILE_EXT_XML; |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 | return $this->_configFileExt; |
@@ -633,15 +633,15 @@ discard block |
||
633 | 633 | public function getConfigurationFileName() |
634 | 634 | { |
635 | 635 | static $fileName; |
636 | - if($fileName == null) |
|
636 | + if($fileName==null) |
|
637 | 637 | { |
638 | 638 | switch($this->_configType) |
639 | 639 | { |
640 | 640 | case TApplication::CONFIG_TYPE_PHP: |
641 | - $fileName = TApplication::CONFIG_FILE_PHP; |
|
641 | + $fileName=TApplication::CONFIG_FILE_PHP; |
|
642 | 642 | break; |
643 | 643 | default: |
644 | - $fileName = TApplication::CONFIG_FILE_XML; |
|
644 | + $fileName=TApplication::CONFIG_FILE_XML; |
|
645 | 645 | } |
646 | 646 | } |
647 | 647 | return $fileName; |
@@ -689,10 +689,10 @@ 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 | 694 | if(isset($this->_modules[$id])) |
695 | - throw new TConfigurationException('application_moduleid_duplicated',$id); |
|
695 | + throw new TConfigurationException('application_moduleid_duplicated', $id); |
|
696 | 696 | else |
697 | 697 | $this->_modules[$id]=$module; |
698 | 698 | } |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | // force loading of a lazy module |
709 | 709 | if($this->_modules[$id]===null) |
710 | 710 | { |
711 | - $module = $this->internalLoadModule($id, true); |
|
711 | + $module=$this->internalLoadModule($id, true); |
|
712 | 712 | $module[0]->init($module[1]); |
713 | 713 | } |
714 | 714 | |
@@ -957,37 +957,37 @@ discard block |
||
957 | 957 | list($moduleClass, $initProperties, $configElement)=$this->_lazyModules[$id]; |
958 | 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'); |
|
965 | + Prado::trace("Loading module $id ({$moduleClass})", 'System.TApplication'); |
|
966 | 966 | $module=Prado::createComponent($moduleClass); |
967 | 967 | foreach($initProperties as $name=>$value) |
968 | 968 | { |
969 | 969 | if($name==='lazy') continue; |
970 | - $module->setSubProperty($name,$value); |
|
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 | 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 | 985 | if($config->getIsEmpty()) |
986 | 986 | return; |
987 | 987 | |
988 | 988 | // set path aliases and using namespaces |
989 | 989 | foreach($config->getAliases() as $alias=>$path) |
990 | - Prado::setPathOfAlias($alias,$path); |
|
990 | + Prado::setPathOfAlias($alias, $path); |
|
991 | 991 | foreach($config->getUsings() as $using) |
992 | 992 | Prado::using($using); |
993 | 993 | |
@@ -995,11 +995,11 @@ discard block |
||
995 | 995 | if(!$withinService) |
996 | 996 | { |
997 | 997 | foreach($config->getProperties() as $name=>$value) |
998 | - $this->setSubProperty($name,$value); |
|
998 | + $this->setSubProperty($name, $value); |
|
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | if(empty($this->_services)) |
1002 | - $this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null)); |
|
1002 | + $this->_services=array($this->getPageServiceID()=>array('TPageService', array(), null)); |
|
1003 | 1003 | |
1004 | 1004 | // load parameters |
1005 | 1005 | foreach($config->getParameters() as $id=>$parameter) |
@@ -1008,11 +1008,11 @@ discard block |
||
1008 | 1008 | { |
1009 | 1009 | $component=Prado::createComponent($parameter[0]); |
1010 | 1010 | foreach($parameter[1] as $name=>$value) |
1011 | - $component->setSubProperty($name,$value); |
|
1012 | - $this->_parameters->add($id,$component); |
|
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 |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | if(!is_string($id)) |
1023 | 1023 | $id='_module'.count($this->_lazyModules); |
1024 | 1024 | $this->_lazyModules[$id]=$moduleConfig; |
1025 | - if($module = $this->internalLoadModule($id)) |
|
1025 | + if($module=$this->internalLoadModule($id)) |
|
1026 | 1026 | $modules[]=$module; |
1027 | 1027 | } |
1028 | 1028 | foreach($modules as $module) |
@@ -1039,12 +1039,12 @@ discard block |
||
1039 | 1039 | $condition=$this->evaluateExpression($condition); |
1040 | 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); |
|
1042 | + if(($path=Prado::getPathOfNamespace($filePath, $this->getConfigurationFileExt()))===null || !is_file($path)) |
|
1043 | + throw new TConfigurationException('application_includefile_invalid', $filePath); |
|
1044 | 1044 | $cn=$this->getApplicationConfigurationClass(); |
1045 | 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,21 +1060,21 @@ 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 | 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 | 1069 | $config=new TApplicationConfiguration; |
1070 | 1070 | $config->loadFromFile($this->_configFile); |
1071 | 1071 | if($this->_cacheFile!==null) |
1072 | - file_put_contents($this->_cacheFile,serialize($config),LOCK_EX); |
|
1072 | + file_put_contents($this->_cacheFile, serialize($config), LOCK_EX); |
|
1073 | 1073 | } |
1074 | 1074 | else |
1075 | 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 | 1080 | if(($serviceID=$this->getRequest()->resolveRequest(array_keys($this->_services)))===null) |
@@ -1093,32 +1093,32 @@ discard block |
||
1093 | 1093 | { |
1094 | 1094 | if(isset($this->_services[$serviceID])) |
1095 | 1095 | { |
1096 | - list($serviceClass,$initProperties,$configElement)=$this->_services[$serviceID]; |
|
1096 | + list($serviceClass, $initProperties, $configElement)=$this->_services[$serviceID]; |
|
1097 | 1097 | $service=Prado::createComponent($serviceClass); |
1098 | 1098 | if(!($service instanceof IService)) |
1099 | - throw new THttpException(500,'application_service_invalid',$serviceClass); |
|
1099 | + throw new THttpException(500, 'application_service_invalid', $serviceClass); |
|
1100 | 1100 | if(!$service->getEnabled()) |
1101 | - throw new THttpException(500,'application_service_unavailable',$serviceClass); |
|
1101 | + throw new THttpException(500, 'application_service_unavailable', $serviceClass); |
|
1102 | 1102 | $service->setID($serviceID); |
1103 | 1103 | $this->setService($service); |
1104 | 1104 | |
1105 | 1105 | foreach($initProperties as $name=>$value) |
1106 | - $service->setSubProperty($name,$value); |
|
1106 | + $service->setSubProperty($name, $value); |
|
1107 | 1107 | |
1108 | 1108 | if($configElement!==null) |
1109 | 1109 | { |
1110 | 1110 | $config=new TApplicationConfiguration; |
1111 | 1111 | if($this->getConfigurationType()==self::CONFIG_TYPE_PHP) |
1112 | - $config->loadFromPhp($configElement,$this->getBasePath()); |
|
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 | /** |
@@ -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,14 +1244,14 @@ 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 | /** |
1251 | 1251 | * Flushes output to client side. |
1252 | 1252 | * @param boolean whether to continue buffering after flush if buffering was active |
1253 | 1253 | */ |
1254 | - public function flushOutput($continueBuffering = true) |
|
1254 | + public function flushOutput($continueBuffering=true) |
|
1255 | 1255 | { |
1256 | 1256 | $this->getResponse()->flush($continueBuffering); |
1257 | 1257 | } |
@@ -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 | |
@@ -1344,14 +1344,14 @@ discard block |
||
1344 | 1344 | { |
1345 | 1345 | if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
1346 | 1346 | { |
1347 | - $fcontent = include $fname; |
|
1348 | - $this->loadFromPhp($fcontent,dirname($fname)); |
|
1347 | + $fcontent=include $fname; |
|
1348 | + $this->loadFromPhp($fcontent, dirname($fname)); |
|
1349 | 1349 | } |
1350 | 1350 | else |
1351 | 1351 | { |
1352 | 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 | |
@@ -1377,23 +1377,23 @@ discard block |
||
1377 | 1377 | { |
1378 | 1378 | $this->_properties[$name]=$value; |
1379 | 1379 | } |
1380 | - $this->_empty = false; |
|
1380 | + $this->_empty=false; |
|
1381 | 1381 | } |
1382 | 1382 | |
1383 | 1383 | if(isset($config['paths']) && is_array($config['paths'])) |
1384 | - $this->loadPathsPhp($config['paths'],$configPath); |
|
1384 | + $this->loadPathsPhp($config['paths'], $configPath); |
|
1385 | 1385 | |
1386 | 1386 | if(isset($config['modules']) && is_array($config['modules'])) |
1387 | - $this->loadModulesPhp($config['modules'],$configPath); |
|
1387 | + $this->loadModulesPhp($config['modules'], $configPath); |
|
1388 | 1388 | |
1389 | 1389 | if(isset($config['services']) && is_array($config['services'])) |
1390 | - $this->loadServicesPhp($config['services'],$configPath); |
|
1390 | + $this->loadServicesPhp($config['services'], $configPath); |
|
1391 | 1391 | |
1392 | 1392 | if(isset($config['parameters']) && is_array($config['parameters'])) |
1393 | 1393 | $this->loadParametersPhp($config['parameters'], $configPath); |
1394 | 1394 | |
1395 | 1395 | if(isset($config['includes']) && is_array($config['includes'])) |
1396 | - $this->loadExternalXml($config['includes'],$configPath); |
|
1396 | + $this->loadExternalXml($config['includes'], $configPath); |
|
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | /** |
@@ -1401,7 +1401,7 @@ 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 | 1407 | foreach($dom->getAttributes() as $name=>$value) |
@@ -1415,19 +1415,19 @@ discard block |
||
1415 | 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()); |
@@ -1447,15 +1447,15 @@ discard block |
||
1447 | 1447 | { |
1448 | 1448 | foreach($pathsNode['aliases'] as $id=>$path) |
1449 | 1449 | { |
1450 | - $path=str_replace('\\','/',$path); |
|
1451 | - if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) // if absolute path |
|
1450 | + $path=str_replace('\\', '/', $path); |
|
1451 | + if(preg_match('/^\\/|.:\\/|.:\\\\/', $path)) // if absolute path |
|
1452 | 1452 | $p=realpath($path); |
1453 | 1453 | else |
1454 | 1454 | $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
1455 | 1455 | if($p===false || !is_dir($p)) |
1456 | - throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
1456 | + throw new TConfigurationException('appconfig_aliaspath_invalid', $id, $path); |
|
1457 | 1457 | if(isset($this->_aliases[$id])) |
1458 | - throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
1458 | + throw new TConfigurationException('appconfig_alias_redefined', $id); |
|
1459 | 1459 | $this->_aliases[$id]=$p; |
1460 | 1460 | } |
1461 | 1461 | } |
@@ -1464,7 +1464,7 @@ discard block |
||
1464 | 1464 | { |
1465 | 1465 | foreach($pathsNode['using'] as $namespace) |
1466 | 1466 | { |
1467 | - $this->_usings[] = $namespace; |
|
1467 | + $this->_usings[]=$namespace; |
|
1468 | 1468 | } |
1469 | 1469 | } |
1470 | 1470 | } |
@@ -1474,7 +1474,7 @@ 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 | 1479 | foreach($pathsNode->getElements() as $element) |
1480 | 1480 | { |
@@ -1484,15 +1484,15 @@ discard block |
||
1484 | 1484 | { |
1485 | 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 |
|
1487 | + $path=str_replace('\\', '/', $path); |
|
1488 | + if(preg_match('/^\\/|.:\\/|.:\\\\/', $path)) // if absolute path |
|
1489 | 1489 | $p=realpath($path); |
1490 | 1490 | else |
1491 | 1491 | $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
1492 | 1492 | if($p===false || !is_dir($p)) |
1493 | - throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
1493 | + throw new TConfigurationException('appconfig_aliaspath_invalid', $id, $path); |
|
1494 | 1494 | if(isset($this->_aliases[$id])) |
1495 | - throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
1495 | + throw new TConfigurationException('appconfig_alias_redefined', $id); |
|
1496 | 1496 | $this->_aliases[$id]=$p; |
1497 | 1497 | } |
1498 | 1498 | else |
@@ -1510,7 +1510,7 @@ discard block |
||
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 | } |
@@ -1525,17 +1525,17 @@ discard block |
||
1525 | 1525 | foreach($modulesNode as $id=>$module) |
1526 | 1526 | { |
1527 | 1527 | if(!isset($module['class'])) |
1528 | - throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
1529 | - $type = $module['class']; |
|
1528 | + throw new TConfigurationException('appconfig_moduletype_required', $id); |
|
1529 | + $type=$module['class']; |
|
1530 | 1530 | unset($module['class']); |
1531 | - $properties = array(); |
|
1531 | + $properties=array(); |
|
1532 | 1532 | if(isset($module['properties'])) |
1533 | 1533 | { |
1534 | - $properties = $module['properties']; |
|
1534 | + $properties=$module['properties']; |
|
1535 | 1535 | unset($module['properties']); |
1536 | 1536 | } |
1537 | - $properties['id'] = $id; |
|
1538 | - $this->_modules[$id]=array($type,$properties,$module); |
|
1537 | + $properties['id']=$id; |
|
1538 | + $this->_modules[$id]=array($type, $properties, $module); |
|
1539 | 1539 | $this->_empty=false; |
1540 | 1540 | } |
1541 | 1541 | } |
@@ -1545,7 +1545,7 @@ 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 | 1550 | foreach($modulesNode->getElements() as $element) |
1551 | 1551 | { |
@@ -1555,16 +1555,16 @@ discard block |
||
1555 | 1555 | $id=$properties->itemAt('id'); |
1556 | 1556 | $type=$properties->remove('class'); |
1557 | 1557 | if($type===null) |
1558 | - throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
1558 | + throw new TConfigurationException('appconfig_moduletype_required', $id); |
|
1559 | 1559 | $element->setParent(null); |
1560 | 1560 | if($id===null) |
1561 | - $this->_modules[]=array($type,$properties->toArray(),$element); |
|
1561 | + $this->_modules[]=array($type, $properties->toArray(), $element); |
|
1562 | 1562 | else |
1563 | - $this->_modules[$id]=array($type,$properties->toArray(),$element); |
|
1563 | + $this->_modules[$id]=array($type, $properties->toArray(), $element); |
|
1564 | 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,18 +1573,18 @@ 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 | 1578 | foreach($servicesNode as $id => $service) |
1579 | 1579 | { |
1580 | 1580 | if(!isset($service['class'])) |
1581 | 1581 | throw new TConfigurationException('appconfig_servicetype_required'); |
1582 | - $type = $service['class']; |
|
1583 | - $properties = isset($service['properties']) ? $service['properties'] : array(); |
|
1582 | + $type=$service['class']; |
|
1583 | + $properties=isset($service['properties']) ? $service['properties'] : array(); |
|
1584 | 1584 | unset($service['properties']); |
1585 | - $properties['id'] = $id; |
|
1586 | - $this->_services[$id] = array($type,$properties,$service); |
|
1587 | - $this->_empty = false; |
|
1585 | + $properties['id']=$id; |
|
1586 | + $this->_services[$id]=array($type, $properties, $service); |
|
1587 | + $this->_empty=false; |
|
1588 | 1588 | } |
1589 | 1589 | } |
1590 | 1590 | |
@@ -1593,7 +1593,7 @@ 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 | 1598 | foreach($servicesNode->getElements() as $element) |
1599 | 1599 | { |
@@ -1603,13 +1603,13 @@ discard block |
||
1603 | 1603 | if(($id=$properties->itemAt('id'))===null) |
1604 | 1604 | throw new TConfigurationException('appconfig_serviceid_required'); |
1605 | 1605 | if(($type=$properties->remove('class'))===null) |
1606 | - throw new TConfigurationException('appconfig_servicetype_required',$id); |
|
1606 | + throw new TConfigurationException('appconfig_servicetype_required', $id); |
|
1607 | 1607 | $element->setParent(null); |
1608 | - $this->_services[$id]=array($type,$properties->toArray(),$element); |
|
1608 | + $this->_services[$id]=array($type, $properties->toArray(), $element); |
|
1609 | 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,7 +1618,7 @@ 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 | 1623 | foreach($parametersNode as $id => $parameter) |
1624 | 1624 | { |
@@ -1626,16 +1626,16 @@ discard block |
||
1626 | 1626 | { |
1627 | 1627 | if(isset($parameter['class'])) |
1628 | 1628 | { |
1629 | - $type = $parameter['class']; |
|
1629 | + $type=$parameter['class']; |
|
1630 | 1630 | unset($parameter['class']); |
1631 | - $properties = isset($service['properties']) ? $service['properties'] : array(); |
|
1632 | - $properties['id'] = $id; |
|
1633 | - $this->_parameters[$id] = array($type,$properties); |
|
1631 | + $properties=isset($service['properties']) ? $service['properties'] : array(); |
|
1632 | + $properties['id']=$id; |
|
1633 | + $this->_parameters[$id]=array($type, $properties); |
|
1634 | 1634 | } |
1635 | 1635 | } |
1636 | 1636 | else |
1637 | 1637 | { |
1638 | - $this->_parameters[$id] = $parameter; |
|
1638 | + $this->_parameters[$id]=$parameter; |
|
1639 | 1639 | } |
1640 | 1640 | } |
1641 | 1641 | } |
@@ -1645,7 +1645,7 @@ 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 | 1650 | foreach($parametersNode->getElements() as $element) |
1651 | 1651 | { |
@@ -1662,11 +1662,11 @@ discard block |
||
1662 | 1662 | $this->_parameters[$id]=$value; |
1663 | 1663 | } |
1664 | 1664 | else |
1665 | - $this->_parameters[$id]=array($type,$properties->toArray()); |
|
1665 | + $this->_parameters[$id]=array($type, $properties->toArray()); |
|
1666 | 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,14 +1675,14 @@ 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 | 1680 | foreach($includeNode as $include) |
1681 | 1681 | { |
1682 | - $when = isset($include['when'])?true:false; |
|
1682 | + $when=isset($include['when']) ? true : false; |
|
1683 | 1683 | if(!isset($include['file'])) |
1684 | 1684 | throw new TConfigurationException('appconfig_includefile_required'); |
1685 | - $filePath = $include['file']; |
|
1685 | + $filePath=$include['file']; |
|
1686 | 1686 | if(isset($this->_includes[$filePath])) |
1687 | 1687 | $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')'; |
1688 | 1688 | else |
@@ -1696,7 +1696,7 @@ 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 | 1701 | if(($when=$includeNode->getAttribute('when'))===null) |
1702 | 1702 | $when=true; |
@@ -1862,12 +1862,12 @@ discard block |
||
1862 | 1862 | if($cache->get(self::CACHE_NAME)===$content) |
1863 | 1863 | $saveFile=false; |
1864 | 1864 | else |
1865 | - $cache->set(self::CACHE_NAME,$content); |
|
1865 | + $cache->set(self::CACHE_NAME, $content); |
|
1866 | 1866 | } |
1867 | 1867 | if($saveFile) |
1868 | 1868 | { |
1869 | 1869 | $fileName=$this->getStateFilePath(); |
1870 | - file_put_contents($fileName,$content,LOCK_EX); |
|
1870 | + file_put_contents($fileName, $content, LOCK_EX); |
|
1871 | 1871 | } |
1872 | 1872 | } |
1873 | 1873 |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | if($this->_file===null) |
120 | 120 | $this->_file=$this->getApplication()->getRuntimePath().'/sqlite.cache'; |
121 | 121 | $error=''; |
122 | - if(($this->_db=new SQLiteDatabase($this->_file,0666,$error))===false) |
|
123 | - throw new TConfigurationException('sqlitecache_connection_failed',$error); |
|
122 | + if(($this->_db=new SQLiteDatabase($this->_file, 0666, $error))===false) |
|
123 | + throw new TConfigurationException('sqlitecache_connection_failed', $error); |
|
124 | 124 | if(@$this->_db->query('DELETE FROM '.self::CACHE_TABLE.' WHERE expire<>0 AND expire<'.time())===false) |
125 | 125 | { |
126 | 126 | if($this->_db->query('CREATE TABLE '.self::CACHE_TABLE.' (key CHAR(128) PRIMARY KEY, value BLOB, expire INT)')===false) |
127 | - throw new TConfigurationException('sqlitecache_table_creation_failed',sqlite_error_string(sqlite_last_error())); |
|
127 | + throw new TConfigurationException('sqlitecache_table_creation_failed', sqlite_error_string(sqlite_last_error())); |
|
128 | 128 | } |
129 | 129 | $this->_initialized=true; |
130 | 130 | parent::init($config); |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | { |
148 | 148 | if($this->_initialized) |
149 | 149 | throw new TInvalidOperationException('sqlitecache_dbfile_unchangeable'); |
150 | - else if(($this->_file=Prado::getPathOfNamespace($value,self::DB_FILE_EXT))===null) |
|
151 | - throw new TConfigurationException('sqlitecache_dbfile_invalid',$value); |
|
150 | + else if(($this->_file=Prado::getPathOfNamespace($value, self::DB_FILE_EXT))===null) |
|
151 | + throw new TConfigurationException('sqlitecache_dbfile_invalid', $value); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
176 | 176 | * @return boolean true if the value is successfully stored into cache, false otherwise |
177 | 177 | */ |
178 | - protected function setValue($key,$value,$expire) |
|
178 | + protected function setValue($key, $value, $expire) |
|
179 | 179 | { |
180 | - $expire=($expire<=0)?0:time()+$expire; |
|
180 | + $expire=($expire <= 0) ? 0 : time() + $expire; |
|
181 | 181 | $sql='REPLACE INTO '.self::CACHE_TABLE.' VALUES(\''.$key.'\',\''.sqlite_escape_string(serialize($value)).'\','.$expire.')'; |
182 | 182 | return $this->_db->query($sql)!==false; |
183 | 183 | } |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
192 | 192 | * @return boolean true if the value is successfully stored into cache, false otherwise |
193 | 193 | */ |
194 | - protected function addValue($key,$value,$expire) |
|
194 | + protected function addValue($key, $value, $expire) |
|
195 | 195 | { |
196 | - $expire=($expire<=0)?0:time()+$expire; |
|
196 | + $expire=($expire <= 0) ? 0 : time() + $expire; |
|
197 | 197 | $sql='INSERT INTO '.self::CACHE_TABLE.' VALUES(\''.$key.'\',\''.sqlite_escape_string(serialize($value)).'\','.$expire.')'; |
198 | 198 | return @$this->_db->query($sql)!==false; |
199 | 199 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | if($this->getApplication()->getCache()===null) |
65 | 65 | $this->getApplication()->setCache($this); |
66 | 66 | else |
67 | - throw new TConfigurationException('cache_primary_duplicated',get_class($this)); |
|
67 | + throw new TConfigurationException('cache_primary_duplicated', get_class($this)); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labeled invalid. |
143 | 143 | * @return boolean true if the value is successfully stored into cache, false otherwise |
144 | 144 | */ |
145 | - public function set($id,$value,$expire=0,$dependency=null) |
|
145 | + public function set($id, $value, $expire=0, $dependency=null) |
|
146 | 146 | { |
147 | - if(empty($value) && $expire === 0) |
|
147 | + if(empty($value) && $expire===0) |
|
148 | 148 | $this->delete($id); |
149 | 149 | else |
150 | 150 | { |
151 | - $data=array($value,$dependency); |
|
152 | - return $this->setValue($this->generateUniqueKey($id),$data,$expire); |
|
151 | + $data=array($value, $dependency); |
|
152 | + return $this->setValue($this->generateUniqueKey($id), $data, $expire); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labeled invalid. |
163 | 163 | * @return boolean true if the value is successfully stored into cache, false otherwise |
164 | 164 | */ |
165 | - public function add($id,$value,$expire=0,$dependency=null) |
|
165 | + public function add($id, $value, $expire=0, $dependency=null) |
|
166 | 166 | { |
167 | - if(empty($value) && $expire === 0) |
|
167 | + if(empty($value) && $expire===0) |
|
168 | 168 | return false; |
169 | - $data=array($value,$dependency); |
|
170 | - return $this->addValue($this->generateUniqueKey($id),$data,$expire); |
|
169 | + $data=array($value, $dependency); |
|
170 | + return $this->addValue($this->generateUniqueKey($id), $data, $expire); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
215 | 215 | * @return boolean true if the value is successfully stored into cache, false otherwise |
216 | 216 | */ |
217 | - abstract protected function setValue($key,$value,$expire); |
|
217 | + abstract protected function setValue($key, $value, $expire); |
|
218 | 218 | |
219 | 219 | /** |
220 | 220 | * Stores a value identified by a key into cache if the cache does not contain this key. |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
229 | 229 | * @return boolean true if the value is successfully stored into cache, false otherwise |
230 | 230 | */ |
231 | - abstract protected function addValue($key,$value,$expire); |
|
231 | + abstract protected function addValue($key, $value, $expire); |
|
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Deletes a value with the specified key from cache |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function offsetExists($id) |
248 | 248 | { |
249 | - return $this->get($id) !== false; |
|
249 | + return $this->get($id)!==false; |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | public function setDirectory($directory) |
431 | 431 | { |
432 | 432 | if(($path=realpath($directory))===false || !is_dir($path)) |
433 | - throw new TInvalidDataValueException('directorycachedependency_directory_invalid',$directory); |
|
433 | + throw new TInvalidDataValueException('directorycachedependency_directory_invalid', $directory); |
|
434 | 434 | $this->_directory=$path; |
435 | 435 | $this->_timestamps=$this->generateTimestamps($path); |
436 | 436 | } |
@@ -518,10 +518,10 @@ discard block |
||
518 | 518 | * @param int level of the recursion |
519 | 519 | * @return array list of file modification time indexed by the file path |
520 | 520 | */ |
521 | - protected function generateTimestamps($directory,$level=0) |
|
521 | + protected function generateTimestamps($directory, $level=0) |
|
522 | 522 | { |
523 | 523 | if(($dir=opendir($directory))===false) |
524 | - throw new TIOException('directorycachedependency_directory_invalid',$directory); |
|
524 | + throw new TIOException('directorycachedependency_directory_invalid', $directory); |
|
525 | 525 | $timestamps=array(); |
526 | 526 | while(($file=readdir($dir))!==false) |
527 | 527 | { |
@@ -530,8 +530,8 @@ discard block |
||
530 | 530 | continue; |
531 | 531 | else if(is_dir($path)) |
532 | 532 | { |
533 | - if(($this->_recursiveLevel<0 || $level<$this->_recursiveLevel) && $this->validateDirectory($path)) |
|
534 | - $timestamps=array_merge($this->generateTimestamps($path,$level+1)); |
|
533 | + if(($this->_recursiveLevel < 0 || $level < $this->_recursiveLevel) && $this->validateDirectory($path)) |
|
534 | + $timestamps=array_merge($this->generateTimestamps($path, $level + 1)); |
|
535 | 535 | } |
536 | 536 | else if($this->validateFile($path)) |
537 | 537 | $timestamps[$path]=filemtime($path); |
@@ -699,10 +699,10 @@ discard block |
||
699 | 699 | * @param mixed new item |
700 | 700 | * @throws TInvalidDataTypeException if the item to be inserted is not a dependency instance |
701 | 701 | */ |
702 | - public function insertAt($index,$item) |
|
702 | + public function insertAt($index, $item) |
|
703 | 703 | { |
704 | 704 | if($item instanceof ICacheDependency) |
705 | - parent::insertAt($index,$item); |
|
705 | + parent::insertAt($index, $item); |
|
706 | 706 | else |
707 | 707 | throw new TInvalidDataTypeException('cachedependencylist_cachedependency_required'); |
708 | 708 | } |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | if(!extension_loaded('apc')) |
57 | 57 | throw new TConfigurationException('apccache_extension_required'); |
58 | 58 | |
59 | - if(ini_get('apc.enabled') == false) |
|
59 | + if(ini_get('apc.enabled')==false) |
|
60 | 60 | throw new TConfigurationException('apccache_extension_not_enabled'); |
61 | 61 | |
62 | - if(substr(php_sapi_name(), 0, 3) === 'cli' and ini_get('apc.enable_cli') == false) |
|
62 | + if(substr(php_sapi_name(), 0, 3)==='cli' and ini_get('apc.enable_cli')==false) |
|
63 | 63 | throw new TConfigurationException('apccache_extension_not_enabled_cli'); |
64 | 64 | |
65 | 65 | parent::init($config); |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
86 | 86 | * @return boolean true if the value is successfully stored into cache, false otherwise |
87 | 87 | */ |
88 | - protected function setValue($key,$value,$expire) |
|
88 | + protected function setValue($key, $value, $expire) |
|
89 | 89 | { |
90 | - return apc_store($key,$value,$expire); |
|
90 | + return apc_store($key, $value, $expire); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
100 | 100 | * @return boolean true if the value is successfully stored into cache, false otherwise |
101 | 101 | */ |
102 | - protected function addValue($key,$value,$expire) |
|
102 | + protected function addValue($key, $value, $expire) |
|
103 | 103 | { |
104 | - return apc_add($key,$value,$expire); |
|
104 | + return apc_add($key, $value, $expire); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -104,17 +104,17 @@ discard block |
||
104 | 104 | /** |
105 | 105 | * @var boolean controls the use of a persistent connection. Default to true. |
106 | 106 | */ |
107 | - private $_persistence = true; |
|
107 | + private $_persistence=true; |
|
108 | 108 | /** |
109 | 109 | * @var integer number of buckets to create for this server which in turn control its |
110 | 110 | * probability of it being selected. The probability is relative to the total weight |
111 | 111 | * of all servers. |
112 | 112 | */ |
113 | - private $_weight = 1; |
|
113 | + private $_weight=1; |
|
114 | 114 | |
115 | - private $_timeout = 360; |
|
115 | + private $_timeout=360; |
|
116 | 116 | |
117 | - private $_retryInterval = 15; |
|
117 | + private $_retryInterval=15; |
|
118 | 118 | /** |
119 | 119 | * @var integer Controls the minimum value length before attempting to compress automatically. |
120 | 120 | */ |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | */ |
126 | 126 | private $_minSavings=0.0; |
127 | 127 | |
128 | - private $_status = true; |
|
128 | + private $_status=true; |
|
129 | 129 | |
130 | - private $_failureCallback = null; |
|
130 | + private $_failureCallback=null; |
|
131 | 131 | |
132 | 132 | /** |
133 | 133 | * @var boolean whether to use memcached or memcache as the underlying caching extension. |
@@ -168,26 +168,26 @@ discard block |
||
168 | 168 | if(!extension_loaded('memcached') && $this->_useMemcached) |
169 | 169 | throw new TConfigurationException('memcached_extension_required'); |
170 | 170 | |
171 | - $this->_cache = $this->_useMemcached ? new Memcached : new Memcache; |
|
171 | + $this->_cache=$this->_useMemcached ? new Memcached : new Memcache; |
|
172 | 172 | $this->loadConfig($config); |
173 | 173 | if(count($this->_servers)) |
174 | 174 | { |
175 | 175 | foreach($this->_servers as $server) |
176 | 176 | { |
177 | 177 | Prado::trace('Adding server '.$server['Host'].' from serverlist', 'System.Caching.TMemCache'); |
178 | - if($this->_cache->addServer($server['Host'],$server['Port'],$server['Persistent'], |
|
179 | - $server['Weight'],$server['Timeout'],$server['RetryInterval'])===false) |
|
180 | - throw new TConfigurationException('memcache_connection_failed',$server['Host'],$server['Port']); |
|
178 | + if($this->_cache->addServer($server['Host'], $server['Port'], $server['Persistent'], |
|
179 | + $server['Weight'], $server['Timeout'], $server['RetryInterval'])===false) |
|
180 | + throw new TConfigurationException('memcache_connection_failed', $server['Host'], $server['Port']); |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | else |
184 | 184 | { |
185 | 185 | Prado::trace('Adding server '.$this->_host, 'System.Caching.TMemCache'); |
186 | - if($this->_cache->addServer($this->_host,$this->_port)===false) |
|
187 | - throw new TConfigurationException('memcache_connection_failed',$this->_host,$this->_port); |
|
186 | + if($this->_cache->addServer($this->_host, $this->_port)===false) |
|
187 | + throw new TConfigurationException('memcache_connection_failed', $this->_host, $this->_port); |
|
188 | 188 | } |
189 | 189 | if($this->_threshold!==0) |
190 | - $this->_cache->setCompressThreshold($this->_threshold,$this->_minSavings); |
|
190 | + $this->_cache->setCompressThreshold($this->_threshold, $this->_minSavings); |
|
191 | 191 | $this->_initialized=true; |
192 | 192 | parent::init($config); |
193 | 193 | } |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | throw new TConfigurationException('memcache_serverport_required'); |
211 | 211 | if(!is_numeric($port)) |
212 | 212 | throw new TConfigurationException('memcache_serverport_invalid'); |
213 | - $server = array('Host'=>$host,'Port'=>$port,'Weight'=>1,'Timeout'=>1800,'RetryInterval'=>15,'Persistent'=>true); |
|
214 | - $checks = array( |
|
213 | + $server=array('Host'=>$host, 'Port'=>$port, 'Weight'=>1, 'Timeout'=>1800, 'RetryInterval'=>15, 'Persistent'=>true); |
|
214 | + $checks=array( |
|
215 | 215 | 'Weight'=>'memcache_serverweight_invalid', |
216 | 216 | 'Timeout'=>'memcache_servertimeout_invalid', |
217 | 217 | 'RetryInterval'=>'memcach_serverretryinterval_invalid' |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | else if($value!==null) |
225 | 225 | throw new TConfigurationException($exception); |
226 | 226 | } |
227 | - $server['Persistent']= TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
|
227 | + $server['Persistent']=TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
|
228 | 228 | $this->_servers[]=$server; |
229 | 229 | } |
230 | 230 | } |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
351 | 351 | * @return boolean true if the value is successfully stored into cache, false otherwise |
352 | 352 | */ |
353 | - protected function setValue($key,$value,$expire) |
|
353 | + protected function setValue($key, $value, $expire) |
|
354 | 354 | { |
355 | 355 | if($this->_useMemcached) { |
356 | - return $this->_cache->set($key,$value,$expire); |
|
356 | + return $this->_cache->set($key, $value, $expire); |
|
357 | 357 | } else { |
358 | - return $this->_cache->set($key,$value,0,$expire); |
|
358 | + return $this->_cache->set($key, $value, 0, $expire); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
369 | 369 | * @return boolean true if the value is successfully stored into cache, false otherwise |
370 | 370 | */ |
371 | - protected function addValue($key,$value,$expire) |
|
371 | + protected function addValue($key, $value, $expire) |
|
372 | 372 | { |
373 | 373 | if($this->_useMemcached) { |
374 | - $this->_cache->add($key,$value,$expire); |
|
374 | + $this->_cache->add($key, $value, $expire); |
|
375 | 375 | } else { |
376 | - return $this->_cache->add($key,$value,0,$expire); |
|
376 | + return $this->_cache->add($key, $value, 0, $expire); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 |