@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | - * @return TSqlMapper The SqlMap used by this MappedStatement |
|
87 | + * @return TSqlMapManager The SqlMap used by this MappedStatement |
|
88 | 88 | */ |
89 | 89 | public function getManager() |
90 | 90 | { |
@@ -469,6 +469,7 @@ discard block |
||
469 | 469 | * @param IDbConnection database connection |
470 | 470 | * @param mixed insert statement parameter |
471 | 471 | * @param TSqlMapSelectKey select key statement |
472 | + * @param TSqlMapSelectKey $selectKey |
|
472 | 473 | * @return string last insert ID. |
473 | 474 | */ |
474 | 475 | protected function executeSelectKey($connection, $parameter, $selectKey) |
@@ -569,6 +570,7 @@ discard block |
||
569 | 570 | * @param string result object class name |
570 | 571 | * @param array a result set row retrieved from the database |
571 | 572 | * @param object the result object, will create if necessary. |
573 | + * @param string $resultClass |
|
572 | 574 | * @return object result object filled with data |
573 | 575 | */ |
574 | 576 | protected function fillResultClass($resultClass, $row, $resultObject) |
@@ -591,6 +593,7 @@ discard block |
||
591 | 593 | * Apply the result to a TList or an array. |
592 | 594 | * @param array a result set row retrieved from the database |
593 | 595 | * @param object result object, array or list |
596 | + * @param ArrayAccess $resultObject |
|
594 | 597 | * @return object result filled with data. |
595 | 598 | */ |
596 | 599 | protected function fillResultArrayList($row, $resultObject) |
@@ -633,6 +636,7 @@ discard block |
||
633 | 636 | * @param string result map name. |
634 | 637 | * @param array a result set row retrieved from the database |
635 | 638 | * @param object result object to fill, will create new instances if required. |
639 | + * @param string $parentGroup |
|
636 | 640 | * @return object result object filled with data. |
637 | 641 | */ |
638 | 642 | protected function fillResultMap($resultMapName, $row, $parentGroup=null, &$resultObject=null) |
@@ -772,6 +776,7 @@ discard block |
||
772 | 776 | * Converts the first array value to scalar value of given type. |
773 | 777 | * @param array list of results |
774 | 778 | * @param string scalar type. |
779 | + * @param string $type |
|
775 | 780 | * @return mixed scalar value. |
776 | 781 | */ |
777 | 782 | protected function getScalarResult($result, $type) |
@@ -961,6 +966,10 @@ discard block |
||
961 | 966 | public function setKeys($value){ $this->_keys = $value; } |
962 | 967 | |
963 | 968 | public function getMethod(){ return $this->_method; } |
969 | + |
|
970 | + /** |
|
971 | + * @param integer $value |
|
972 | + */ |
|
964 | 973 | public function setMethod($value){ $this->_method = $value; } |
965 | 974 | } |
966 | 975 | |
@@ -1003,6 +1012,7 @@ discard block |
||
1003 | 1012 | * @param string parent node id |
1004 | 1013 | * @param string new node id |
1005 | 1014 | * @param mixed node value |
1015 | + * @param string $node |
|
1006 | 1016 | */ |
1007 | 1017 | public function add($parent, $node, $object='') |
1008 | 1018 | { |
@@ -1168,6 +1178,9 @@ discard block |
||
1168 | 1178 | private $_parameterObject; |
1169 | 1179 | private $_list; |
1170 | 1180 | |
1181 | + /** |
|
1182 | + * @param ArrayAccess $list |
|
1183 | + */ |
|
1171 | 1184 | public function __construct($result, $parameter, &$list) |
1172 | 1185 | { |
1173 | 1186 | $this->_resultObject = $result; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @var TPostSelectBinding[] post select statement queue. |
41 | 41 | */ |
42 | - private $_selectQueue=array(); |
|
42 | + private $_selectQueue = array(); |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @var boolean true when data is mapped to a particular row. |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | */ |
162 | 162 | protected function executeSQLQueryLimit($connection, $command, $max, $skip) |
163 | 163 | { |
164 | - if($max>-1 || $skip > -1) |
|
164 | + if ($max > -1 || $skip > -1) |
|
165 | 165 | { |
166 | - $maxStr=$max>0?' LIMIT '.$max:''; |
|
167 | - $skipStr=$skip>0?' OFFSET '.$skip:''; |
|
168 | - $command->setText($command->getText().$maxStr.$skipStr); |
|
166 | + $maxStr = $max > 0 ? ' LIMIT ' . $max : ''; |
|
167 | + $skipStr = $skip > 0 ? ' OFFSET ' . $skip : ''; |
|
168 | + $command->setText($command->getText() . $maxStr . $skipStr); |
|
169 | 169 | } |
170 | 170 | $connection->setActive(true); |
171 | 171 | return $command->query(); |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | * @param callback row delegate handler |
200 | 200 | * @see executeQueryForList() |
201 | 201 | */ |
202 | - public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null) |
|
202 | + public function executeQueryForList($connection, $parameter, $result = null, $skip = -1, $max = -1, $delegate = null) |
|
203 | 203 | { |
204 | - $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter,$skip,$max); |
|
204 | + $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter, $skip, $max); |
|
205 | 205 | return $this->runQueryForList($connection, $parameter, $sql, $result, $delegate); |
206 | 206 | } |
207 | 207 | |
@@ -221,17 +221,16 @@ discard block |
||
221 | 221 | * @return array a list of result objects |
222 | 222 | * @see executeQueryForList() |
223 | 223 | */ |
224 | - public function runQueryForList($connection, $parameter, $sql, $result, $delegate=null) |
|
224 | + public function runQueryForList($connection, $parameter, $sql, $result, $delegate = null) |
|
225 | 225 | { |
226 | - $registry=$this->getManager()->getTypeHandlers(); |
|
227 | - $list = $result instanceof ArrayAccess ? $result : |
|
228 | - $this->_statement->createInstanceOfListClass($registry); |
|
226 | + $registry = $this->getManager()->getTypeHandlers(); |
|
227 | + $list = $result instanceof ArrayAccess ? $result : $this->_statement->createInstanceOfListClass($registry); |
|
229 | 228 | $connection->setActive(true); |
230 | 229 | $reader = $sql->query(); |
231 | 230 | //$reader = $this->executeSQLQueryLimit($connection, $sql, $max, $skip); |
232 | - if($delegate!==null) |
|
231 | + if ($delegate !== null) |
|
233 | 232 | { |
234 | - foreach($reader as $row) |
|
233 | + foreach ($reader as $row) |
|
235 | 234 | { |
236 | 235 | $obj = $this->applyResultMap($row); |
237 | 236 | $param = new TResultSetListItemParameter($obj, $parameter, $list); |
@@ -241,14 +240,14 @@ discard block |
||
241 | 240 | else |
242 | 241 | { |
243 | 242 | //var_dump($sql,$parameter); |
244 | - foreach($reader as $row) |
|
243 | + foreach ($reader as $row) |
|
245 | 244 | { |
246 | 245 | // var_dump($row); |
247 | 246 | $list[] = $this->applyResultMap($row); |
248 | 247 | } |
249 | 248 | } |
250 | 249 | |
251 | - if(!$this->_groupBy->isEmpty()) |
|
250 | + if (!$this->_groupBy->isEmpty()) |
|
252 | 251 | { |
253 | 252 | $list = $this->_groupBy->collect(); |
254 | 253 | $this->initialGroupByResults(); |
@@ -272,7 +271,7 @@ discard block |
||
272 | 271 | * @param callback row delegate handler |
273 | 272 | * @return array An array of object containing the rows keyed by keyProperty. |
274 | 273 | */ |
275 | - public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null, $skip=-1, $max=-1, $delegate=null) |
|
274 | + public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty = null, $skip = -1, $max = -1, $delegate = null) |
|
276 | 275 | { |
277 | 276 | $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter, $skip, $max); |
278 | 277 | return $this->runQueryForMap($connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate); |
@@ -296,21 +295,20 @@ discard block |
||
296 | 295 | * @return array An array of object containing the rows keyed by keyProperty. |
297 | 296 | * @see executeQueryForMap() |
298 | 297 | */ |
299 | - public function runQueryForMap($connection, $parameter, $command, $keyProperty, $valueProperty=null, $delegate=null) |
|
298 | + public function runQueryForMap($connection, $parameter, $command, $keyProperty, $valueProperty = null, $delegate = null) |
|
300 | 299 | { |
301 | 300 | $map = array(); |
302 | 301 | //$recordSet = $this->executeSQLQuery($connection, $sql); |
303 | 302 | $connection->setActive(true); |
304 | 303 | $reader = $command->query(); |
305 | - if($delegate!==null) |
|
304 | + if ($delegate !== null) |
|
306 | 305 | { |
307 | 306 | //while($row = $recordSet->fetchRow()) |
308 | - foreach($reader as $row) |
|
307 | + foreach ($reader as $row) |
|
309 | 308 | { |
310 | 309 | $obj = $this->applyResultMap($row); |
311 | 310 | $key = TPropertyAccess::get($obj, $keyProperty); |
312 | - $value = ($valueProperty===null) ? $obj : |
|
313 | - TPropertyAccess::get($obj, $valueProperty); |
|
311 | + $value = ($valueProperty === null) ? $obj : TPropertyAccess::get($obj, $valueProperty); |
|
314 | 312 | $param = new TResultSetMapItemParameter($key, $value, $parameter, $map); |
315 | 313 | $this->raiseRowDelegate($delegate, $param); |
316 | 314 | } |
@@ -318,12 +316,11 @@ discard block |
||
318 | 316 | else |
319 | 317 | { |
320 | 318 | //while($row = $recordSet->fetchRow()) |
321 | - foreach($reader as $row) |
|
319 | + foreach ($reader as $row) |
|
322 | 320 | { |
323 | 321 | $obj = $this->applyResultMap($row); |
324 | 322 | $key = TPropertyAccess::get($obj, $keyProperty); |
325 | - $map[$key] = ($valueProperty===null) ? $obj : |
|
326 | - TPropertyAccess::get($obj, $valueProperty); |
|
323 | + $map[$key] = ($valueProperty === null) ? $obj : TPropertyAccess::get($obj, $valueProperty); |
|
327 | 324 | } |
328 | 325 | } |
329 | 326 | $this->onExecuteQuery($command); |
@@ -338,24 +335,24 @@ discard block |
||
338 | 335 | */ |
339 | 336 | protected function raiseRowDelegate($handler, $param) |
340 | 337 | { |
341 | - if(is_string($handler)) |
|
338 | + if (is_string($handler)) |
|
342 | 339 | { |
343 | - call_user_func($handler,$this,$param); |
|
340 | + call_user_func($handler, $this, $param); |
|
344 | 341 | } |
345 | - else if(is_callable($handler,true)) |
|
342 | + else if (is_callable($handler, true)) |
|
346 | 343 | { |
347 | 344 | // an array: 0 - object, 1 - method name/path |
348 | - list($object,$method)=$handler; |
|
349 | - if(is_string($object)) // static method call |
|
350 | - call_user_func($handler,$this,$param); |
|
345 | + list($object, $method) = $handler; |
|
346 | + if (is_string($object)) // static method call |
|
347 | + call_user_func($handler, $this, $param); |
|
351 | 348 | else |
352 | 349 | { |
353 | - if(($pos=strrpos($method,'.'))!==false) |
|
350 | + if (($pos = strrpos($method, '.')) !== false) |
|
354 | 351 | { |
355 | - $object=$this->getSubProperty(substr($method,0,$pos)); |
|
356 | - $method=substr($method,$pos+1); |
|
352 | + $object = $this->getSubProperty(substr($method, 0, $pos)); |
|
353 | + $method = substr($method, $pos + 1); |
|
357 | 354 | } |
358 | - $object->$method($this,$param); |
|
355 | + $object->$method($this, $param); |
|
359 | 356 | } |
360 | 357 | } |
361 | 358 | else |
@@ -370,7 +367,7 @@ discard block |
||
370 | 367 | * @param mixed The result object. |
371 | 368 | * @return ${return} |
372 | 369 | */ |
373 | - public function executeQueryForObject($connection, $parameter, $result=null) |
|
370 | + public function executeQueryForObject($connection, $parameter, $result = null) |
|
374 | 371 | { |
375 | 372 | $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter); |
376 | 373 | return $this->runQueryForObject($connection, $sql, $result); |
@@ -393,10 +390,10 @@ discard block |
||
393 | 390 | { |
394 | 391 | $object = null; |
395 | 392 | $connection->setActive(true); |
396 | - foreach($command->query() as $row) |
|
393 | + foreach ($command->query() as $row) |
|
397 | 394 | $object = $this->applyResultMap($row, $result); |
398 | 395 | |
399 | - if(!$this->_groupBy->isEmpty()) |
|
396 | + if (!$this->_groupBy->isEmpty()) |
|
400 | 397 | { |
401 | 398 | $list = $this->_groupBy->collect(); |
402 | 399 | $this->initialGroupByResults(); |
@@ -424,7 +421,7 @@ discard block |
||
424 | 421 | // var_dump($command,$parameter); |
425 | 422 | $result = $command->execute(); |
426 | 423 | |
427 | - if($generatedKey===null) |
|
424 | + if ($generatedKey === null) |
|
428 | 425 | $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter); |
429 | 426 | |
430 | 427 | $this->executePostSelect($connection); |
@@ -440,10 +437,10 @@ discard block |
||
440 | 437 | */ |
441 | 438 | protected function getPreGeneratedSelectKey($connection, $parameter) |
442 | 439 | { |
443 | - if($this->_statement instanceof TSqlMapInsert) |
|
440 | + if ($this->_statement instanceof TSqlMapInsert) |
|
444 | 441 | { |
445 | 442 | $selectKey = $this->_statement->getSelectKey(); |
446 | - if(($selectKey!==null) && !$selectKey->getIsAfter()) |
|
443 | + if (($selectKey !== null) && !$selectKey->getIsAfter()) |
|
447 | 444 | return $this->executeSelectKey($connection, $parameter, $selectKey); |
448 | 445 | } |
449 | 446 | } |
@@ -456,10 +453,10 @@ discard block |
||
456 | 453 | */ |
457 | 454 | protected function getPostGeneratedSelectKey($connection, $parameter) |
458 | 455 | { |
459 | - if($this->_statement instanceof TSqlMapInsert) |
|
456 | + if ($this->_statement instanceof TSqlMapInsert) |
|
460 | 457 | { |
461 | 458 | $selectKey = $this->_statement->getSelectKey(); |
462 | - if(($selectKey!==null) && $selectKey->getIsAfter()) |
|
459 | + if (($selectKey !== null) && $selectKey->getIsAfter()) |
|
463 | 460 | return $this->executeSelectKey($connection, $parameter, $selectKey); |
464 | 461 | } |
465 | 462 | } |
@@ -476,7 +473,7 @@ discard block |
||
476 | 473 | $mappedStatement = $this->getManager()->getMappedStatement($selectKey->getID()); |
477 | 474 | $generatedKey = $mappedStatement->executeQueryForObject( |
478 | 475 | $connection, $parameter, null); |
479 | - if(strlen($prop = $selectKey->getProperty()) > 0) |
|
476 | + if (strlen($prop = $selectKey->getProperty()) > 0) |
|
480 | 477 | TPropertyAccess::set($parameter, $prop, $generatedKey); |
481 | 478 | return $generatedKey; |
482 | 479 | } |
@@ -490,7 +487,7 @@ discard block |
||
490 | 487 | */ |
491 | 488 | public function executeUpdate($connection, $parameter) |
492 | 489 | { |
493 | - $sql = $this->_command->create($this->getManager(),$connection, $this->_statement, $parameter); |
|
490 | + $sql = $this->_command->create($this->getManager(), $connection, $this->_statement, $parameter); |
|
494 | 491 | $affectedRows = $sql->execute(); |
495 | 492 | //$this->executeSQLQuery($connection, $sql); |
496 | 493 | $this->executePostSelect($connection); |
@@ -504,7 +501,7 @@ discard block |
||
504 | 501 | */ |
505 | 502 | protected function executePostSelect($connection) |
506 | 503 | { |
507 | - while(count($this->_selectQueue)) |
|
504 | + while (count($this->_selectQueue)) |
|
508 | 505 | { |
509 | 506 | $postSelect = array_shift($this->_selectQueue); |
510 | 507 | $method = $postSelect->getMethod(); |
@@ -513,15 +510,15 @@ discard block |
||
513 | 510 | $keys = $postSelect->getKeys(); |
514 | 511 | $resultObject = $postSelect->getResultObject(); |
515 | 512 | |
516 | - if($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY) |
|
513 | + if ($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY) |
|
517 | 514 | { |
518 | 515 | $values = $statement->executeQueryForList($connection, $keys, null); |
519 | 516 | |
520 | - if($method == self::QUERY_FOR_ARRAY) |
|
517 | + if ($method == self::QUERY_FOR_ARRAY) |
|
521 | 518 | $values = $values->toArray(); |
522 | 519 | TPropertyAccess::set($resultObject, $property, $values); |
523 | 520 | } |
524 | - else if($method == self::QUERY_FOR_OBJECT) |
|
521 | + else if ($method == self::QUERY_FOR_OBJECT) |
|
525 | 522 | { |
526 | 523 | $value = $statement->executeQueryForObject($connection, $keys, null); |
527 | 524 | TPropertyAccess::set($resultObject, $property, $value); |
@@ -544,23 +541,23 @@ discard block |
||
544 | 541 | * @param object the result object, will create if necessary. |
545 | 542 | * @return object the result filled with data, null if not filled. |
546 | 543 | */ |
547 | - protected function applyResultMap($row, &$resultObject=null) |
|
544 | + protected function applyResultMap($row, &$resultObject = null) |
|
548 | 545 | { |
549 | - if($row === false) return null; |
|
546 | + if ($row === false) return null; |
|
550 | 547 | |
551 | 548 | $resultMapName = $this->_statement->getResultMap(); |
552 | 549 | $resultClass = $this->_statement->getResultClass(); |
553 | 550 | |
554 | - $obj=null; |
|
555 | - if($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
551 | + $obj = null; |
|
552 | + if ($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
556 | 553 | $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject); |
557 | - else if(strlen($resultClass) > 0) |
|
554 | + else if (strlen($resultClass) > 0) |
|
558 | 555 | $obj = $this->fillResultClass($resultClass, $row, $resultObject); |
559 | 556 | else |
560 | 557 | $obj = $this->fillDefaultResultMap(null, $row, $resultObject); |
561 | - if(class_exists('TActiveRecord',false) && $obj instanceof TActiveRecord) |
|
558 | + if (class_exists('TActiveRecord', false) && $obj instanceof TActiveRecord) |
|
562 | 559 | //Create a new clean active record. |
563 | - $obj=TActiveRecord::createRecord(get_class($obj),$obj); |
|
560 | + $obj = TActiveRecord::createRecord(get_class($obj), $obj); |
|
564 | 561 | return $obj; |
565 | 562 | } |
566 | 563 | |
@@ -573,15 +570,15 @@ discard block |
||
573 | 570 | */ |
574 | 571 | protected function fillResultClass($resultClass, $row, $resultObject) |
575 | 572 | { |
576 | - if($resultObject===null) |
|
573 | + if ($resultObject === null) |
|
577 | 574 | { |
578 | 575 | $registry = $this->getManager()->getTypeHandlers(); |
579 | - $resultObject = $this->_statement->createInstanceOfResultClass($registry,$row); |
|
576 | + $resultObject = $this->_statement->createInstanceOfResultClass($registry, $row); |
|
580 | 577 | } |
581 | 578 | |
582 | - if($resultObject instanceOf ArrayAccess) |
|
579 | + if ($resultObject instanceOf ArrayAccess) |
|
583 | 580 | return $this->fillResultArrayList($row, $resultObject); |
584 | - else if(is_object($resultObject)) |
|
581 | + else if (is_object($resultObject)) |
|
585 | 582 | return $this->fillResultObjectProperty($row, $resultObject); |
586 | 583 | else |
587 | 584 | return $this->fillDefaultResultMap(null, $row, $resultObject); |
@@ -595,11 +592,11 @@ discard block |
||
595 | 592 | */ |
596 | 593 | protected function fillResultArrayList($row, $resultObject) |
597 | 594 | { |
598 | - if($resultObject instanceof TList) |
|
599 | - foreach($row as $v) |
|
595 | + if ($resultObject instanceof TList) |
|
596 | + foreach ($row as $v) |
|
600 | 597 | $resultObject[] = $v; |
601 | 598 | else |
602 | - foreach($row as $k => $v) |
|
599 | + foreach ($row as $k => $v) |
|
603 | 600 | $resultObject[$k] = $v; |
604 | 601 | return $resultObject; |
605 | 602 | } |
@@ -613,17 +610,17 @@ discard block |
||
613 | 610 | protected function fillResultObjectProperty($row, $resultObject) |
614 | 611 | { |
615 | 612 | $index = 0; |
616 | - $registry=$this->getManager()->getTypeHandlers(); |
|
617 | - foreach($row as $k=>$v) |
|
613 | + $registry = $this->getManager()->getTypeHandlers(); |
|
614 | + foreach ($row as $k=>$v) |
|
618 | 615 | { |
619 | 616 | $property = new TResultProperty; |
620 | - if(is_string($k) && strlen($k) > 0) |
|
617 | + if (is_string($k) && strlen($k) > 0) |
|
621 | 618 | $property->setColumn($k); |
622 | 619 | $property->setColumnIndex(++$index); |
623 | - $type = gettype(TPropertyAccess::get($resultObject,$k)); |
|
620 | + $type = gettype(TPropertyAccess::get($resultObject, $k)); |
|
624 | 621 | $property->setType($type); |
625 | - $value = $property->getPropertyValue($registry,$row); |
|
626 | - TPropertyAccess::set($resultObject, $k,$value); |
|
622 | + $value = $property->getPropertyValue($registry, $row); |
|
623 | + TPropertyAccess::set($resultObject, $k, $value); |
|
627 | 624 | } |
628 | 625 | return $resultObject; |
629 | 626 | } |
@@ -635,21 +632,21 @@ discard block |
||
635 | 632 | * @param object result object to fill, will create new instances if required. |
636 | 633 | * @return object result object filled with data. |
637 | 634 | */ |
638 | - protected function fillResultMap($resultMapName, $row, $parentGroup=null, &$resultObject=null) |
|
635 | + protected function fillResultMap($resultMapName, $row, $parentGroup = null, &$resultObject = null) |
|
639 | 636 | { |
640 | 637 | $resultMap = $this->getManager()->getResultMap($resultMapName); |
641 | 638 | $registry = $this->getManager()->getTypeHandlers(); |
642 | - $resultMap = $resultMap->resolveSubMap($registry,$row); |
|
639 | + $resultMap = $resultMap->resolveSubMap($registry, $row); |
|
643 | 640 | |
644 | - if($resultObject===null) |
|
641 | + if ($resultObject === null) |
|
645 | 642 | $resultObject = $resultMap->createInstanceOfResult($registry); |
646 | 643 | |
647 | - if(is_object($resultObject)) |
|
644 | + if (is_object($resultObject)) |
|
648 | 645 | { |
649 | - if(strlen($resultMap->getGroupBy()) > 0) |
|
646 | + if (strlen($resultMap->getGroupBy()) > 0) |
|
650 | 647 | return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
651 | 648 | else |
652 | - foreach($resultMap->getColumns() as $property) |
|
649 | + foreach ($resultMap->getColumns() as $property) |
|
653 | 650 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
654 | 651 | } |
655 | 652 | else |
@@ -671,26 +668,26 @@ discard block |
||
671 | 668 | { |
672 | 669 | $group = $this->getResultMapGroupKey($resultMap, $row); |
673 | 670 | |
674 | - if(empty($parent)) |
|
671 | + if (empty($parent)) |
|
675 | 672 | { |
676 | 673 | $rootObject = array('object'=>$resultObject, 'property' => null); |
677 | 674 | $this->_groupBy->add(null, $group, $rootObject); |
678 | 675 | } |
679 | 676 | |
680 | - foreach($resultMap->getColumns() as $property) |
|
677 | + foreach ($resultMap->getColumns() as $property) |
|
681 | 678 | { |
682 | 679 | //set properties. |
683 | 680 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
684 | 681 | $nested = $property->getResultMapping(); |
685 | 682 | |
686 | 683 | //nested property |
687 | - if($this->getManager()->getResultMaps()->contains($nested)) |
|
684 | + if ($this->getManager()->getResultMaps()->contains($nested)) |
|
688 | 685 | { |
689 | 686 | $nestedMap = $this->getManager()->getResultMap($nested); |
690 | 687 | $groupKey = $this->getResultMapGroupKey($nestedMap, $row); |
691 | 688 | |
692 | 689 | //add the node reference first |
693 | - if(empty($parent)) |
|
690 | + if (empty($parent)) |
|
694 | 691 | $this->_groupBy->add($group, $groupKey, ''); |
695 | 692 | |
696 | 693 | //get the nested result mapping value |
@@ -698,7 +695,7 @@ discard block |
||
698 | 695 | |
699 | 696 | //add it to the object tree graph |
700 | 697 | $groupObject = array('object'=>$value, 'property' => $property->getProperty()); |
701 | - if(empty($parent)) |
|
698 | + if (empty($parent)) |
|
702 | 699 | $this->_groupBy->add($group, $groupKey, $groupObject); |
703 | 700 | else |
704 | 701 | $this->_groupBy->add($parent, $groupKey, $groupObject); |
@@ -716,10 +713,10 @@ discard block |
||
716 | 713 | protected function getResultMapGroupKey($resultMap, $row) |
717 | 714 | { |
718 | 715 | $groupBy = $resultMap->getGroupBy(); |
719 | - if(isset($row[$groupBy])) |
|
720 | - return $resultMap->getID().$row[$groupBy]; |
|
716 | + if (isset($row[$groupBy])) |
|
717 | + return $resultMap->getID() . $row[$groupBy]; |
|
721 | 718 | else |
722 | - return $resultMap->getID().crc32(serialize($row)); |
|
719 | + return $resultMap->getID() . crc32(serialize($row)); |
|
723 | 720 | } |
724 | 721 | |
725 | 722 | /** |
@@ -732,16 +729,16 @@ discard block |
||
732 | 729 | */ |
733 | 730 | protected function fillDefaultResultMap($resultMap, $row, $resultObject) |
734 | 731 | { |
735 | - if($resultObject===null) |
|
736 | - $resultObject=''; |
|
732 | + if ($resultObject === null) |
|
733 | + $resultObject = ''; |
|
737 | 734 | |
738 | - if($resultMap!==null) |
|
735 | + if ($resultMap !== null) |
|
739 | 736 | $result = $this->fillArrayResultMap($resultMap, $row, $resultObject); |
740 | 737 | else |
741 | 738 | $result = $row; |
742 | 739 | |
743 | 740 | //if scalar result types |
744 | - if(count($result) == 1 && ($type = gettype($resultObject))!= 'array') |
|
741 | + if (count($result) == 1 && ($type = gettype($resultObject)) != 'array') |
|
745 | 742 | return $this->getScalarResult($result, $type); |
746 | 743 | else |
747 | 744 | return $result; |
@@ -757,13 +754,13 @@ discard block |
||
757 | 754 | protected function fillArrayResultMap($resultMap, $row, $resultObject) |
758 | 755 | { |
759 | 756 | $result = array(); |
760 | - $registry=$this->getManager()->getTypeHandlers(); |
|
761 | - foreach($resultMap->getColumns() as $column) |
|
757 | + $registry = $this->getManager()->getTypeHandlers(); |
|
758 | + foreach ($resultMap->getColumns() as $column) |
|
762 | 759 | { |
763 | - if(($column->getType()===null) |
|
764 | - && ($resultObject!==null) && !is_object($resultObject)) |
|
760 | + if (($column->getType() === null) |
|
761 | + && ($resultObject !== null) && !is_object($resultObject)) |
|
765 | 762 | $column->setType(gettype($resultObject)); |
766 | - $result[$column->getProperty()] = $column->getPropertyValue($registry,$row); |
|
763 | + $result[$column->getProperty()] = $column->getPropertyValue($registry, $row); |
|
767 | 764 | } |
768 | 765 | return $result; |
769 | 766 | } |
@@ -793,26 +790,26 @@ discard block |
||
793 | 790 | $select = $property->getSelect(); |
794 | 791 | $key = $property->getProperty(); |
795 | 792 | $nested = $property->getNestedResultMap(); |
796 | - $registry=$this->getManager()->getTypeHandlers(); |
|
797 | - if($key === '') |
|
793 | + $registry = $this->getManager()->getTypeHandlers(); |
|
794 | + if ($key === '') |
|
798 | 795 | { |
799 | - $resultObject = $property->getPropertyValue($registry,$row); |
|
796 | + $resultObject = $property->getPropertyValue($registry, $row); |
|
800 | 797 | } |
801 | - else if(strlen($select) == 0 && ($nested===null)) |
|
798 | + else if (strlen($select) == 0 && ($nested === null)) |
|
802 | 799 | { |
803 | - $value = $property->getPropertyValue($registry,$row); |
|
800 | + $value = $property->getPropertyValue($registry, $row); |
|
804 | 801 | |
805 | 802 | $this->_IsRowDataFound = $this->_IsRowDataFound || ($value != null); |
806 | - if(is_array($resultObject) || is_object($resultObject)) |
|
803 | + if (is_array($resultObject) || is_object($resultObject)) |
|
807 | 804 | TPropertyAccess::set($resultObject, $key, $value); |
808 | 805 | else |
809 | 806 | $resultObject = $value; |
810 | 807 | } |
811 | - else if($nested!==null) |
|
808 | + else if ($nested !== null) |
|
812 | 809 | { |
813 | - if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
|
810 | + if ($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
|
814 | 811 | { |
815 | - if(strlen($resultMap->getGroupBy()) <= 0) |
|
812 | + if (strlen($resultMap->getGroupBy()) <= 0) |
|
816 | 813 | throw new TSqlMapExecutionException( |
817 | 814 | 'sqlmap_non_groupby_array_list_type', $resultMap->getID(), |
818 | 815 | get_class($resultObject), $key); |
@@ -820,7 +817,7 @@ discard block |
||
820 | 817 | else |
821 | 818 | { |
822 | 819 | $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers()); |
823 | - if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
820 | + if ($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
824 | 821 | $obj = null; |
825 | 822 | TPropertyAccess::set($resultObject, $key, $obj); |
826 | 823 | } |
@@ -849,10 +846,10 @@ discard block |
||
849 | 846 | $postSelect->setResultProperty($property); |
850 | 847 | $postSelect->setKeys($key); |
851 | 848 | |
852 | - if($property->instanceOfListType($resultObject)) |
|
849 | + if ($property->instanceOfListType($resultObject)) |
|
853 | 850 | { |
854 | 851 | $values = null; |
855 | - if($property->getLazyLoad()) |
|
852 | + if ($property->getLazyLoad()) |
|
856 | 853 | { |
857 | 854 | $values = TLazyLoadList::newInstance($statement, $key, |
858 | 855 | $resultObject, $property->getProperty()); |
@@ -861,12 +858,12 @@ discard block |
||
861 | 858 | else |
862 | 859 | $postSelect->setMethod(self::QUERY_FOR_LIST); |
863 | 860 | } |
864 | - else if($property->instanceOfArrayType($resultObject)) |
|
861 | + else if ($property->instanceOfArrayType($resultObject)) |
|
865 | 862 | $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
866 | 863 | else |
867 | 864 | $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
868 | 865 | |
869 | - if(!$property->getLazyLoad()) |
|
866 | + if (!$property->getLazyLoad()) |
|
870 | 867 | $this->_selectQueue[] = $postSelect; |
871 | 868 | } |
872 | 869 | |
@@ -877,23 +874,23 @@ discard block |
||
877 | 874 | * @param array current row data. |
878 | 875 | * @return array list of primary key values. |
879 | 876 | */ |
880 | - protected function getPostSelectKeys($resultMap, $property,$row) |
|
877 | + protected function getPostSelectKeys($resultMap, $property, $row) |
|
881 | 878 | { |
882 | 879 | $value = $property->getColumn(); |
883 | - if(is_int(strpos($value.',',0)) || is_int(strpos($value, '=',0))) |
|
880 | + if (is_int(strpos($value . ',', 0)) || is_int(strpos($value, '=', 0))) |
|
884 | 881 | { |
885 | 882 | $keys = array(); |
886 | - foreach(explode(',', $value) as $entry) |
|
883 | + foreach (explode(',', $value) as $entry) |
|
887 | 884 | { |
888 | - $pair =explode('=',$entry); |
|
885 | + $pair = explode('=', $entry); |
|
889 | 886 | $keys[trim($pair[0])] = $row[trim($pair[1])]; |
890 | 887 | } |
891 | 888 | return $keys; |
892 | 889 | } |
893 | 890 | else |
894 | 891 | { |
895 | - $registry=$this->getManager()->getTypeHandlers(); |
|
896 | - return $property->getPropertyValue($registry,$row); |
|
892 | + $registry = $this->getManager()->getTypeHandlers(); |
|
893 | + return $property->getPropertyValue($registry, $row); |
|
897 | 894 | } |
898 | 895 | } |
899 | 896 | |
@@ -907,7 +904,7 @@ discard block |
||
907 | 904 | protected function fillPropertyWithResultMap($resultMap, $row, &$resultObject) |
908 | 905 | { |
909 | 906 | $dataFound = false; |
910 | - foreach($resultMap->getColumns() as $property) |
|
907 | + foreach ($resultMap->getColumns() as $property) |
|
911 | 908 | { |
912 | 909 | $this->_IsRowDataFound = false; |
913 | 910 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
@@ -929,7 +926,7 @@ discard block |
||
929 | 926 | if (!count($this->_selectQueue)) $exprops[] = "\0$cn\0_selectQueue"; |
930 | 927 | if (is_null($this->_groupBy)) $exprops[] = "\0$cn\0_groupBy"; |
931 | 928 | if (!$this->_IsRowDataFound) $exprops[] = "\0$cn\0_IsRowDataFound"; |
932 | - return array_diff(parent::__sleep(),$exprops); |
|
929 | + return array_diff(parent::__sleep(), $exprops); |
|
933 | 930 | } |
934 | 931 | } |
935 | 932 | |
@@ -942,26 +939,26 @@ discard block |
||
942 | 939 | */ |
943 | 940 | class TPostSelectBinding |
944 | 941 | { |
945 | - private $_statement=null; |
|
946 | - private $_property=null; |
|
947 | - private $_resultObject=null; |
|
948 | - private $_keys=null; |
|
949 | - private $_method=TMappedStatement::QUERY_FOR_LIST; |
|
942 | + private $_statement = null; |
|
943 | + private $_property = null; |
|
944 | + private $_resultObject = null; |
|
945 | + private $_keys = null; |
|
946 | + private $_method = TMappedStatement::QUERY_FOR_LIST; |
|
950 | 947 | |
951 | - public function getStatement(){ return $this->_statement; } |
|
952 | - public function setStatement($value){ $this->_statement = $value; } |
|
948 | + public function getStatement() { return $this->_statement; } |
|
949 | + public function setStatement($value) { $this->_statement = $value; } |
|
953 | 950 | |
954 | - public function getResultProperty(){ return $this->_property; } |
|
955 | - public function setResultProperty($value){ $this->_property = $value; } |
|
951 | + public function getResultProperty() { return $this->_property; } |
|
952 | + public function setResultProperty($value) { $this->_property = $value; } |
|
956 | 953 | |
957 | - public function getResultObject(){ return $this->_resultObject; } |
|
958 | - public function setResultObject($value){ $this->_resultObject = $value; } |
|
954 | + public function getResultObject() { return $this->_resultObject; } |
|
955 | + public function setResultObject($value) { $this->_resultObject = $value; } |
|
959 | 956 | |
960 | - public function getKeys(){ return $this->_keys; } |
|
961 | - public function setKeys($value){ $this->_keys = $value; } |
|
957 | + public function getKeys() { return $this->_keys; } |
|
958 | + public function setKeys($value) { $this->_keys = $value; } |
|
962 | 959 | |
963 | - public function getMethod(){ return $this->_method; } |
|
964 | - public function setMethod($value){ $this->_method = $value; } |
|
960 | + public function getMethod() { return $this->_method; } |
|
961 | + public function setMethod($value) { $this->_method = $value; } |
|
965 | 962 | } |
966 | 963 | |
967 | 964 | /** |
@@ -1004,26 +1001,26 @@ discard block |
||
1004 | 1001 | * @param string new node id |
1005 | 1002 | * @param mixed node value |
1006 | 1003 | */ |
1007 | - public function add($parent, $node, $object='') |
|
1004 | + public function add($parent, $node, $object = '') |
|
1008 | 1005 | { |
1009 | - if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null) |
|
1010 | - && isset($this->_entries[$node]) && ($this->_entries[$node]!==null)) |
|
1006 | + if (isset($this->_entries[$parent]) && ($this->_entries[$parent] !== null) |
|
1007 | + && isset($this->_entries[$node]) && ($this->_entries[$node] !== null)) |
|
1011 | 1008 | { |
1012 | 1009 | $this->_entries[$node] = $object; |
1013 | 1010 | return; |
1014 | 1011 | } |
1015 | 1012 | $this->_entries[$node] = $object; |
1016 | - if(empty($parent)) |
|
1013 | + if (empty($parent)) |
|
1017 | 1014 | { |
1018 | - if(isset($this->_entries[$node])) |
|
1015 | + if (isset($this->_entries[$node])) |
|
1019 | 1016 | return; |
1020 | 1017 | $this->_tree[$node] = array(); |
1021 | 1018 | } |
1022 | 1019 | $found = $this->addNode($this->_tree, $parent, $node); |
1023 | - if(!$found && !empty($parent)) |
|
1020 | + if (!$found && !empty($parent)) |
|
1024 | 1021 | { |
1025 | 1022 | $this->_tree[$parent] = array(); |
1026 | - if(!isset($this->_entries[$parent]) || $object !== '') |
|
1023 | + if (!isset($this->_entries[$parent]) || $object !== '') |
|
1027 | 1024 | $this->_entries[$parent] = $object; |
1028 | 1025 | $this->addNode($this->_tree, $parent, $node); |
1029 | 1026 | } |
@@ -1040,11 +1037,11 @@ discard block |
||
1040 | 1037 | { |
1041 | 1038 | $found = false; |
1042 | 1039 | reset($childs); |
1043 | - for($i = 0, $k = count($childs); $i < $k; $i++) |
|
1040 | + for ($i = 0, $k = count($childs); $i < $k; $i++) |
|
1044 | 1041 | { |
1045 | 1042 | $key = key($childs); |
1046 | 1043 | next($childs); |
1047 | - if($key == $parent) |
|
1044 | + if ($key == $parent) |
|
1048 | 1045 | { |
1049 | 1046 | $found = true; |
1050 | 1047 | $childs[$key][$node] = array(); |
@@ -1062,7 +1059,7 @@ discard block |
||
1062 | 1059 | */ |
1063 | 1060 | public function collect() |
1064 | 1061 | { |
1065 | - while(count($this->_tree) > 0) |
|
1062 | + while (count($this->_tree) > 0) |
|
1066 | 1063 | $this->collectChildren(null, $this->_tree); |
1067 | 1064 | return $this->getCollection(); |
1068 | 1065 | } |
@@ -1074,8 +1071,8 @@ discard block |
||
1074 | 1071 | protected function hasChildren(&$nodes) |
1075 | 1072 | { |
1076 | 1073 | $hasChildren = false; |
1077 | - foreach($nodes as $node) |
|
1078 | - if(count($node) != 0) |
|
1074 | + foreach ($nodes as $node) |
|
1075 | + if (count($node) != 0) |
|
1079 | 1076 | return true; |
1080 | 1077 | return $hasChildren; |
1081 | 1078 | } |
@@ -1089,10 +1086,10 @@ discard block |
||
1089 | 1086 | { |
1090 | 1087 | $noChildren = !$this->hasChildren($nodes); |
1091 | 1088 | $childs = array(); |
1092 | - for(reset($nodes); $key = key($nodes);) |
|
1089 | + for (reset($nodes); $key = key($nodes);) |
|
1093 | 1090 | { |
1094 | 1091 | next($nodes); |
1095 | - if($noChildren) |
|
1092 | + if ($noChildren) |
|
1096 | 1093 | { |
1097 | 1094 | $childs[] = $key; |
1098 | 1095 | unset($nodes[$key]); |
@@ -1100,7 +1097,7 @@ discard block |
||
1100 | 1097 | else |
1101 | 1098 | $this->collectChildren($key, $nodes[$key]); |
1102 | 1099 | } |
1103 | - if(count($childs) > 0) |
|
1100 | + if (count($childs) > 0) |
|
1104 | 1101 | $this->onChildNodesVisited($parent, $childs); |
1105 | 1102 | } |
1106 | 1103 | |
@@ -1111,7 +1108,7 @@ discard block |
||
1111 | 1108 | */ |
1112 | 1109 | protected function onChildNodesVisited($parent, $nodes) |
1113 | 1110 | { |
1114 | - if(empty($parent) || empty($this->_entries[$parent])) |
|
1111 | + if (empty($parent) || empty($this->_entries[$parent])) |
|
1115 | 1112 | return; |
1116 | 1113 | |
1117 | 1114 | $parentObject = $this->_entries[$parent]['object']; |
@@ -1119,21 +1116,21 @@ discard block |
||
1119 | 1116 | |
1120 | 1117 | $list = TPropertyAccess::get($parentObject, $property); |
1121 | 1118 | |
1122 | - foreach($nodes as $node) |
|
1119 | + foreach ($nodes as $node) |
|
1123 | 1120 | { |
1124 | - if($list instanceof TList) |
|
1121 | + if ($list instanceof TList) |
|
1125 | 1122 | $parentObject->{$property}[] = $this->_entries[$node]['object']; |
1126 | - else if(is_array($list)) |
|
1123 | + else if (is_array($list)) |
|
1127 | 1124 | $list[] = $this->_entries[$node]['object']; |
1128 | 1125 | else |
1129 | 1126 | throw new TSqlMapExecutionException( |
1130 | 1127 | 'sqlmap_property_must_be_list'); |
1131 | 1128 | } |
1132 | 1129 | |
1133 | - if(is_array($list)) |
|
1130 | + if (is_array($list)) |
|
1134 | 1131 | TPropertyAccess::set($parentObject, $property, $list); |
1135 | 1132 | |
1136 | - if($this->_entries[$parent]['property'] === null) |
|
1133 | + if ($this->_entries[$parent]['property'] === null) |
|
1137 | 1134 | $this->_list[] = $parentObject; |
1138 | 1135 | } |
1139 | 1136 | |
@@ -1151,7 +1148,7 @@ discard block |
||
1151 | 1148 | if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree"; |
1152 | 1149 | if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries"; |
1153 | 1150 | if (!count($this->_list)) $exprops[] = "\0$cn\0_list"; |
1154 | - return array_diff(parent::__sleep(),$exprops); |
|
1151 | + return array_diff(parent::__sleep(), $exprops); |
|
1155 | 1152 | } |
1156 | 1153 | } |
1157 | 1154 |
@@ -237,8 +237,7 @@ discard block |
||
237 | 237 | $param = new TResultSetListItemParameter($obj, $parameter, $list); |
238 | 238 | $this->raiseRowDelegate($delegate, $param); |
239 | 239 | } |
240 | - } |
|
241 | - else |
|
240 | + } else |
|
242 | 241 | { |
243 | 242 | //var_dump($sql,$parameter); |
244 | 243 | foreach($reader as $row) |
@@ -314,8 +313,7 @@ discard block |
||
314 | 313 | $param = new TResultSetMapItemParameter($key, $value, $parameter, $map); |
315 | 314 | $this->raiseRowDelegate($delegate, $param); |
316 | 315 | } |
317 | - } |
|
318 | - else |
|
316 | + } else |
|
319 | 317 | { |
320 | 318 | //while($row = $recordSet->fetchRow()) |
321 | 319 | foreach($reader as $row) |
@@ -341,8 +339,7 @@ discard block |
||
341 | 339 | if(is_string($handler)) |
342 | 340 | { |
343 | 341 | call_user_func($handler,$this,$param); |
344 | - } |
|
345 | - else if(is_callable($handler,true)) |
|
342 | + } else if(is_callable($handler,true)) |
|
346 | 343 | { |
347 | 344 | // an array: 0 - object, 1 - method name/path |
348 | 345 | list($object,$method)=$handler; |
@@ -357,8 +354,7 @@ discard block |
||
357 | 354 | } |
358 | 355 | $object->$method($this,$param); |
359 | 356 | } |
360 | - } |
|
361 | - else |
|
357 | + } else |
|
362 | 358 | throw new TInvalidDataValueException('sqlmap_invalid_delegate', $this->getID(), $handler); |
363 | 359 | } |
364 | 360 | |
@@ -393,8 +389,9 @@ discard block |
||
393 | 389 | { |
394 | 390 | $object = null; |
395 | 391 | $connection->setActive(true); |
396 | - foreach($command->query() as $row) |
|
397 | - $object = $this->applyResultMap($row, $result); |
|
392 | + foreach($command->query() as $row) { |
|
393 | + $object = $this->applyResultMap($row, $result); |
|
394 | + } |
|
398 | 395 | |
399 | 396 | if(!$this->_groupBy->isEmpty()) |
400 | 397 | { |
@@ -520,8 +517,7 @@ discard block |
||
520 | 517 | if($method == self::QUERY_FOR_ARRAY) |
521 | 518 | $values = $values->toArray(); |
522 | 519 | TPropertyAccess::set($resultObject, $property, $values); |
523 | - } |
|
524 | - else if($method == self::QUERY_FOR_OBJECT) |
|
520 | + } else if($method == self::QUERY_FOR_OBJECT) |
|
525 | 521 | { |
526 | 522 | $value = $statement->executeQueryForObject($connection, $keys, null); |
527 | 523 | TPropertyAccess::set($resultObject, $property, $value); |
@@ -596,11 +592,13 @@ discard block |
||
596 | 592 | protected function fillResultArrayList($row, $resultObject) |
597 | 593 | { |
598 | 594 | if($resultObject instanceof TList) |
599 | - foreach($row as $v) |
|
600 | - $resultObject[] = $v; |
|
595 | + foreach($row as $v) { |
|
596 | + $resultObject[] = $v; |
|
597 | + } |
|
601 | 598 | else |
602 | - foreach($row as $k => $v) |
|
603 | - $resultObject[$k] = $v; |
|
599 | + foreach($row as $k => $v) { |
|
600 | + $resultObject[$k] = $v; |
|
601 | + } |
|
604 | 602 | return $resultObject; |
605 | 603 | } |
606 | 604 | |
@@ -649,10 +647,10 @@ discard block |
||
649 | 647 | if(strlen($resultMap->getGroupBy()) > 0) |
650 | 648 | return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
651 | 649 | else |
652 | - foreach($resultMap->getColumns() as $property) |
|
653 | - $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
|
654 | - } |
|
655 | - else |
|
650 | + foreach($resultMap->getColumns() as $property) { |
|
651 | + $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
|
652 | + } |
|
653 | + } else |
|
656 | 654 | { |
657 | 655 | $resultObject = $this->fillDefaultResultMap($resultMap, $row, $resultObject); |
658 | 656 | } |
@@ -797,8 +795,7 @@ discard block |
||
797 | 795 | if($key === '') |
798 | 796 | { |
799 | 797 | $resultObject = $property->getPropertyValue($registry,$row); |
800 | - } |
|
801 | - else if(strlen($select) == 0 && ($nested===null)) |
|
798 | + } else if(strlen($select) == 0 && ($nested===null)) |
|
802 | 799 | { |
803 | 800 | $value = $property->getPropertyValue($registry,$row); |
804 | 801 | |
@@ -807,8 +804,7 @@ discard block |
||
807 | 804 | TPropertyAccess::set($resultObject, $key, $value); |
808 | 805 | else |
809 | 806 | $resultObject = $value; |
810 | - } |
|
811 | - else if($nested!==null) |
|
807 | + } else if($nested!==null) |
|
812 | 808 | { |
813 | 809 | if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
814 | 810 | { |
@@ -816,16 +812,14 @@ discard block |
||
816 | 812 | throw new TSqlMapExecutionException( |
817 | 813 | 'sqlmap_non_groupby_array_list_type', $resultMap->getID(), |
818 | 814 | get_class($resultObject), $key); |
819 | - } |
|
820 | - else |
|
815 | + } else |
|
821 | 816 | { |
822 | 817 | $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers()); |
823 | 818 | if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
824 | 819 | $obj = null; |
825 | 820 | TPropertyAccess::set($resultObject, $key, $obj); |
826 | 821 | } |
827 | - } |
|
828 | - else //'select' ResultProperty |
|
822 | + } else //'select' ResultProperty |
|
829 | 823 | { |
830 | 824 | $this->enquequePostSelect($select, $resultMap, $property, $row, $resultObject); |
831 | 825 | } |
@@ -857,11 +851,9 @@ discard block |
||
857 | 851 | $values = TLazyLoadList::newInstance($statement, $key, |
858 | 852 | $resultObject, $property->getProperty()); |
859 | 853 | TPropertyAccess::set($resultObject, $property->getProperty(), $values); |
860 | - } |
|
861 | - else |
|
854 | + } else |
|
862 | 855 | $postSelect->setMethod(self::QUERY_FOR_LIST); |
863 | - } |
|
864 | - else if($property->instanceOfArrayType($resultObject)) |
|
856 | + } else if($property->instanceOfArrayType($resultObject)) |
|
865 | 857 | $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
866 | 858 | else |
867 | 859 | $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
@@ -889,8 +881,7 @@ discard block |
||
889 | 881 | $keys[trim($pair[0])] = $row[trim($pair[1])]; |
890 | 882 | } |
891 | 883 | return $keys; |
892 | - } |
|
893 | - else |
|
884 | + } else |
|
894 | 885 | { |
895 | 886 | $registry=$this->getManager()->getTypeHandlers(); |
896 | 887 | return $property->getPropertyValue($registry,$row); |
@@ -1048,8 +1039,7 @@ discard block |
||
1048 | 1039 | { |
1049 | 1040 | $found = true; |
1050 | 1041 | $childs[$key][$node] = array(); |
1051 | - } |
|
1052 | - else |
|
1042 | + } else |
|
1053 | 1043 | { |
1054 | 1044 | $found = $found || $this->addNode($childs[$key], $parent, $node); |
1055 | 1045 | } |
@@ -1062,8 +1052,9 @@ discard block |
||
1062 | 1052 | */ |
1063 | 1053 | public function collect() |
1064 | 1054 | { |
1065 | - while(count($this->_tree) > 0) |
|
1066 | - $this->collectChildren(null, $this->_tree); |
|
1055 | + while(count($this->_tree) > 0) { |
|
1056 | + $this->collectChildren(null, $this->_tree); |
|
1057 | + } |
|
1067 | 1058 | return $this->getCollection(); |
1068 | 1059 | } |
1069 | 1060 | |
@@ -1074,9 +1065,10 @@ discard block |
||
1074 | 1065 | protected function hasChildren(&$nodes) |
1075 | 1066 | { |
1076 | 1067 | $hasChildren = false; |
1077 | - foreach($nodes as $node) |
|
1078 | - if(count($node) != 0) |
|
1068 | + foreach($nodes as $node) { |
|
1069 | + if(count($node) != 0) |
|
1079 | 1070 | return true; |
1071 | + } |
|
1080 | 1072 | return $hasChildren; |
1081 | 1073 | } |
1082 | 1074 | |
@@ -1096,8 +1088,7 @@ discard block |
||
1096 | 1088 | { |
1097 | 1089 | $childs[] = $key; |
1098 | 1090 | unset($nodes[$key]); |
1099 | - } |
|
1100 | - else |
|
1091 | + } else |
|
1101 | 1092 | $this->collectChildren($key, $nodes[$key]); |
1102 | 1093 | } |
1103 | 1094 | if(count($childs) > 0) |
@@ -579,7 +579,7 @@ |
||
579 | 579 | $resultObject = $this->_statement->createInstanceOfResultClass($registry,$row); |
580 | 580 | } |
581 | 581 | |
582 | - if($resultObject instanceOf ArrayAccess) |
|
582 | + if($resultObject instanceof ArrayAccess) |
|
583 | 583 | return $this->fillResultArrayList($row, $resultObject); |
584 | 584 | else if(is_object($resultObject)) |
585 | 585 | return $this->fillResultObjectProperty($row, $resultObject); |
@@ -55,6 +55,7 @@ discard block |
||
55 | 55 | * Constructor, create a new SqlMap manager. |
56 | 56 | * @param TDbConnection database connection |
57 | 57 | * @param string configuration file. |
58 | + * @param TDbConnection $connection |
|
58 | 59 | */ |
59 | 60 | public function __construct($connection=null) |
60 | 61 | { |
@@ -68,6 +69,7 @@ discard block |
||
68 | 69 | |
69 | 70 | /** |
70 | 71 | * @param TDbConnection default database connection |
72 | + * @param TComponent $conn |
|
71 | 73 | */ |
72 | 74 | public function setDbConnection($conn) |
73 | 75 | { |
@@ -105,6 +107,7 @@ discard block |
||
105 | 107 | /** |
106 | 108 | * Loads and parses the SqlMap configuration file. |
107 | 109 | * @param string xml configuration file. |
110 | + * @param string $file |
|
108 | 111 | */ |
109 | 112 | public function configureXml($file) |
110 | 113 | { |
@@ -180,6 +183,7 @@ discard block |
||
180 | 183 | /** |
181 | 184 | * Gets a named result map |
182 | 185 | * @param string result name. |
186 | + * @param string $name |
|
183 | 187 | * @return TResultMap the result map. |
184 | 188 | * @throws TSqlMapUndefinedException |
185 | 189 | */ |
@@ -212,6 +216,7 @@ discard block |
||
212 | 216 | |
213 | 217 | /** |
214 | 218 | * @param string parameter map ID name. |
219 | + * @param string $name |
|
215 | 220 | * @return TParameterMap the parameter with given ID. |
216 | 221 | * @throws TSqlMapUndefinedException |
217 | 222 | */ |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | * @param TDbConnection database connection |
57 | 57 | * @param string configuration file. |
58 | 58 | */ |
59 | - public function __construct($connection=null) |
|
59 | + public function __construct($connection = null) |
|
60 | 60 | { |
61 | - $this->_connection=$connection; |
|
61 | + $this->_connection = $connection; |
|
62 | 62 | |
63 | - $this->_mappedStatements=new TMap; |
|
64 | - $this->_resultMaps=new TMap; |
|
65 | - $this->_parameterMaps=new TMap; |
|
66 | - $this->_cacheModels=new TMap; |
|
63 | + $this->_mappedStatements = new TMap; |
|
64 | + $this->_resultMaps = new TMap; |
|
65 | + $this->_parameterMaps = new TMap; |
|
66 | + $this->_cacheModels = new TMap; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function setDbConnection($conn) |
73 | 73 | { |
74 | - $this->_connection=$conn; |
|
74 | + $this->_connection = $conn; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function getTypeHandlers() |
89 | 89 | { |
90 | - if($this->_typeHandlers===null) |
|
91 | - $this->_typeHandlers= new TSqlMapTypeHandlerRegistry(); |
|
90 | + if ($this->_typeHandlers === null) |
|
91 | + $this->_typeHandlers = new TSqlMapTypeHandlerRegistry(); |
|
92 | 92 | return $this->_typeHandlers; |
93 | 93 | } |
94 | 94 | |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function getSqlmapGateway() |
99 | 99 | { |
100 | - if($this->_gateway===null) |
|
101 | - $this->_gateway=$this->createSqlMapGateway(); |
|
100 | + if ($this->_gateway === null) |
|
101 | + $this->_gateway = $this->createSqlMapGateway(); |
|
102 | 102 | return $this->_gateway; |
103 | 103 | } |
104 | 104 | |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function getCacheDependencies() |
120 | 120 | { |
121 | - if($this->_cacheDependencies === null) |
|
122 | - $this->_cacheDependencies=new TChainedCacheDependency(); |
|
121 | + if ($this->_cacheDependencies === null) |
|
122 | + $this->_cacheDependencies = new TChainedCacheDependency(); |
|
123 | 123 | |
124 | 124 | return $this->_cacheDependencies; |
125 | 125 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function getMappedStatement($name) |
152 | 152 | { |
153 | - if($this->_mappedStatements->contains($name) == false) |
|
153 | + if ($this->_mappedStatements->contains($name) == false) |
|
154 | 154 | throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name); |
155 | 155 | return $this->_mappedStatements[$name]; |
156 | 156 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | public function addMappedStatement(IMappedStatement $statement) |
165 | 165 | { |
166 | 166 | $key = $statement->getID(); |
167 | - if($this->_mappedStatements->contains($key) == true) |
|
167 | + if ($this->_mappedStatements->contains($key) == true) |
|
168 | 168 | throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key); |
169 | 169 | $this->_mappedStatements->add($key, $statement); |
170 | 170 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function getResultMap($name) |
187 | 187 | { |
188 | - if($this->_resultMaps->contains($name) == false) |
|
188 | + if ($this->_resultMaps->contains($name) == false) |
|
189 | 189 | throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name); |
190 | 190 | return $this->_resultMaps[$name]; |
191 | 191 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | public function addResultMap(TResultMap $result) |
198 | 198 | { |
199 | 199 | $key = $result->getID(); |
200 | - if($this->_resultMaps->contains($key) == true) |
|
200 | + if ($this->_resultMaps->contains($key) == true) |
|
201 | 201 | throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key); |
202 | 202 | $this->_resultMaps->add($key, $result); |
203 | 203 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function getParameterMap($name) |
219 | 219 | { |
220 | - if($this->_parameterMaps->contains($name) == false) |
|
220 | + if ($this->_parameterMaps->contains($name) == false) |
|
221 | 221 | throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name); |
222 | 222 | return $this->_parameterMaps[$name]; |
223 | 223 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | public function addParameterMap(TParameterMap $parameter) |
230 | 230 | { |
231 | 231 | $key = $parameter->getID(); |
232 | - if($this->_parameterMaps->contains($key) == true) |
|
232 | + if ($this->_parameterMaps->contains($key) == true) |
|
233 | 233 | throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key); |
234 | 234 | $this->_parameterMaps->add($key, $parameter); |
235 | 235 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function addCacheModel(TSqlMapCacheModel $cacheModel) |
243 | 243 | { |
244 | - if($this->_cacheModels->contains($cacheModel->getID())) |
|
244 | + if ($this->_cacheModels->contains($cacheModel->getID())) |
|
245 | 245 | throw new TSqlMapConfigurationException('sqlmap_cache_model_already_exists', $cacheModel->getID()); |
246 | 246 | else |
247 | 247 | $this->_cacheModels->add($cacheModel->getID(), $cacheModel); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | */ |
256 | 256 | public function getCacheModel($name) |
257 | 257 | { |
258 | - if(!$this->_cacheModels->contains($name)) |
|
258 | + if (!$this->_cacheModels->contains($name)) |
|
259 | 259 | throw new TSqlMapConfigurationException('sqlmap_unable_to_find_cache_model', $name); |
260 | 260 | return $this->_cacheModels[$name]; |
261 | 261 | } |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function flushCacheModels() |
267 | 267 | { |
268 | - foreach($this->_cacheModels as $cache) |
|
268 | + foreach ($this->_cacheModels as $cache) |
|
269 | 269 | $cache->flush(); |
270 | 270 | } |
271 | 271 | } |
@@ -265,8 +265,9 @@ |
||
265 | 265 | */ |
266 | 266 | public function flushCacheModels() |
267 | 267 | { |
268 | - foreach($this->_cacheModels as $cache) |
|
269 | - $cache->flush(); |
|
268 | + foreach($this->_cacheModels as $cache) { |
|
269 | + $cache->flush(); |
|
270 | + } |
|
270 | 271 | } |
271 | 272 | } |
272 | 273 |
@@ -136,6 +136,7 @@ |
||
136 | 136 | * @param mixed Name of the PHP variable to bind to the SQL statement parameter |
137 | 137 | * @param int SQL data type of the parameter |
138 | 138 | * @param int length of the data type |
139 | + * @param string $name |
|
139 | 140 | * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php |
140 | 141 | */ |
141 | 142 | public function bindParameter($name, &$value, $dataType=null, $length=null) |
@@ -109,8 +109,7 @@ discard block |
||
109 | 109 | try |
110 | 110 | { |
111 | 111 | $this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText()); |
112 | - } |
|
113 | - catch(Exception $e) |
|
112 | + } catch(Exception $e) |
|
114 | 113 | { |
115 | 114 | throw new TDbException('dbcommand_prepare_failed',$e->getMessage(),$this->getText()); |
116 | 115 | } |
@@ -186,11 +185,9 @@ discard block |
||
186 | 185 | { |
187 | 186 | $this->_statement->execute(); |
188 | 187 | return $this->_statement->rowCount(); |
189 | - } |
|
190 | - else |
|
188 | + } else |
|
191 | 189 | return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
192 | - } |
|
193 | - catch(Exception $e) |
|
190 | + } catch(Exception $e) |
|
194 | 191 | { |
195 | 192 | throw new TDbException('dbcommand_execute_failed',$e->getMessage(),$this->getDebugStatementText()); |
196 | 193 | } |
@@ -223,8 +220,7 @@ discard block |
||
223 | 220 | else |
224 | 221 | $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
225 | 222 | return new TDbDataReader($this); |
226 | - } |
|
227 | - catch(Exception $e) |
|
223 | + } catch(Exception $e) |
|
228 | 224 | { |
229 | 225 | throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
230 | 226 | } |
@@ -250,8 +246,7 @@ discard block |
||
250 | 246 | $result=$this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
251 | 247 | $this->_statement->closeCursor(); |
252 | 248 | return $result; |
253 | - } |
|
254 | - catch(Exception $e) |
|
249 | + } catch(Exception $e) |
|
255 | 250 | { |
256 | 251 | throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
257 | 252 | } |
@@ -279,8 +274,7 @@ discard block |
||
279 | 274 | return stream_get_contents($result); |
280 | 275 | else |
281 | 276 | return $result; |
282 | - } |
|
283 | - catch(Exception $e) |
|
277 | + } catch(Exception $e) |
|
284 | 278 | { |
285 | 279 | throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
286 | 280 | } |
@@ -298,8 +292,9 @@ discard block |
||
298 | 292 | { |
299 | 293 | $rows=$this->query()->readAll(); |
300 | 294 | $column=array(); |
301 | - foreach($rows as $row) |
|
302 | - $column[]=current($row); |
|
295 | + foreach($rows as $row) { |
|
296 | + $column[]=current($row); |
|
297 | + } |
|
303 | 298 | return $column; |
304 | 299 | } |
305 | 300 | } |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | class TDbCommand extends TComponent |
38 | 38 | { |
39 | 39 | private $_connection; |
40 | - private $_text=''; |
|
41 | - private $_statement=null; |
|
40 | + private $_text = ''; |
|
41 | + private $_statement = null; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Constructor. |
45 | 45 | * @param TDbConnection the database connection |
46 | 46 | * @param string the SQL statement to be executed |
47 | 47 | */ |
48 | - public function __construct(TDbConnection $connection,$text) |
|
48 | + public function __construct(TDbConnection $connection, $text) |
|
49 | 49 | { |
50 | - $this->_connection=$connection; |
|
50 | + $this->_connection = $connection; |
|
51 | 51 | $this->setText($text); |
52 | 52 | } |
53 | 53 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function __sleep() |
58 | 58 | { |
59 | - return array_diff(parent::__sleep(),array("\0TDbCommand\0_statement")); |
|
59 | + return array_diff(parent::__sleep(), array("\0TDbCommand\0_statement")); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function setText($value) |
76 | 76 | { |
77 | - $this->_text=$value; |
|
77 | + $this->_text = $value; |
|
78 | 78 | $this->cancel(); |
79 | 79 | } |
80 | 80 | |
@@ -104,15 +104,15 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function prepare() |
106 | 106 | { |
107 | - if($this->_statement==null) |
|
107 | + if ($this->_statement == null) |
|
108 | 108 | { |
109 | 109 | try |
110 | 110 | { |
111 | - $this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText()); |
|
111 | + $this->_statement = $this->getConnection()->getPdoInstance()->prepare($this->getText()); |
|
112 | 112 | } |
113 | - catch(Exception $e) |
|
113 | + catch (Exception $e) |
|
114 | 114 | { |
115 | - throw new TDbException('dbcommand_prepare_failed',$e->getMessage(),$this->getText()); |
|
115 | + throw new TDbException('dbcommand_prepare_failed', $e->getMessage(), $this->getText()); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function cancel() |
124 | 124 | { |
125 | - $this->_statement=null; |
|
125 | + $this->_statement = null; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | * @param int length of the data type |
139 | 139 | * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php |
140 | 140 | */ |
141 | - public function bindParameter($name, &$value, $dataType=null, $length=null) |
|
141 | + public function bindParameter($name, &$value, $dataType = null, $length = null) |
|
142 | 142 | { |
143 | 143 | $this->prepare(); |
144 | - if($dataType===null) |
|
145 | - $this->_statement->bindParam($name,$value); |
|
146 | - else if($length===null) |
|
147 | - $this->_statement->bindParam($name,$value,$dataType); |
|
144 | + if ($dataType === null) |
|
145 | + $this->_statement->bindParam($name, $value); |
|
146 | + else if ($length === null) |
|
147 | + $this->_statement->bindParam($name, $value, $dataType); |
|
148 | 148 | else |
149 | - $this->_statement->bindParam($name,$value,$dataType,$length); |
|
149 | + $this->_statement->bindParam($name, $value, $dataType, $length); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -159,13 +159,13 @@ discard block |
||
159 | 159 | * @param int SQL data type of the parameter |
160 | 160 | * @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php |
161 | 161 | */ |
162 | - public function bindValue($name, $value, $dataType=null) |
|
162 | + public function bindValue($name, $value, $dataType = null) |
|
163 | 163 | { |
164 | 164 | $this->prepare(); |
165 | - if($dataType===null) |
|
166 | - $this->_statement->bindValue($name,$value); |
|
165 | + if ($dataType === null) |
|
166 | + $this->_statement->bindValue($name, $value); |
|
167 | 167 | else |
168 | - $this->_statement->bindValue($name,$value,$dataType); |
|
168 | + $this->_statement->bindValue($name, $value, $dataType); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | // Do not trace because it will remain even in |
183 | 183 | // Performance mode or when pradolite.php is used |
184 | 184 | // Prado::trace('Execute Command: '.$this->getDebugStatementText(), 'System.Data'); |
185 | - if($this->_statement instanceof PDOStatement) |
|
185 | + if ($this->_statement instanceof PDOStatement) |
|
186 | 186 | { |
187 | 187 | $this->_statement->execute(); |
188 | 188 | return $this->_statement->rowCount(); |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | else |
191 | 191 | return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
192 | 192 | } |
193 | - catch(Exception $e) |
|
193 | + catch (Exception $e) |
|
194 | 194 | { |
195 | - throw new TDbException('dbcommand_execute_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
195 | + throw new TDbException('dbcommand_execute_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
@@ -218,15 +218,15 @@ discard block |
||
218 | 218 | try |
219 | 219 | { |
220 | 220 | // Prado::trace('Query: '.$this->getDebugStatementText(), 'System.Data'); |
221 | - if($this->_statement instanceof PDOStatement) |
|
221 | + if ($this->_statement instanceof PDOStatement) |
|
222 | 222 | $this->_statement->execute(); |
223 | 223 | else |
224 | - $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
224 | + $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
225 | 225 | return new TDbDataReader($this); |
226 | 226 | } |
227 | - catch(Exception $e) |
|
227 | + catch (Exception $e) |
|
228 | 228 | { |
229 | - throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
229 | + throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 | |
@@ -238,22 +238,22 @@ discard block |
||
238 | 238 | * @return array the first row of the query result, false if no result. |
239 | 239 | * @throws TDbException execution failed |
240 | 240 | */ |
241 | - public function queryRow($fetchAssociative=true) |
|
241 | + public function queryRow($fetchAssociative = true) |
|
242 | 242 | { |
243 | 243 | try |
244 | 244 | { |
245 | 245 | // Prado::trace('Query Row: '.$this->getDebugStatementText(), 'System.Data'); |
246 | - if($this->_statement instanceof PDOStatement) |
|
246 | + if ($this->_statement instanceof PDOStatement) |
|
247 | 247 | $this->_statement->execute(); |
248 | 248 | else |
249 | - $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
250 | - $result=$this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
|
249 | + $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
250 | + $result = $this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
|
251 | 251 | $this->_statement->closeCursor(); |
252 | 252 | return $result; |
253 | 253 | } |
254 | - catch(Exception $e) |
|
254 | + catch (Exception $e) |
|
255 | 255 | { |
256 | - throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
256 | + throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
@@ -269,20 +269,20 @@ discard block |
||
269 | 269 | try |
270 | 270 | { |
271 | 271 | // Prado::trace('Query Scalar: '.$this->getDebugStatementText(), 'System.Data'); |
272 | - if($this->_statement instanceof PDOStatement) |
|
272 | + if ($this->_statement instanceof PDOStatement) |
|
273 | 273 | $this->_statement->execute(); |
274 | 274 | else |
275 | - $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
276 | - $result=$this->_statement->fetchColumn(); |
|
275 | + $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
276 | + $result = $this->_statement->fetchColumn(); |
|
277 | 277 | $this->_statement->closeCursor(); |
278 | - if(is_resource($result) && get_resource_type($result)==='stream') |
|
278 | + if (is_resource($result) && get_resource_type($result) === 'stream') |
|
279 | 279 | return stream_get_contents($result); |
280 | 280 | else |
281 | 281 | return $result; |
282 | 282 | } |
283 | - catch(Exception $e) |
|
283 | + catch (Exception $e) |
|
284 | 284 | { |
285 | - throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
285 | + throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public function queryColumn() |
298 | 298 | { |
299 | - $rows=$this->query()->readAll(); |
|
300 | - $column=array(); |
|
301 | - foreach($rows as $row) |
|
302 | - $column[]=current($row); |
|
299 | + $rows = $this->query()->readAll(); |
|
300 | + $column = array(); |
|
301 | + foreach ($rows as $row) |
|
302 | + $column[] = current($row); |
|
303 | 303 | return $column; |
304 | 304 | } |
305 | 305 | } |
@@ -157,6 +157,7 @@ discard block |
||
157 | 157 | /** |
158 | 158 | * Open or close the DB connection. |
159 | 159 | * @param boolean whether to open or close DB connection |
160 | + * @param boolean $value |
|
160 | 161 | * @throws TDbException if connection fails |
161 | 162 | */ |
162 | 163 | public function setActive($value) |
@@ -241,6 +242,7 @@ discard block |
||
241 | 242 | |
242 | 243 | /** |
243 | 244 | * @param string The Data Source Name, or DSN, contains the information required to connect to the database. |
245 | + * @param string $value |
|
244 | 246 | * @see http://www.php.net/manual/en/function.PDO-construct.php |
245 | 247 | */ |
246 | 248 | public function setConnectionString($value) |
@@ -258,6 +260,7 @@ discard block |
||
258 | 260 | |
259 | 261 | /** |
260 | 262 | * @param string the username for establishing DB connection |
263 | + * @param string $value |
|
261 | 264 | */ |
262 | 265 | public function setUsername($value) |
263 | 266 | { |
@@ -274,6 +277,7 @@ discard block |
||
274 | 277 | |
275 | 278 | /** |
276 | 279 | * @param string the password for establishing DB connection |
280 | + * @param string $value |
|
277 | 281 | */ |
278 | 282 | public function setPassword($value) |
279 | 283 | { |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | */ |
88 | 88 | const DEFAULT_TRANSACTION_CLASS = 'System.Data.TDbTransaction'; |
89 | 89 | |
90 | - private $_dsn=''; |
|
91 | - private $_username=''; |
|
92 | - private $_password=''; |
|
93 | - private $_charset=''; |
|
94 | - private $_attributes=array(); |
|
95 | - private $_active=false; |
|
96 | - private $_pdo=null; |
|
90 | + private $_dsn = ''; |
|
91 | + private $_username = ''; |
|
92 | + private $_password = ''; |
|
93 | + private $_charset = ''; |
|
94 | + private $_attributes = array(); |
|
95 | + private $_active = false; |
|
96 | + private $_pdo = null; |
|
97 | 97 | private $_transaction; |
98 | 98 | |
99 | 99 | /** |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @var string |
106 | 106 | * @since 3.1.7 |
107 | 107 | */ |
108 | - private $_transactionClass=self::DEFAULT_TRANSACTION_CLASS; |
|
108 | + private $_transactionClass = self::DEFAULT_TRANSACTION_CLASS; |
|
109 | 109 | |
110 | 110 | /** |
111 | 111 | * Constructor. |
@@ -120,12 +120,12 @@ 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 | - $this->_dsn=$dsn; |
|
126 | - $this->_username=$username; |
|
127 | - $this->_password=$password; |
|
128 | - $this->_charset=$charset; |
|
125 | + $this->_dsn = $dsn; |
|
126 | + $this->_username = $username; |
|
127 | + $this->_password = $password; |
|
128 | + $this->_charset = $charset; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -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 | /** |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function setActive($value) |
163 | 163 | { |
164 | - $value=TPropertyValue::ensureBoolean($value); |
|
165 | - if($value!==$this->_active) |
|
164 | + $value = TPropertyValue::ensureBoolean($value); |
|
165 | + if ($value !== $this->_active) |
|
166 | 166 | { |
167 | - if($value) |
|
167 | + if ($value) |
|
168 | 168 | $this->open(); |
169 | 169 | else |
170 | 170 | $this->close(); |
@@ -177,22 +177,22 @@ discard block |
||
177 | 177 | */ |
178 | 178 | protected function open() |
179 | 179 | { |
180 | - if($this->_pdo===null) |
|
180 | + if ($this->_pdo === null) |
|
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); |
189 | 189 | $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
190 | - $this->_active=true; |
|
190 | + $this->_active = true; |
|
191 | 191 | $this->setConnectionCharset(); |
192 | 192 | } |
193 | - catch(PDOException $e) |
|
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 | } |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | */ |
204 | 204 | protected function close() |
205 | 205 | { |
206 | - $this->_pdo=null; |
|
207 | - $this->_active=false; |
|
206 | + $this->_pdo = null; |
|
207 | + $this->_active = false; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /* |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | public function setConnectionString($value) |
247 | 247 | { |
248 | - $this->_dsn=$value; |
|
248 | + $this->_dsn = $value; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function setUsername($value) |
263 | 263 | { |
264 | - $this->_username=$value; |
|
264 | + $this->_username = $value; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -277,13 +277,13 @@ discard block |
||
277 | 277 | */ |
278 | 278 | public function setPassword($value) |
279 | 279 | { |
280 | - $this->_password=$value; |
|
280 | + $this->_password = $value; |
|
281 | 281 | } |
282 | 282 | |
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,9 +291,9 @@ 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 | - $this->_charset=$value; |
|
296 | + $this->_charset = $value; |
|
297 | 297 | $this->setConnectionCharset(); |
298 | 298 | } |
299 | 299 | |
@@ -313,8 +313,8 @@ discard block |
||
313 | 313 | */ |
314 | 314 | public function createCommand($sql) |
315 | 315 | { |
316 | - if($this->getActive()) |
|
317 | - return new TDbCommand($this,$sql); |
|
316 | + if ($this->getActive()) |
|
317 | + return new TDbCommand($this, $sql); |
|
318 | 318 | else |
319 | 319 | throw new TDbException('dbconnection_connection_inactive'); |
320 | 320 | } |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | */ |
325 | 325 | public function getCurrentTransaction() |
326 | 326 | { |
327 | - if($this->_transaction!==null) |
|
327 | + if ($this->_transaction !== null) |
|
328 | 328 | { |
329 | - if($this->_transaction->getActive()) |
|
329 | + if ($this->_transaction->getActive()) |
|
330 | 330 | return $this->_transaction; |
331 | 331 | } |
332 | 332 | return null; |
@@ -339,10 +339,10 @@ discard block |
||
339 | 339 | */ |
340 | 340 | public function beginTransaction() |
341 | 341 | { |
342 | - if($this->getActive()) |
|
342 | + if ($this->getActive()) |
|
343 | 343 | { |
344 | 344 | $this->_pdo->beginTransaction(); |
345 | - return $this->_transaction=Prado::createComponent($this->getTransactionClass(), $this); |
|
345 | + return $this->_transaction = Prado::createComponent($this->getTransactionClass(), $this); |
|
346 | 346 | } |
347 | 347 | else |
348 | 348 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -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 | /** |
@@ -373,9 +373,9 @@ discard block |
||
373 | 373 | * @return string the row ID of the last row inserted, or the last value retrieved from the sequence object |
374 | 374 | * @see http://www.php.net/manual/en/function.PDO-lastInsertId.php |
375 | 375 | */ |
376 | - public function getLastInsertID($sequenceName='') |
|
376 | + public function getLastInsertID($sequenceName = '') |
|
377 | 377 | { |
378 | - if($this->getActive()) |
|
378 | + if ($this->getActive()) |
|
379 | 379 | return $this->_pdo->lastInsertId($sequenceName); |
380 | 380 | else |
381 | 381 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | */ |
390 | 390 | public function quoteString($str) |
391 | 391 | { |
392 | - if($this->getActive()) |
|
392 | + if ($this->getActive()) |
|
393 | 393 | return $this->_pdo->quote($str); |
394 | 394 | else |
395 | 395 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | */ |
431 | 431 | public function getDbMetaData() |
432 | 432 | { |
433 | - if($this->_dbMeta===null) |
|
433 | + if ($this->_dbMeta === null) |
|
434 | 434 | { |
435 | 435 | Prado::using('System.Data.Common.TDbMetaData'); |
436 | 436 | $this->_dbMeta = TDbMetaData::getInstance($this); |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | */ |
444 | 444 | public function getColumnCase() |
445 | 445 | { |
446 | - switch($this->getAttribute(PDO::ATTR_CASE)) |
|
446 | + switch ($this->getAttribute(PDO::ATTR_CASE)) |
|
447 | 447 | { |
448 | 448 | case PDO::CASE_NATURAL: |
449 | 449 | return TDbColumnCaseMode::Preserved; |
@@ -459,19 +459,19 @@ 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 | - $value=PDO::CASE_NATURAL; |
|
465 | + $value = PDO::CASE_NATURAL; |
|
466 | 466 | break; |
467 | 467 | case TDbColumnCaseMode::LowerCase: |
468 | - $value=PDO::CASE_LOWER; |
|
468 | + $value = PDO::CASE_LOWER; |
|
469 | 469 | break; |
470 | 470 | case TDbColumnCaseMode::UpperCase: |
471 | - $value=PDO::CASE_UPPER; |
|
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 | /** |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | */ |
480 | 480 | public function getNullConversion() |
481 | 481 | { |
482 | - switch($this->getAttribute(PDO::ATTR_ORACLE_NULLS)) |
|
482 | + switch ($this->getAttribute(PDO::ATTR_ORACLE_NULLS)) |
|
483 | 483 | { |
484 | 484 | case PDO::NULL_NATURAL: |
485 | 485 | return TDbNullConversionMode::Preserved; |
@@ -495,19 +495,19 @@ 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 | - $value=PDO::NULL_NATURAL; |
|
501 | + $value = PDO::NULL_NATURAL; |
|
502 | 502 | break; |
503 | 503 | case TDbNullConversionMode::EmptyStringToNull: |
504 | - $value=PDO::NULL_EMPTY_STRING; |
|
504 | + $value = PDO::NULL_EMPTY_STRING; |
|
505 | 505 | break; |
506 | 506 | case TDbNullConversionMode::NullToEmptyString: |
507 | - $value=PDO::NULL_TO_STRING; |
|
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 | /** |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | */ |
612 | 612 | public function getAttribute($name) |
613 | 613 | { |
614 | - if($this->getActive()) |
|
614 | + if ($this->getActive()) |
|
615 | 615 | return $this->_pdo->getAttribute($name); |
616 | 616 | else |
617 | 617 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -623,12 +623,12 @@ 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 | - if($this->_pdo instanceof PDO) |
|
629 | - $this->_pdo->setAttribute($name,$value); |
|
628 | + if ($this->_pdo instanceof PDO) |
|
629 | + $this->_pdo->setAttribute($name, $value); |
|
630 | 630 | else |
631 | - $this->_attributes[$name]=$value; |
|
631 | + $this->_attributes[$name] = $value; |
|
632 | 632 | } |
633 | 633 | } |
634 | 634 | |
@@ -644,15 +644,15 @@ discard block |
||
644 | 644 | /** |
645 | 645 | * Column name cases are kept as is from the database |
646 | 646 | */ |
647 | - const Preserved='Preserved'; |
|
647 | + const Preserved = 'Preserved'; |
|
648 | 648 | /** |
649 | 649 | * Column names are converted to lower case |
650 | 650 | */ |
651 | - const LowerCase='LowerCase'; |
|
651 | + const LowerCase = 'LowerCase'; |
|
652 | 652 | /** |
653 | 653 | * Column names are converted to upper case |
654 | 654 | */ |
655 | - const UpperCase='UpperCase'; |
|
655 | + const UpperCase = 'UpperCase'; |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -667,14 +667,14 @@ discard block |
||
667 | 667 | /** |
668 | 668 | * No conversion is performed for null and empty values. |
669 | 669 | */ |
670 | - const Preserved='Preserved'; |
|
670 | + const Preserved = 'Preserved'; |
|
671 | 671 | /** |
672 | 672 | * NULL is converted to empty string |
673 | 673 | */ |
674 | - const NullToEmptyString='NullToEmptyString'; |
|
674 | + const NullToEmptyString = 'NullToEmptyString'; |
|
675 | 675 | /** |
676 | 676 | * Empty string is converted to NULL |
677 | 677 | */ |
678 | - const EmptyStringToNull='EmptyStringToNull'; |
|
678 | + const EmptyStringToNull = 'EmptyStringToNull'; |
|
679 | 679 | } |
680 | 680 |
@@ -189,8 +189,7 @@ discard block |
||
189 | 189 | $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
190 | 190 | $this->_active=true; |
191 | 191 | $this->setConnectionCharset(); |
192 | - } |
|
193 | - catch(PDOException $e) |
|
192 | + } catch(PDOException $e) |
|
194 | 193 | { |
195 | 194 | throw new TDbException('dbconnection_open_failed',$e->getMessage()); |
196 | 195 | } |
@@ -343,8 +342,7 @@ discard block |
||
343 | 342 | { |
344 | 343 | $this->_pdo->beginTransaction(); |
345 | 344 | return $this->_transaction=Prado::createComponent($this->getTransactionClass(), $this); |
346 | - } |
|
347 | - else |
|
345 | + } else |
|
348 | 346 | throw new TDbException('dbconnection_connection_inactive'); |
349 | 347 | } |
350 | 348 |
@@ -109,6 +109,7 @@ discard block |
||
109 | 109 | * It terminates the application immediately after the error is displayed. |
110 | 110 | * @param mixed sender of the event |
111 | 111 | * @param mixed event parameter (if the event is raised by TApplication, it refers to the exception instance) |
112 | + * @param null|TApplication $sender |
|
112 | 113 | */ |
113 | 114 | public function handleError($sender,$param) |
114 | 115 | { |
@@ -363,6 +364,9 @@ discard block |
||
363 | 364 | return $result; |
364 | 365 | } |
365 | 366 | |
367 | + /** |
|
368 | + * @param string $pattern |
|
369 | + */ |
|
366 | 370 | private function getPropertyAccessTrace($trace,$pattern) |
367 | 371 | { |
368 | 372 | $result=null; |
@@ -395,6 +399,9 @@ discard block |
||
395 | 399 | return $source; |
396 | 400 | } |
397 | 401 | |
402 | + /** |
|
403 | + * @param string $message |
|
404 | + */ |
|
398 | 405 | private function addLink($message) |
399 | 406 | { |
400 | 407 | $baseUrl='http://pradosoft.github.io/docs/manual/class-'; |
@@ -219,8 +219,7 @@ discard block |
||
219 | 219 | echo "<body><h1>Recursive Error</h1>\n"; |
220 | 220 | echo "<pre>".$exception->__toString()."</pre>\n"; |
221 | 221 | echo "</body></html>"; |
222 | - } |
|
223 | - else |
|
222 | + } else |
|
224 | 223 | { |
225 | 224 | error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
226 | 225 | header('HTTP/1.0 500 Internal Error'); |
@@ -251,15 +250,13 @@ discard block |
||
251 | 250 | if($fileName==='') |
252 | 251 | $fileName='---embedded template---'; |
253 | 252 | $errorLine=$exception->getLineNumber(); |
254 | - } |
|
255 | - else |
|
253 | + } else |
|
256 | 254 | { |
257 | 255 | if(($trace=$this->getExactTrace($exception))!==null) |
258 | 256 | { |
259 | 257 | $fileName=$trace['file']; |
260 | 258 | $errorLine=$trace['line']; |
261 | - } |
|
262 | - else |
|
259 | + } else |
|
263 | 260 | { |
264 | 261 | $fileName=$exception->getFile(); |
265 | 262 | $errorLine=$exception->getLine(); |
@@ -350,8 +347,7 @@ discard block |
||
350 | 347 | $result=$trace[0]; |
351 | 348 | elseif(isset($trace[1])) |
352 | 349 | $result=$trace[1]; |
353 | - } |
|
354 | - else if($exception instanceof TInvalidOperationException) |
|
350 | + } else if($exception instanceof TInvalidOperationException) |
|
355 | 351 | { |
356 | 352 | // in case of getter or setter error, find out the exact file and row |
357 | 353 | if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null) |
@@ -388,8 +384,7 @@ discard block |
||
388 | 384 | { |
389 | 385 | $line=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
390 | 386 | $source.="<div class=\"error\">".$line."</div>"; |
391 | - } |
|
392 | - else |
|
387 | + } else |
|
393 | 388 | $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
394 | 389 | } |
395 | 390 | return $source; |
@@ -52,20 +52,20 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * error template file basename |
54 | 54 | */ |
55 | - const ERROR_FILE_NAME='error'; |
|
55 | + const ERROR_FILE_NAME = 'error'; |
|
56 | 56 | /** |
57 | 57 | * exception template file basename |
58 | 58 | */ |
59 | - const EXCEPTION_FILE_NAME='exception'; |
|
59 | + const EXCEPTION_FILE_NAME = 'exception'; |
|
60 | 60 | /** |
61 | 61 | * number of lines before and after the error line to be displayed in case of an exception |
62 | 62 | */ |
63 | - const SOURCE_LINES=12; |
|
63 | + const SOURCE_LINES = 12; |
|
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @var string error template directory |
67 | 67 | */ |
68 | - private $_templatePath=null; |
|
68 | + private $_templatePath = null; |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Initializes the module. |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function getErrorTemplatePath() |
84 | 84 | { |
85 | - if($this->_templatePath===null) |
|
86 | - $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates'; |
|
85 | + if ($this->_templatePath === null) |
|
86 | + $this->_templatePath = Prado::getFrameworkPath() . '/Exceptions/templates'; |
|
87 | 87 | return $this->_templatePath; |
88 | 88 | } |
89 | 89 | |
@@ -95,10 +95,10 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function setErrorTemplatePath($value) |
97 | 97 | { |
98 | - if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath)) |
|
99 | - $this->_templatePath=$templatePath; |
|
98 | + if (($templatePath = Prado::getPathOfNamespace($value)) !== null && is_dir($templatePath)) |
|
99 | + $this->_templatePath = $templatePath; |
|
100 | 100 | else |
101 | - throw new TConfigurationException('errorhandler_errortemplatepath_invalid',$value); |
|
101 | + throw new TConfigurationException('errorhandler_errortemplatepath_invalid', $value); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -110,30 +110,30 @@ discard block |
||
110 | 110 | * @param mixed sender of the event |
111 | 111 | * @param mixed event parameter (if the event is raised by TApplication, it refers to the exception instance) |
112 | 112 | */ |
113 | - public function handleError($sender,$param) |
|
113 | + public function handleError($sender, $param) |
|
114 | 114 | { |
115 | - static $handling=false; |
|
115 | + static $handling = false; |
|
116 | 116 | // We need to restore error and exception handlers, |
117 | 117 | // because within error and exception handlers, new errors and exceptions |
118 | 118 | // cannot be handled properly by PHP |
119 | 119 | restore_error_handler(); |
120 | 120 | restore_exception_handler(); |
121 | 121 | // ensure that we do not enter infinite loop of error handling |
122 | - if($handling) |
|
122 | + if ($handling) |
|
123 | 123 | $this->handleRecursiveError($param); |
124 | 124 | else |
125 | 125 | { |
126 | - $handling=true; |
|
127 | - if(($response=$this->getResponse())!==null) |
|
126 | + $handling = true; |
|
127 | + if (($response = $this->getResponse()) !== null) |
|
128 | 128 | $response->clear(); |
129 | - if(!headers_sent()) |
|
129 | + if (!headers_sent()) |
|
130 | 130 | header('Content-Type: text/html; charset=UTF-8'); |
131 | - if($param instanceof THttpException) |
|
132 | - $this->handleExternalError($param->getStatusCode(),$param); |
|
133 | - else if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
131 | + if ($param instanceof THttpException) |
|
132 | + $this->handleExternalError($param->getStatusCode(), $param); |
|
133 | + else if ($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
134 | 134 | $this->displayException($param); |
135 | 135 | else |
136 | - $this->handleExternalError(500,$param); |
|
136 | + $this->handleExternalError(500, $param); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
@@ -144,22 +144,22 @@ discard block |
||
144 | 144 | * @return string |
145 | 145 | * @since 3.1.6 |
146 | 146 | */ |
147 | - protected static function hideSecurityRelated($value, $exception=null) |
|
147 | + protected static function hideSecurityRelated($value, $exception = null) |
|
148 | 148 | { |
149 | 149 | $aRpl = array(); |
150 | - if($exception !== null && $exception instanceof Exception) |
|
150 | + if ($exception !== null && $exception instanceof Exception) |
|
151 | 151 | { |
152 | 152 | $aTrace = $exception->getTrace(); |
153 | - foreach($aTrace as $item) |
|
153 | + foreach ($aTrace as $item) |
|
154 | 154 | { |
155 | - if(isset($item['file'])) |
|
155 | + if (isset($item['file'])) |
|
156 | 156 | $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
157 | 157 | } |
158 | 158 | } |
159 | 159 | $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}'; |
160 | 160 | $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}'; |
161 | 161 | $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR; |
162 | - if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
|
162 | + if (isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
|
163 | 163 | $aRpl = array_reverse($aRpl, true); |
164 | 164 | |
165 | 165 | return str_replace(array_keys($aRpl), $aRpl, $value); |
@@ -172,36 +172,36 @@ discard block |
||
172 | 172 | * @param integer response status code |
173 | 173 | * @param Exception exception instance |
174 | 174 | */ |
175 | - protected function handleExternalError($statusCode,$exception) |
|
175 | + protected function handleExternalError($statusCode, $exception) |
|
176 | 176 | { |
177 | - if(!($exception instanceof THttpException)) |
|
177 | + if (!($exception instanceof THttpException)) |
|
178 | 178 | error_log($exception->__toString()); |
179 | 179 | |
180 | - $content=$this->getErrorTemplate($statusCode,$exception); |
|
180 | + $content = $this->getErrorTemplate($statusCode, $exception); |
|
181 | 181 | |
182 | - $serverAdmin=isset($_SERVER['SERVER_ADMIN'])?$_SERVER['SERVER_ADMIN']:''; |
|
182 | + $serverAdmin = isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : ''; |
|
183 | 183 | |
184 | - $isDebug = $this->getApplication()->getMode()===TApplicationMode::Debug; |
|
184 | + $isDebug = $this->getApplication()->getMode() === TApplicationMode::Debug; |
|
185 | 185 | |
186 | 186 | $errorMessage = $exception->getMessage(); |
187 | - if($isDebug) |
|
188 | - $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
187 | + if ($isDebug) |
|
188 | + $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
189 | 189 | else |
190 | 190 | { |
191 | - $version=''; |
|
191 | + $version = ''; |
|
192 | 192 | $errorMessage = self::hideSecurityRelated($errorMessage, $exception); |
193 | 193 | } |
194 | - $tokens=array( |
|
194 | + $tokens = array( |
|
195 | 195 | '%%StatusCode%%' => "$statusCode", |
196 | 196 | '%%ErrorMessage%%' => htmlspecialchars($errorMessage), |
197 | 197 | '%%ServerAdmin%%' => $serverAdmin, |
198 | 198 | '%%Version%%' => $version, |
199 | - '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time()) |
|
199 | + '%%Time%%' => @strftime('%Y-%m-%d %H:%M', time()) |
|
200 | 200 | ); |
201 | 201 | |
202 | 202 | $this->getApplication()->getResponse()->setStatusCode($statusCode, $isDebug ? $exception->getMessage() : null); |
203 | 203 | |
204 | - echo strtr($content,$tokens); |
|
204 | + echo strtr($content, $tokens); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -213,16 +213,16 @@ discard block |
||
213 | 213 | */ |
214 | 214 | protected function handleRecursiveError($exception) |
215 | 215 | { |
216 | - if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
216 | + if ($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
217 | 217 | { |
218 | 218 | echo "<html><head><title>Recursive Error</title></head>\n"; |
219 | 219 | echo "<body><h1>Recursive Error</h1>\n"; |
220 | - echo "<pre>".$exception->__toString()."</pre>\n"; |
|
220 | + echo "<pre>" . $exception->__toString() . "</pre>\n"; |
|
221 | 221 | echo "</body></html>"; |
222 | 222 | } |
223 | 223 | else |
224 | 224 | { |
225 | - error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
|
225 | + error_log("Error happened while processing an existing error:\n" . $exception->__toString()); |
|
226 | 226 | header('HTTP/1.0 500 Internal Error'); |
227 | 227 | } |
228 | 228 | } |
@@ -236,55 +236,55 @@ discard block |
||
236 | 236 | */ |
237 | 237 | protected function displayException($exception) |
238 | 238 | { |
239 | - if(php_sapi_name()==='cli') |
|
239 | + if (php_sapi_name() === 'cli') |
|
240 | 240 | { |
241 | - echo $exception->getMessage()."\n"; |
|
241 | + echo $exception->getMessage() . "\n"; |
|
242 | 242 | echo $exception->getTraceAsString(); |
243 | 243 | return; |
244 | 244 | } |
245 | 245 | |
246 | - if($exception instanceof TTemplateException) |
|
246 | + if ($exception instanceof TTemplateException) |
|
247 | 247 | { |
248 | - $fileName=$exception->getTemplateFile(); |
|
249 | - $lines=empty($fileName)?explode("\n",$exception->getTemplateSource()):@file($fileName); |
|
250 | - $source=$this->getSourceCode($lines,$exception->getLineNumber()); |
|
251 | - if($fileName==='') |
|
252 | - $fileName='---embedded template---'; |
|
253 | - $errorLine=$exception->getLineNumber(); |
|
248 | + $fileName = $exception->getTemplateFile(); |
|
249 | + $lines = empty($fileName) ?explode("\n", $exception->getTemplateSource()) : @file($fileName); |
|
250 | + $source = $this->getSourceCode($lines, $exception->getLineNumber()); |
|
251 | + if ($fileName === '') |
|
252 | + $fileName = '---embedded template---'; |
|
253 | + $errorLine = $exception->getLineNumber(); |
|
254 | 254 | } |
255 | 255 | else |
256 | 256 | { |
257 | - if(($trace=$this->getExactTrace($exception))!==null) |
|
257 | + if (($trace = $this->getExactTrace($exception)) !== null) |
|
258 | 258 | { |
259 | - $fileName=$trace['file']; |
|
260 | - $errorLine=$trace['line']; |
|
259 | + $fileName = $trace['file']; |
|
260 | + $errorLine = $trace['line']; |
|
261 | 261 | } |
262 | 262 | else |
263 | 263 | { |
264 | - $fileName=$exception->getFile(); |
|
265 | - $errorLine=$exception->getLine(); |
|
264 | + $fileName = $exception->getFile(); |
|
265 | + $errorLine = $exception->getLine(); |
|
266 | 266 | } |
267 | - $source=$this->getSourceCode(@file($fileName),$errorLine); |
|
267 | + $source = $this->getSourceCode(@file($fileName), $errorLine); |
|
268 | 268 | } |
269 | 269 | |
270 | - if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
271 | - $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
270 | + if ($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
271 | + $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
272 | 272 | else |
273 | - $version=''; |
|
273 | + $version = ''; |
|
274 | 274 | |
275 | - $tokens=array( |
|
275 | + $tokens = array( |
|
276 | 276 | '%%ErrorType%%' => get_class($exception), |
277 | 277 | '%%ErrorMessage%%' => $this->addLink(htmlspecialchars($exception->getMessage())), |
278 | - '%%SourceFile%%' => htmlspecialchars($fileName).' ('.$errorLine.')', |
|
278 | + '%%SourceFile%%' => htmlspecialchars($fileName) . ' (' . $errorLine . ')', |
|
279 | 279 | '%%SourceCode%%' => $source, |
280 | 280 | '%%StackTrace%%' => htmlspecialchars($exception->getTraceAsString()), |
281 | 281 | '%%Version%%' => $version, |
282 | - '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time()) |
|
282 | + '%%Time%%' => @strftime('%Y-%m-%d %H:%M', time()) |
|
283 | 283 | ); |
284 | 284 | |
285 | - $content=$this->getExceptionTemplate($exception); |
|
285 | + $content = $this->getExceptionTemplate($exception); |
|
286 | 286 | |
287 | - echo strtr($content,$tokens); |
|
287 | + echo strtr($content, $tokens); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -296,11 +296,11 @@ discard block |
||
296 | 296 | */ |
297 | 297 | protected function getExceptionTemplate($exception) |
298 | 298 | { |
299 | - $lang=Prado::getPreferredLanguage(); |
|
300 | - $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'-'.$lang.'.html'; |
|
301 | - if(!is_file($exceptionFile)) |
|
302 | - $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html'; |
|
303 | - if(($content=@file_get_contents($exceptionFile))===false) |
|
299 | + $lang = Prado::getPreferredLanguage(); |
|
300 | + $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '-' . $lang . '.html'; |
|
301 | + if (!is_file($exceptionFile)) |
|
302 | + $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '.html'; |
|
303 | + if (($content = @file_get_contents($exceptionFile)) === false) |
|
304 | 304 | die("Unable to open exception template file '$exceptionFile'."); |
305 | 305 | return $content; |
306 | 306 | } |
@@ -321,84 +321,84 @@ discard block |
||
321 | 321 | * @param Exception the exception to be displayed |
322 | 322 | * @return string the template content |
323 | 323 | */ |
324 | - protected function getErrorTemplate($statusCode,$exception) |
|
324 | + protected function getErrorTemplate($statusCode, $exception) |
|
325 | 325 | { |
326 | - $base=$this->getErrorTemplatePath().DIRECTORY_SEPARATOR.self::ERROR_FILE_NAME; |
|
327 | - $lang=Prado::getPreferredLanguage(); |
|
328 | - if(is_file("$base$statusCode-$lang.html")) |
|
329 | - $errorFile="$base$statusCode-$lang.html"; |
|
330 | - else if(is_file("$base$statusCode.html")) |
|
331 | - $errorFile="$base$statusCode.html"; |
|
332 | - else if(is_file("$base-$lang.html")) |
|
333 | - $errorFile="$base-$lang.html"; |
|
326 | + $base = $this->getErrorTemplatePath() . DIRECTORY_SEPARATOR . self::ERROR_FILE_NAME; |
|
327 | + $lang = Prado::getPreferredLanguage(); |
|
328 | + if (is_file("$base$statusCode-$lang.html")) |
|
329 | + $errorFile = "$base$statusCode-$lang.html"; |
|
330 | + else if (is_file("$base$statusCode.html")) |
|
331 | + $errorFile = "$base$statusCode.html"; |
|
332 | + else if (is_file("$base-$lang.html")) |
|
333 | + $errorFile = "$base-$lang.html"; |
|
334 | 334 | else |
335 | - $errorFile="$base.html"; |
|
336 | - if(($content=@file_get_contents($errorFile))===false) |
|
335 | + $errorFile = "$base.html"; |
|
336 | + if (($content = @file_get_contents($errorFile)) === false) |
|
337 | 337 | die("Unable to open error template file '$errorFile'."); |
338 | 338 | return $content; |
339 | 339 | } |
340 | 340 | |
341 | 341 | private function getExactTrace($exception) |
342 | 342 | { |
343 | - $trace=$exception->getTrace(); |
|
344 | - $result=null; |
|
343 | + $trace = $exception->getTrace(); |
|
344 | + $result = null; |
|
345 | 345 | // if PHP exception, we want to show the 2nd stack level context |
346 | 346 | // because the 1st stack level is of little use (it's in error handler) |
347 | - if($exception instanceof TPhpErrorException) |
|
347 | + if ($exception instanceof TPhpErrorException) |
|
348 | 348 | { |
349 | - if(isset($trace[0]['file'])) |
|
350 | - $result=$trace[0]; |
|
351 | - elseif(isset($trace[1])) |
|
352 | - $result=$trace[1]; |
|
349 | + if (isset($trace[0]['file'])) |
|
350 | + $result = $trace[0]; |
|
351 | + elseif (isset($trace[1])) |
|
352 | + $result = $trace[1]; |
|
353 | 353 | } |
354 | - else if($exception instanceof TInvalidOperationException) |
|
354 | + else if ($exception instanceof TInvalidOperationException) |
|
355 | 355 | { |
356 | 356 | // in case of getter or setter error, find out the exact file and row |
357 | - if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null) |
|
358 | - $result=$this->getPropertyAccessTrace($trace,'__set'); |
|
357 | + if (($result = $this->getPropertyAccessTrace($trace, '__get')) === null) |
|
358 | + $result = $this->getPropertyAccessTrace($trace, '__set'); |
|
359 | 359 | } |
360 | - if($result!==null && strpos($result['file'],': eval()\'d code')!==false) |
|
360 | + if ($result !== null && strpos($result['file'], ': eval()\'d code') !== false) |
|
361 | 361 | return null; |
362 | 362 | |
363 | 363 | return $result; |
364 | 364 | } |
365 | 365 | |
366 | - private function getPropertyAccessTrace($trace,$pattern) |
|
366 | + private function getPropertyAccessTrace($trace, $pattern) |
|
367 | 367 | { |
368 | - $result=null; |
|
369 | - foreach($trace as $t) |
|
368 | + $result = null; |
|
369 | + foreach ($trace as $t) |
|
370 | 370 | { |
371 | - if(isset($t['function']) && $t['function']===$pattern) |
|
372 | - $result=$t; |
|
371 | + if (isset($t['function']) && $t['function'] === $pattern) |
|
372 | + $result = $t; |
|
373 | 373 | else |
374 | 374 | break; |
375 | 375 | } |
376 | 376 | return $result; |
377 | 377 | } |
378 | 378 | |
379 | - private function getSourceCode($lines,$errorLine) |
|
379 | + private function getSourceCode($lines, $errorLine) |
|
380 | 380 | { |
381 | - $beginLine=$errorLine-self::SOURCE_LINES>=0?$errorLine-self::SOURCE_LINES:0; |
|
382 | - $endLine=$errorLine+self::SOURCE_LINES<=count($lines)?$errorLine+self::SOURCE_LINES:count($lines); |
|
381 | + $beginLine = $errorLine - self::SOURCE_LINES >= 0 ? $errorLine - self::SOURCE_LINES : 0; |
|
382 | + $endLine = $errorLine + self::SOURCE_LINES <= count($lines) ? $errorLine + self::SOURCE_LINES : count($lines); |
|
383 | 383 | |
384 | - $source=''; |
|
385 | - for($i=$beginLine;$i<$endLine;++$i) |
|
384 | + $source = ''; |
|
385 | + for ($i = $beginLine; $i < $endLine; ++$i) |
|
386 | 386 | { |
387 | - if($i===$errorLine-1) |
|
387 | + if ($i === $errorLine - 1) |
|
388 | 388 | { |
389 | - $line=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
390 | - $source.="<div class=\"error\">".$line."</div>"; |
|
389 | + $line = htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
390 | + $source .= "<div class=\"error\">" . $line . "</div>"; |
|
391 | 391 | } |
392 | 392 | else |
393 | - $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
393 | + $source .= htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
394 | 394 | } |
395 | 395 | return $source; |
396 | 396 | } |
397 | 397 | |
398 | 398 | private function addLink($message) |
399 | 399 | { |
400 | - $baseUrl='http://pradosoft.github.io/docs/manual/class-'; |
|
401 | - return preg_replace('/\b(T[A-Z]\w+)\b/',"<a href=\"$baseUrl\${1}\" target=\"_blank\">\${1}</a>",$message); |
|
400 | + $baseUrl = 'http://pradosoft.github.io/docs/manual/class-'; |
|
401 | + return preg_replace('/\b(T[A-Z]\w+)\b/', "<a href=\"$baseUrl\${1}\" target=\"_blank\">\${1}</a>", $message); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 |
@@ -393,6 +393,7 @@ |
||
393 | 393 | * in the message file. If so, the message in the preferred language |
394 | 394 | * will be used as the error message. Any rest parameters will be used |
395 | 395 | * to replace placeholders ({0}, {1}, {2}, etc.) in the message. |
396 | + * @param string $errorMessage |
|
396 | 397 | */ |
397 | 398 | public function __construct($statusCode,$errorMessage) |
398 | 399 | { |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | */ |
33 | 33 | class TException extends Exception |
34 | 34 | { |
35 | - private $_errorCode=''; |
|
36 | - static $_messageCache=array(); |
|
35 | + private $_errorCode = ''; |
|
36 | + static $_messageCache = array(); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Constructor. |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __construct($errorMessage) |
46 | 46 | { |
47 | - $this->_errorCode=$errorMessage; |
|
48 | - $errorMessage=$this->translateErrorMessage($errorMessage); |
|
49 | - $args=func_get_args(); |
|
47 | + $this->_errorCode = $errorMessage; |
|
48 | + $errorMessage = $this->translateErrorMessage($errorMessage); |
|
49 | + $args = func_get_args(); |
|
50 | 50 | array_shift($args); |
51 | - $n=count($args); |
|
52 | - $tokens=array(); |
|
53 | - for($i=0;$i<$n;++$i) |
|
54 | - $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]); |
|
55 | - parent::__construct(strtr($errorMessage,$tokens)); |
|
51 | + $n = count($args); |
|
52 | + $tokens = array(); |
|
53 | + for ($i = 0; $i < $n; ++$i) |
|
54 | + $tokens['{' . $i . '}'] = TPropertyValue::ensureString($args[$i]); |
|
55 | + parent::__construct(strtr($errorMessage, $tokens)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | */ |
63 | 63 | protected function translateErrorMessage($key) |
64 | 64 | { |
65 | - $msgFile=$this->getErrorMessageFile(); |
|
65 | + $msgFile = $this->getErrorMessageFile(); |
|
66 | 66 | |
67 | 67 | // Cache messages |
68 | 68 | if (!isset(self::$_messageCache[$msgFile])) |
69 | 69 | { |
70 | - if(($entries=@file($msgFile))!==false) |
|
70 | + if (($entries = @file($msgFile)) !== false) |
|
71 | 71 | { |
72 | - foreach($entries as $entry) |
|
72 | + foreach ($entries as $entry) |
|
73 | 73 | { |
74 | - @list($code,$message)=explode('=',$entry,2); |
|
75 | - self::$_messageCache[$msgFile][trim($code)]=trim($message); |
|
74 | + @list($code, $message) = explode('=', $entry, 2); |
|
75 | + self::$_messageCache[$msgFile][trim($code)] = trim($message); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | } |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function getErrorMessageFile() |
86 | 86 | { |
87 | - $lang=Prado::getPreferredLanguage(); |
|
88 | - $msgFile=Prado::getFrameworkPath().'/Exceptions/messages/messages-'.$lang.'.txt'; |
|
89 | - if(!is_file($msgFile)) |
|
90 | - $msgFile=Prado::getFrameworkPath().'/Exceptions/messages/messages.txt'; |
|
87 | + $lang = Prado::getPreferredLanguage(); |
|
88 | + $msgFile = Prado::getFrameworkPath() . '/Exceptions/messages/messages-' . $lang . '.txt'; |
|
89 | + if (!is_file($msgFile)) |
|
90 | + $msgFile = Prado::getFrameworkPath() . '/Exceptions/messages/messages.txt'; |
|
91 | 91 | return $msgFile; |
92 | 92 | } |
93 | 93 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function setErrorCode($code) |
106 | 106 | { |
107 | - $this->_errorCode=$code; |
|
107 | + $this->_errorCode = $code; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | protected function setErrorMessage($message) |
122 | 122 | { |
123 | - $this->message=$message; |
|
123 | + $this->message = $message; |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
@@ -214,9 +214,9 @@ discard block |
||
214 | 214 | */ |
215 | 215 | class TTemplateException extends TConfigurationException |
216 | 216 | { |
217 | - private $_template=''; |
|
218 | - private $_lineNumber=0; |
|
219 | - private $_fileName=''; |
|
217 | + private $_template = ''; |
|
218 | + private $_lineNumber = 0; |
|
219 | + private $_fileName = ''; |
|
220 | 220 | |
221 | 221 | /** |
222 | 222 | * @return string the template source code that causes the exception. This is empty if {@link getTemplateFile TemplateFile} is not empty. |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public function setTemplateSource($value) |
233 | 233 | { |
234 | - $this->_template=$value; |
|
234 | + $this->_template = $value; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function setTemplateFile($value) |
249 | 249 | { |
250 | - $this->_fileName=$value; |
|
250 | + $this->_fileName = $value; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | */ |
264 | 264 | public function setLineNumber($value) |
265 | 265 | { |
266 | - $this->_lineNumber=TPropertyValue::ensureInteger($value); |
|
266 | + $this->_lineNumber = TPropertyValue::ensureInteger($value); |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
@@ -338,9 +338,9 @@ discard block |
||
338 | 338 | * @param string error file |
339 | 339 | * @param integer error line number |
340 | 340 | */ |
341 | - public function __construct($errno,$errstr,$errfile,$errline) |
|
341 | + public function __construct($errno, $errstr, $errfile, $errline) |
|
342 | 342 | { |
343 | - static $errorTypes=array( |
|
343 | + static $errorTypes = array( |
|
344 | 344 | E_ERROR => "Error", |
345 | 345 | E_WARNING => "Warning", |
346 | 346 | E_PARSE => "Parsing Error", |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | E_USER_NOTICE => "User Notice", |
355 | 355 | E_STRICT => "Runtime Notice" |
356 | 356 | ); |
357 | - $errorType=isset($errorTypes[$errno])?$errorTypes[$errno]:'Unknown Error'; |
|
357 | + $errorType = isset($errorTypes[$errno]) ? $errorTypes[$errno] : 'Unknown Error'; |
|
358 | 358 | parent::__construct("[$errorType] $errstr (@line $errline in file $errfile)."); |
359 | 359 | } |
360 | 360 | |
@@ -394,19 +394,19 @@ discard block |
||
394 | 394 | * will be used as the error message. Any rest parameters will be used |
395 | 395 | * to replace placeholders ({0}, {1}, {2}, etc.) in the message. |
396 | 396 | */ |
397 | - public function __construct($statusCode,$errorMessage) |
|
397 | + public function __construct($statusCode, $errorMessage) |
|
398 | 398 | { |
399 | - $this->_statusCode=$statusCode; |
|
399 | + $this->_statusCode = $statusCode; |
|
400 | 400 | $this->setErrorCode($errorMessage); |
401 | - $errorMessage=$this->translateErrorMessage($errorMessage); |
|
402 | - $args=func_get_args(); |
|
401 | + $errorMessage = $this->translateErrorMessage($errorMessage); |
|
402 | + $args = func_get_args(); |
|
403 | 403 | array_shift($args); |
404 | 404 | array_shift($args); |
405 | - $n=count($args); |
|
406 | - $tokens=array(); |
|
407 | - for($i=0;$i<$n;++$i) |
|
408 | - $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]); |
|
409 | - parent::__construct(strtr($errorMessage,$tokens)); |
|
405 | + $n = count($args); |
|
406 | + $tokens = array(); |
|
407 | + for ($i = 0; $i < $n; ++$i) |
|
408 | + $tokens['{' . $i . '}'] = TPropertyValue::ensureString($args[$i]); |
|
409 | + parent::__construct(strtr($errorMessage, $tokens)); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
@@ -50,8 +50,9 @@ discard block |
||
50 | 50 | array_shift($args); |
51 | 51 | $n=count($args); |
52 | 52 | $tokens=array(); |
53 | - for($i=0;$i<$n;++$i) |
|
54 | - $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]); |
|
53 | + for($i=0;$i<$n;++$i) { |
|
54 | + $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]); |
|
55 | + } |
|
55 | 56 | parent::__construct(strtr($errorMessage,$tokens)); |
56 | 57 | } |
57 | 58 | |
@@ -404,8 +405,9 @@ discard block |
||
404 | 405 | array_shift($args); |
405 | 406 | $n=count($args); |
406 | 407 | $tokens=array(); |
407 | - for($i=0;$i<$n;++$i) |
|
408 | - $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]); |
|
408 | + for($i=0;$i<$n;++$i) { |
|
409 | + $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]); |
|
410 | + } |
|
409 | 411 | parent::__construct(strtr($errorMessage,$tokens)); |
410 | 412 | } |
411 | 413 |
@@ -200,6 +200,7 @@ discard block |
||
200 | 200 | |
201 | 201 | /** |
202 | 202 | * Gets the CultureInfo that for this culture string |
203 | + * @param string $culture |
|
203 | 204 | * @return CultureInfo invariant culture info is "en". |
204 | 205 | */ |
205 | 206 | public static function getInstance($culture) |
@@ -228,6 +229,7 @@ discard block |
||
228 | 229 | * Set the culture for the current instance. The culture indentifier |
229 | 230 | * must be of the form "<language>_(country/region)". |
230 | 231 | * @param string culture identifier, e.g. "fr_FR_EURO". |
232 | + * @param string $culture |
|
231 | 233 | */ |
232 | 234 | protected function setCulture($culture) |
233 | 235 | { |
@@ -243,6 +245,7 @@ discard block |
||
243 | 245 | /** |
244 | 246 | * Load the ICU culture data for the specific culture identifier. |
245 | 247 | * @param string the culture identifier. |
248 | + * @param string $culture |
|
246 | 249 | */ |
247 | 250 | protected function loadCultureData($culture) |
248 | 251 | { |
@@ -283,6 +286,7 @@ discard block |
||
283 | 286 | * The data files are cached in a static variable inside |
284 | 287 | * this function. |
285 | 288 | * @param string the ICU data filename |
289 | + * @param string $filename |
|
286 | 290 | * @return array ICU data |
287 | 291 | */ |
288 | 292 | protected function &getData($filename) |
@@ -386,6 +390,7 @@ discard block |
||
386 | 390 | /** |
387 | 391 | * Set the date time format information. |
388 | 392 | * @param DateTimeFormatInfo the new date time format info. |
393 | + * @param DateTimeFormatInfo $dateTimeFormat |
|
389 | 394 | */ |
390 | 395 | function setDateTimeFormat($dateTimeFormat) |
391 | 396 | { |
@@ -493,6 +498,7 @@ discard block |
||
493 | 498 | /** |
494 | 499 | * Set the number format information. |
495 | 500 | * @param NumberFormatInfo the new number format info. |
501 | + * @param NumberFormatInfo $numberFormat |
|
496 | 502 | */ |
497 | 503 | function setNumberFormat($numberFormat) |
498 | 504 | { |
@@ -199,9 +199,9 @@ |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | - * Gets the CultureInfo that for this culture string |
|
203 | - * @return CultureInfo invariant culture info is "en". |
|
204 | - */ |
|
202 | + * Gets the CultureInfo that for this culture string |
|
203 | + * @return CultureInfo invariant culture info is "en". |
|
204 | + */ |
|
205 | 205 | public static function getInstance($culture) |
206 | 206 | { |
207 | 207 | static $instances = array(); |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | */ |
135 | 135 | function __get($name) |
136 | 136 | { |
137 | - $getProperty = 'get'.$name; |
|
138 | - if(in_array($getProperty, $this->properties)) |
|
137 | + $getProperty = 'get' . $name; |
|
138 | + if (in_array($getProperty, $this->properties)) |
|
139 | 139 | return $this->$getProperty(); |
140 | 140 | else |
141 | - throw new Exception('Property '.$name.' does not exists.'); |
|
141 | + throw new Exception('Property ' . $name . ' does not exists.'); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | */ |
148 | 148 | function __set($name, $value) |
149 | 149 | { |
150 | - $setProperty = 'set'.$name; |
|
151 | - if(in_array($setProperty, $this->properties)) |
|
150 | + $setProperty = 'set' . $name; |
|
151 | + if (in_array($setProperty, $this->properties)) |
|
152 | 152 | $this->$setProperty($value); |
153 | 153 | else |
154 | - throw new Exception('Property '.$name.' can not be set.'); |
|
154 | + throw new Exception('Property ' . $name . ' can not be set.'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | * @param string a culture name, e.g. "en_AU". |
164 | 164 | * @return return new CultureInfo. |
165 | 165 | */ |
166 | - function __construct($culture='en') |
|
166 | + function __construct($culture = 'en') |
|
167 | 167 | { |
168 | 168 | $this->properties = get_class_methods($this); |
169 | 169 | |
170 | - if(empty($culture)) |
|
170 | + if (empty($culture)) |
|
171 | 171 | $culture = 'en'; |
172 | 172 | |
173 | 173 | $this->dataDir = $this->dataDir(); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected static function dataDir() |
188 | 188 | { |
189 | - return dirname(__FILE__).'/data/'; |
|
189 | + return dirname(__FILE__) . '/data/'; |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | public static function getInstance($culture) |
206 | 206 | { |
207 | 207 | static $instances = array(); |
208 | - if(!isset($instances[$culture])) |
|
208 | + if (!isset($instances[$culture])) |
|
209 | 209 | $instances[$culture] = new CultureInfo($culture); |
210 | 210 | return $instances[$culture]; |
211 | 211 | } |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public static function validCulture($culture) |
220 | 220 | { |
221 | - if(preg_match('/^[_\\w]+$/', $culture)) |
|
222 | - return is_file(self::dataDir().$culture.self::fileExt()); |
|
221 | + if (preg_match('/^[_\\w]+$/', $culture)) |
|
222 | + return is_file(self::dataDir() . $culture . self::fileExt()); |
|
223 | 223 | |
224 | 224 | return false; |
225 | 225 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | protected function setCulture($culture) |
233 | 233 | { |
234 | - if(!empty($culture)) |
|
234 | + if (!empty($culture)) |
|
235 | 235 | { |
236 | 236 | if (!preg_match('/^[_\\w]+$/', $culture)) |
237 | 237 | throw new Exception('Invalid culture supplied: ' . $culture); |
@@ -246,32 +246,32 @@ discard block |
||
246 | 246 | */ |
247 | 247 | protected function loadCultureData($culture) |
248 | 248 | { |
249 | - $file_parts = explode('_',$culture); |
|
249 | + $file_parts = explode('_', $culture); |
|
250 | 250 | $current_part = $file_parts[0]; |
251 | 251 | |
252 | 252 | $files = array($current_part); |
253 | 253 | |
254 | - for($i = 1, $k = count($file_parts); $i < $k; ++$i) |
|
254 | + for ($i = 1, $k = count($file_parts); $i < $k; ++$i) |
|
255 | 255 | { |
256 | - $current_part .= '_'.$file_parts[$i]; |
|
256 | + $current_part .= '_' . $file_parts[$i]; |
|
257 | 257 | $files[] = $current_part; |
258 | 258 | } |
259 | 259 | |
260 | - foreach($files as $file) |
|
260 | + foreach ($files as $file) |
|
261 | 261 | { |
262 | - $filename = $this->dataDir.$file.$this->dataFileExt; |
|
262 | + $filename = $this->dataDir . $file . $this->dataFileExt; |
|
263 | 263 | |
264 | - if(is_file($filename) == false) |
|
265 | - throw new Exception('Data file for "'.$file.'" was not found.'); |
|
264 | + if (is_file($filename) == false) |
|
265 | + throw new Exception('Data file for "' . $file . '" was not found.'); |
|
266 | 266 | |
267 | - if(in_array($filename, $this->dataFiles) === false) |
|
267 | + if (in_array($filename, $this->dataFiles) === false) |
|
268 | 268 | { |
269 | 269 | array_unshift($this->dataFiles, $file); |
270 | 270 | |
271 | 271 | $data = &$this->getData($filename); |
272 | 272 | $this->data[$file] = &$data; |
273 | 273 | |
274 | - if(isset($data['__ALIAS'])) |
|
274 | + if (isset($data['__ALIAS'])) |
|
275 | 275 | $this->loadCultureData($data['__ALIAS'][0]); |
276 | 276 | unset($data); |
277 | 277 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | static $data = array(); |
291 | 291 | static $files = array(); |
292 | 292 | |
293 | - if(!in_array($filename, $files)) |
|
293 | + if (!in_array($filename, $files)) |
|
294 | 294 | { |
295 | 295 | $data[$filename] = unserialize(file_get_contents($filename)); |
296 | 296 | $files[] = $filename; |
@@ -313,17 +313,17 @@ discard block |
||
313 | 313 | * @param boolean merge the data from its parents. |
314 | 314 | * @return mixed the specific ICU data. |
315 | 315 | */ |
316 | - protected function findInfo($path='/', $merge=false) |
|
316 | + protected function findInfo($path = '/', $merge = false) |
|
317 | 317 | { |
318 | 318 | $result = array(); |
319 | - foreach($this->dataFiles as $section) |
|
319 | + foreach ($this->dataFiles as $section) |
|
320 | 320 | { |
321 | 321 | $info = $this->searchArray($this->data[$section], $path); |
322 | 322 | |
323 | - if($info) |
|
323 | + if ($info) |
|
324 | 324 | { |
325 | - if($merge) |
|
326 | - $result = array_merge($info,$result); |
|
325 | + if ($merge) |
|
326 | + $result = array_merge($info, $result); |
|
327 | 327 | else |
328 | 328 | return $info; |
329 | 329 | } |
@@ -340,18 +340,18 @@ discard block |
||
340 | 340 | * @param string slash "/" separated array path. |
341 | 341 | * @return mixed the value array using the path |
342 | 342 | */ |
343 | - private function searchArray($info, $path='/') |
|
343 | + private function searchArray($info, $path = '/') |
|
344 | 344 | { |
345 | - $index = explode('/',$path); |
|
345 | + $index = explode('/', $path); |
|
346 | 346 | |
347 | 347 | $array = $info; |
348 | 348 | |
349 | - for($i = 0, $k = count($index); $i < $k; ++$i) |
|
349 | + for ($i = 0, $k = count($index); $i < $k; ++$i) |
|
350 | 350 | { |
351 | 351 | $value = $index[$i]; |
352 | - if($i < $k-1 && isset($array[$value])) |
|
352 | + if ($i < $k - 1 && isset($array[$value])) |
|
353 | 353 | $array = $array[$value]; |
354 | - else if ($i == $k-1 && isset($array[$value])) |
|
354 | + else if ($i == $k - 1 && isset($array[$value])) |
|
355 | 355 | return $array[$value]; |
356 | 356 | } |
357 | 357 | } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | */ |
374 | 374 | function getDateTimeFormat() |
375 | 375 | { |
376 | - if($this->dateTimeFormat === null) |
|
376 | + if ($this->dateTimeFormat === null) |
|
377 | 377 | { |
378 | 378 | $calendar = $this->getCalendar(); |
379 | 379 | $info = $this->findInfo("calendar/{$calendar}", true); |
@@ -410,12 +410,12 @@ discard block |
||
410 | 410 | */ |
411 | 411 | function getNativeName() |
412 | 412 | { |
413 | - $lang = substr($this->culture,0,2); |
|
414 | - $reg = substr($this->culture,3,2); |
|
413 | + $lang = substr($this->culture, 0, 2); |
|
414 | + $reg = substr($this->culture, 3, 2); |
|
415 | 415 | $language = $this->findInfo("Languages/{$lang}"); |
416 | 416 | $region = $this->findInfo("Countries/{$reg}"); |
417 | - if($region) |
|
418 | - return $language[0].' ('.$region[0].')'; |
|
417 | + if ($region) |
|
418 | + return $language[0] . ' (' . $region[0] . ')'; |
|
419 | 419 | else |
420 | 420 | return $language[0]; |
421 | 421 | } |
@@ -428,17 +428,17 @@ discard block |
||
428 | 428 | */ |
429 | 429 | function getEnglishName() |
430 | 430 | { |
431 | - $lang = substr($this->culture,0,2); |
|
432 | - $reg = substr($this->culture,3,2); |
|
431 | + $lang = substr($this->culture, 0, 2); |
|
432 | + $reg = substr($this->culture, 3, 2); |
|
433 | 433 | $culture = $this->getInvariantCulture(); |
434 | 434 | |
435 | 435 | $language = $culture->findInfo("Languages/{$lang}"); |
436 | - if(count($language) == 0) |
|
436 | + if (count($language) == 0) |
|
437 | 437 | return $this->culture; |
438 | 438 | |
439 | 439 | $region = $culture->findInfo("Countries/{$reg}"); |
440 | - if($region) |
|
441 | - return $language[0].' ('.$region[0].')'; |
|
440 | + if ($region) |
|
441 | + return $language[0] . ' (' . $region[0] . ')'; |
|
442 | 442 | else |
443 | 443 | return $language[0]; |
444 | 444 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | static function getInvariantCulture() |
454 | 454 | { |
455 | 455 | static $invariant; |
456 | - if($invariant === null) |
|
456 | + if ($invariant === null) |
|
457 | 457 | $invariant = new CultureInfo(); |
458 | 458 | return $invariant; |
459 | 459 | } |
@@ -476,12 +476,12 @@ discard block |
||
476 | 476 | */ |
477 | 477 | function getNumberFormat() |
478 | 478 | { |
479 | - if($this->numberFormat === null) |
|
479 | + if ($this->numberFormat === null) |
|
480 | 480 | { |
481 | 481 | $elements = $this->findInfo('NumberElements'); |
482 | 482 | $patterns = $this->findInfo('NumberPatterns'); |
483 | 483 | $currencies = $this->getCurrencies(); |
484 | - $data = array( 'NumberElements'=>$elements, |
|
484 | + $data = array('NumberElements'=>$elements, |
|
485 | 485 | 'NumberPatterns'=>$patterns, |
486 | 486 | 'Currencies' => $currencies); |
487 | 487 | |
@@ -506,10 +506,10 @@ discard block |
||
506 | 506 | */ |
507 | 507 | function getParent() |
508 | 508 | { |
509 | - if(strlen($this->culture) == 2) |
|
509 | + if (strlen($this->culture) == 2) |
|
510 | 510 | return $this->getInvariantCulture(); |
511 | 511 | |
512 | - $lang = substr($this->culture,0,2); |
|
512 | + $lang = substr($this->culture, 0, 2); |
|
513 | 513 | return new CultureInfo($lang); |
514 | 514 | } |
515 | 515 | |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | * or CultureInfo::SPECIFIC. |
523 | 523 | * @return array list of culture information available. |
524 | 524 | */ |
525 | - static function getCultures($type=CultureInfo::ALL) |
|
525 | + static function getCultures($type = CultureInfo::ALL) |
|
526 | 526 | { |
527 | 527 | $dataDir = CultureInfo::dataDir(); |
528 | 528 | $dataExt = CultureInfo::fileExt(); |
@@ -533,12 +533,12 @@ discard block |
||
533 | 533 | |
534 | 534 | while (false !== ($entry = $dir->read())) |
535 | 535 | { |
536 | - if(is_file($dataDir.$entry) |
|
537 | - && substr($entry,-4) == $dataExt |
|
538 | - && $entry != 'root'.$dataExt) |
|
536 | + if (is_file($dataDir . $entry) |
|
537 | + && substr($entry, -4) == $dataExt |
|
538 | + && $entry != 'root' . $dataExt) |
|
539 | 539 | { |
540 | - $culture = substr($entry,0,-4); |
|
541 | - if(strlen($culture) == 2) |
|
540 | + $culture = substr($entry, 0, -4); |
|
541 | + if (strlen($culture) == 2) |
|
542 | 542 | $neutral[] = $culture; |
543 | 543 | else |
544 | 544 | $specific[] = $culture; |
@@ -546,10 +546,10 @@ discard block |
||
546 | 546 | } |
547 | 547 | $dir->close(); |
548 | 548 | |
549 | - switch($type) |
|
549 | + switch ($type) |
|
550 | 550 | { |
551 | 551 | case CultureInfo::ALL : |
552 | - $all = array_merge($neutral, $specific); |
|
552 | + $all = array_merge($neutral, $specific); |
|
553 | 553 | sort($all); |
554 | 554 | return $all; |
555 | 555 | break; |
@@ -571,10 +571,10 @@ discard block |
||
571 | 571 | */ |
572 | 572 | private function simplify($array) |
573 | 573 | { |
574 | - for($i = 0, $k = count($array); $i<$k; ++$i) |
|
574 | + for ($i = 0, $k = count($array); $i < $k; ++$i) |
|
575 | 575 | { |
576 | 576 | $key = key($array); |
577 | - if(is_array($array[$key]) |
|
577 | + if (is_array($array[$key]) |
|
578 | 578 | && count($array[$key]) == 1) |
579 | 579 | $array[$key] = $array[$key][0]; |
580 | 580 | next($array); |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | */ |
589 | 589 | function getCountries() |
590 | 590 | { |
591 | - return $this->simplify($this->findInfo('Countries',true)); |
|
591 | + return $this->simplify($this->findInfo('Countries', true)); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | */ |
598 | 598 | function getCurrencies() |
599 | 599 | { |
600 | - return $this->findInfo('Currencies',true); |
|
600 | + return $this->findInfo('Currencies', true); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | */ |
607 | 607 | function getLanguages() |
608 | 608 | { |
609 | - return $this->simplify($this->findInfo('Languages',true)); |
|
609 | + return $this->simplify($this->findInfo('Languages', true)); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | /** |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | */ |
616 | 616 | function getScripts() |
617 | 617 | { |
618 | - return $this->simplify($this->findInfo('Scripts',true)); |
|
618 | + return $this->simplify($this->findInfo('Scripts', true)); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | */ |
625 | 625 | function getTimeZones() |
626 | 626 | { |
627 | - return $this->simplify($this->findInfo('zoneStrings',true)); |
|
627 | + return $this->simplify($this->findInfo('zoneStrings', true)); |
|
628 | 628 | } |
629 | 629 | } |
630 | 630 |
@@ -340,6 +340,7 @@ |
||
340 | 340 | /** |
341 | 341 | * A string containing the name of the era. |
342 | 342 | * @param int era The integer representing the era. |
343 | + * @param integer $era |
|
343 | 344 | * @return string the era name. |
344 | 345 | */ |
345 | 346 | function getEra($era) |
@@ -149,46 +149,46 @@ discard block |
||
149 | 149 | * (invariant). |
150 | 150 | * @return DateTimeFormatInfo default DateTimeFormatInfo. |
151 | 151 | */ |
152 | - static function getInvariantInfo() |
|
153 | - { |
|
154 | - static $invariant; |
|
152 | + static function getInvariantInfo() |
|
153 | + { |
|
154 | + static $invariant; |
|
155 | 155 | if($invariant === null) |
156 | - { |
|
157 | - $culture = CultureInfo::getInvariantCulture(); |
|
158 | - $invariant = $culture->getDateTimeFormat(); |
|
159 | - } |
|
156 | + { |
|
157 | + $culture = CultureInfo::getInvariantCulture(); |
|
158 | + $invariant = $culture->getDateTimeFormat(); |
|
159 | + } |
|
160 | 160 | return $invariant; |
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns the DateTimeFormatInfo associated with the specified culture. |
|
165 | - * @param CultureInfo the culture that gets the DateTimeFormat property. |
|
166 | - * @return DateTimeFormatInfo DateTimeFormatInfo for the specified |
|
167 | - * culture. |
|
168 | - */ |
|
169 | - static function getInstance($culture=null) |
|
170 | - { |
|
171 | - |
|
172 | - if ($culture instanceof CultureInfo) |
|
173 | - return $culture->getDateTimeFormat(); |
|
174 | - else if(is_string($culture)) |
|
175 | - { |
|
176 | - $cultureInfo = CultureInfo::getInstance($culture); |
|
177 | - return $cultureInfo->getDateTimeFormat(); |
|
178 | - } |
|
179 | - else |
|
180 | - { |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns the DateTimeFormatInfo associated with the specified culture. |
|
165 | + * @param CultureInfo the culture that gets the DateTimeFormat property. |
|
166 | + * @return DateTimeFormatInfo DateTimeFormatInfo for the specified |
|
167 | + * culture. |
|
168 | + */ |
|
169 | + static function getInstance($culture=null) |
|
170 | + { |
|
171 | + |
|
172 | + if ($culture instanceof CultureInfo) |
|
173 | + return $culture->getDateTimeFormat(); |
|
174 | + else if(is_string($culture)) |
|
175 | + { |
|
176 | + $cultureInfo = CultureInfo::getInstance($culture); |
|
177 | + return $cultureInfo->getDateTimeFormat(); |
|
178 | + } |
|
179 | + else |
|
180 | + { |
|
181 | 181 | $cultureInfo = CultureInfo::getInvariantCulture(); |
182 | - return $cultureInfo->getDateTimeFormat(); |
|
183 | - } |
|
184 | - } |
|
182 | + return $cultureInfo->getDateTimeFormat(); |
|
183 | + } |
|
184 | + } |
|
185 | 185 | |
186 | 186 | /** |
187 | 187 | * A one-dimensional array of type String containing |
188 | 188 | * the culture-specific abbreviated names of the days |
189 | 189 | * of the week. The array for InvariantInfo contains |
190 | 190 | * "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat". |
191 | - * @return array abbreviated day names |
|
191 | + * @return array abbreviated day names |
|
192 | 192 | */ |
193 | 193 | function getAbbreviatedDayNames() |
194 | 194 | { |
@@ -196,37 +196,37 @@ discard block |
||
196 | 196 | //return $this->data['dayNames/format/abbreviated']; |
197 | 197 | } |
198 | 198 | |
199 | - /** |
|
200 | - * Set the abbreviated day names. The value should be |
|
201 | - * an array of string starting with Sunday and ends in Saturady. |
|
202 | - * For example, |
|
203 | - * <code>array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");</code> |
|
204 | - * @param array abbreviated day names. |
|
205 | - */ |
|
206 | - function setAbbreviatedDayNames($value) |
|
207 | - { |
|
208 | - $this->data['dayNames']['format']['abbreviated'] = $value; |
|
209 | - } |
|
199 | + /** |
|
200 | + * Set the abbreviated day names. The value should be |
|
201 | + * an array of string starting with Sunday and ends in Saturady. |
|
202 | + * For example, |
|
203 | + * <code>array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");</code> |
|
204 | + * @param array abbreviated day names. |
|
205 | + */ |
|
206 | + function setAbbreviatedDayNames($value) |
|
207 | + { |
|
208 | + $this->data['dayNames']['format']['abbreviated'] = $value; |
|
209 | + } |
|
210 | 210 | |
211 | 211 | /** |
212 | 212 | * A one-dimensional array of type String containing |
213 | 213 | * the culture-specific narrow names of the days |
214 | 214 | * of the week. The array for InvariantInfo contains |
215 | 215 | * "S", "M", "T", "W", "T", "F", and "S". |
216 | - * @return array narrow day names |
|
216 | + * @return array narrow day names |
|
217 | 217 | */ |
218 | 218 | function getNarrowDayNames() |
219 | 219 | { |
220 | 220 | return $this->data['dayNames']['format']['narrow']; |
221 | 221 | } |
222 | 222 | |
223 | - /** |
|
224 | - * Set the narrow day names. The value should be |
|
225 | - * an array of string starting with Sunday and ends in Saturady. |
|
226 | - * For example, |
|
227 | - * <code>array("S", "M", "T", "W", "T", "F", "S");</code> |
|
228 | - * @param array narrow day names. |
|
229 | - */ |
|
223 | + /** |
|
224 | + * Set the narrow day names. The value should be |
|
225 | + * an array of string starting with Sunday and ends in Saturady. |
|
226 | + * For example, |
|
227 | + * <code>array("S", "M", "T", "W", "T", "F", "S");</code> |
|
228 | + * @param array narrow day names. |
|
229 | + */ |
|
230 | 230 | function setNarrowDayNames($value) |
231 | 231 | { |
232 | 232 | $this->data['dayNames']['format']['narrow'] = $value; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * culture-specific full names of the days of the week. |
238 | 238 | * The array for InvariantInfo contains "Sunday", "Monday", |
239 | 239 | * "Tuesday", "Wednesday", "Thursday", "Friday", and "Saturday". |
240 | - * @return array day names |
|
240 | + * @return array day names |
|
241 | 241 | */ |
242 | 242 | function getDayNames() |
243 | 243 | { |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | } |
246 | 246 | |
247 | 247 | |
248 | - /** |
|
249 | - * Set the day names. The value should be |
|
250 | - * an array of string starting with Sunday and ends in Saturady. |
|
251 | - * For example, |
|
252 | - * <code>array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", |
|
253 | - * "Friday", "Saturday".);</code> |
|
254 | - * @param array day names. |
|
255 | - */ |
|
248 | + /** |
|
249 | + * Set the day names. The value should be |
|
250 | + * an array of string starting with Sunday and ends in Saturady. |
|
251 | + * For example, |
|
252 | + * <code>array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", |
|
253 | + * "Friday", "Saturday".);</code> |
|
254 | + * @param array day names. |
|
255 | + */ |
|
256 | 256 | function setDayNames($value) |
257 | 257 | { |
258 | 258 | $this->data['dayNames']['format']['wide'] = $value; |
@@ -270,17 +270,17 @@ discard block |
||
270 | 270 | return $this->data['monthNames']['format']['narrow']; |
271 | 271 | } |
272 | 272 | |
273 | - /** |
|
274 | - * Set the narrow month names. The value should be |
|
275 | - * an array of string starting with J and ends in D. |
|
276 | - * For example, |
|
277 | - * <code>array("J","F","M","A","M","J","J","A","S","O","N","D");</code> |
|
278 | - * @param array month names. |
|
279 | - */ |
|
280 | - function setNarrowMonthNames($value) |
|
281 | - { |
|
282 | - $this->data['monthNames']['format']['narrow'] = $value; |
|
283 | - } |
|
273 | + /** |
|
274 | + * Set the narrow month names. The value should be |
|
275 | + * an array of string starting with J and ends in D. |
|
276 | + * For example, |
|
277 | + * <code>array("J","F","M","A","M","J","J","A","S","O","N","D");</code> |
|
278 | + * @param array month names. |
|
279 | + */ |
|
280 | + function setNarrowMonthNames($value) |
|
281 | + { |
|
282 | + $this->data['monthNames']['format']['narrow'] = $value; |
|
283 | + } |
|
284 | 284 | |
285 | 285 | /** |
286 | 286 | * A one-dimensional array of type String containing the |
@@ -298,18 +298,18 @@ discard block |
||
298 | 298 | return $this->data['monthNames']['format']['wide']; |
299 | 299 | } |
300 | 300 | |
301 | - /** |
|
302 | - * Set the abbreviated month names. The value should be |
|
303 | - * an array of string starting with Jan and ends in Dec. |
|
304 | - * For example, |
|
305 | - * <code>array("Jan", "Feb", "Mar", "Apr", "May", "Jun", |
|
306 | - * "Jul", "Aug", "Sep","Oct","Nov","Dec");</code> |
|
307 | - * @param array month names. |
|
308 | - */ |
|
309 | - function setAbbreviatedMonthNames($value) |
|
310 | - { |
|
311 | - $this->data['monthNames']['format']['abbreviated'] = $value; |
|
312 | - } |
|
301 | + /** |
|
302 | + * Set the abbreviated month names. The value should be |
|
303 | + * an array of string starting with Jan and ends in Dec. |
|
304 | + * For example, |
|
305 | + * <code>array("Jan", "Feb", "Mar", "Apr", "May", "Jun", |
|
306 | + * "Jul", "Aug", "Sep","Oct","Nov","Dec");</code> |
|
307 | + * @param array month names. |
|
308 | + */ |
|
309 | + function setAbbreviatedMonthNames($value) |
|
310 | + { |
|
311 | + $this->data['monthNames']['format']['abbreviated'] = $value; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * A one-dimensional array of type String containing the |
@@ -324,18 +324,18 @@ discard block |
||
324 | 324 | return $this->data['monthNames']['format']['wide']; |
325 | 325 | } |
326 | 326 | |
327 | - /** |
|
328 | - * Set the month names. The value should be |
|
329 | - * an array of string starting with Janurary and ends in December. |
|
330 | - * For example, |
|
331 | - * <code>array("January", "February", "March", "April", "May", "June", |
|
332 | - * "July", "August", "September","October","November","December");</code> |
|
333 | - * @param array month names. |
|
334 | - */ |
|
335 | - function setMonthNames($value) |
|
336 | - { |
|
337 | - $this->data['monthNames']['format']['wide'] = $value; |
|
338 | - } |
|
327 | + /** |
|
328 | + * Set the month names. The value should be |
|
329 | + * an array of string starting with Janurary and ends in December. |
|
330 | + * For example, |
|
331 | + * <code>array("January", "February", "March", "April", "May", "June", |
|
332 | + * "July", "August", "September","October","November","December");</code> |
|
333 | + * @param array month names. |
|
334 | + */ |
|
335 | + function setMonthNames($value) |
|
336 | + { |
|
337 | + $this->data['monthNames']['format']['wide'] = $value; |
|
338 | + } |
|
339 | 339 | |
340 | 340 | /** |
341 | 341 | * A string containing the name of the era. |
@@ -359,16 +359,16 @@ discard block |
||
359 | 359 | return $result[0]; |
360 | 360 | } |
361 | 361 | |
362 | - /** |
|
363 | - * Set the AM Designator. For example, 'AM'. |
|
364 | - * @param string AM designator. |
|
365 | - */ |
|
366 | - function setAMDesignator($value) |
|
367 | - { |
|
368 | - $markers = $this->getAMPMMarkers(); |
|
369 | - $markers[0] = $value; |
|
370 | - $this->setAMPMMarkers($markers); |
|
371 | - } |
|
362 | + /** |
|
363 | + * Set the AM Designator. For example, 'AM'. |
|
364 | + * @param string AM designator. |
|
365 | + */ |
|
366 | + function setAMDesignator($value) |
|
367 | + { |
|
368 | + $markers = $this->getAMPMMarkers(); |
|
369 | + $markers[0] = $value; |
|
370 | + $this->setAMPMMarkers($markers); |
|
371 | + } |
|
372 | 372 | |
373 | 373 | /** |
374 | 374 | * The string designator for hours that are "post meridiem" (after noon). |
@@ -381,41 +381,41 @@ discard block |
||
381 | 381 | return $result[1]; |
382 | 382 | } |
383 | 383 | |
384 | - /** |
|
385 | - * Set the PM Designator. For example, 'PM'. |
|
386 | - * @param string PM designator. |
|
387 | - */ |
|
388 | - function setPMDesignator($value) |
|
389 | - { |
|
390 | - $markers = $this->getAMPMMarkers(); |
|
391 | - $markers[1] = $value; |
|
392 | - $this->setAMPMMarkers($markers); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Get the AM and PM markers array. |
|
397 | - * Default InvariantInfo for AM and PM is <code>array('AM','PM');</code> |
|
398 | - * @return array AM and PM markers |
|
399 | - */ |
|
400 | - function getAMPMMarkers() |
|
384 | + /** |
|
385 | + * Set the PM Designator. For example, 'PM'. |
|
386 | + * @param string PM designator. |
|
387 | + */ |
|
388 | + function setPMDesignator($value) |
|
389 | + { |
|
390 | + $markers = $this->getAMPMMarkers(); |
|
391 | + $markers[1] = $value; |
|
392 | + $this->setAMPMMarkers($markers); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Get the AM and PM markers array. |
|
397 | + * Default InvariantInfo for AM and PM is <code>array('AM','PM');</code> |
|
398 | + * @return array AM and PM markers |
|
399 | + */ |
|
400 | + function getAMPMMarkers() |
|
401 | 401 | { |
402 | 402 | return $this->data['AmPmMarkers']; |
403 | 403 | } |
404 | 404 | |
405 | - /** |
|
406 | - * Set the AM and PM markers array. |
|
407 | - * For example <code>array('AM','PM');</code> |
|
408 | - * @param array AM and PM markers |
|
409 | - */ |
|
410 | - function setAMPMMarkers($value) |
|
411 | - { |
|
412 | - $this->data['AmPmMarkers'] = $value; |
|
413 | - } |
|
405 | + /** |
|
406 | + * Set the AM and PM markers array. |
|
407 | + * For example <code>array('AM','PM');</code> |
|
408 | + * @param array AM and PM markers |
|
409 | + */ |
|
410 | + function setAMPMMarkers($value) |
|
411 | + { |
|
412 | + $this->data['AmPmMarkers'] = $value; |
|
413 | + } |
|
414 | 414 | |
415 | 415 | /** |
416 | 416 | * Returns the full time pattern "HH:mm:ss z" (default). |
417 | - * This is culture sensitive. |
|
418 | - * @return string pattern "HH:mm:ss z". |
|
417 | + * This is culture sensitive. |
|
418 | + * @return string pattern "HH:mm:ss z". |
|
419 | 419 | */ |
420 | 420 | function getFullTimePattern() |
421 | 421 | { |
@@ -424,8 +424,8 @@ discard block |
||
424 | 424 | |
425 | 425 | /** |
426 | 426 | * Returns the long time pattern "HH:mm:ss z" (default). |
427 | - * This is culture sensitive. |
|
428 | - * @return string pattern "HH:mm:ss z". |
|
427 | + * This is culture sensitive. |
|
428 | + * @return string pattern "HH:mm:ss z". |
|
429 | 429 | */ |
430 | 430 | function getLongTimePattern() |
431 | 431 | { |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | |
435 | 435 | /** |
436 | 436 | * Returns the medium time pattern "HH:mm:ss" (default). |
437 | - * This is culture sensitive. |
|
438 | - * @return string pattern "HH:mm:ss". |
|
437 | + * This is culture sensitive. |
|
438 | + * @return string pattern "HH:mm:ss". |
|
439 | 439 | */ |
440 | 440 | function getMediumTimePattern() |
441 | 441 | { |
@@ -444,8 +444,8 @@ discard block |
||
444 | 444 | |
445 | 445 | /** |
446 | 446 | * Returns the short time pattern "HH:mm" (default). |
447 | - * This is culture sensitive. |
|
448 | - * @return string pattern "HH:mm". |
|
447 | + * This is culture sensitive. |
|
448 | + * @return string pattern "HH:mm". |
|
449 | 449 | */ |
450 | 450 | function getShortTimePattern() |
451 | 451 | { |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | |
455 | 455 | /** |
456 | 456 | * Returns the full date pattern "EEEE, yyyy MMMM dd" (default). |
457 | - * This is culture sensitive. |
|
458 | - * @return string pattern "EEEE, yyyy MMMM dd". |
|
457 | + * This is culture sensitive. |
|
458 | + * @return string pattern "EEEE, yyyy MMMM dd". |
|
459 | 459 | */ |
460 | 460 | function getFullDatePattern() |
461 | 461 | { |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | |
465 | 465 | /** |
466 | 466 | * Returns the long date pattern "yyyy MMMM d" (default). |
467 | - * This is culture sensitive. |
|
468 | - * @return string pattern "yyyy MMMM d". |
|
467 | + * This is culture sensitive. |
|
468 | + * @return string pattern "yyyy MMMM d". |
|
469 | 469 | */ |
470 | 470 | function getLongDatePattern() |
471 | 471 | { |
@@ -474,8 +474,8 @@ discard block |
||
474 | 474 | |
475 | 475 | /** |
476 | 476 | * Returns the medium date pattern "yyyy MMMM d" (default). |
477 | - * This is culture sensitive. |
|
478 | - * @return string pattern "yyyy MMM d". |
|
477 | + * This is culture sensitive. |
|
478 | + * @return string pattern "yyyy MMM d". |
|
479 | 479 | */ |
480 | 480 | function getMediumDatePattern() |
481 | 481 | { |
@@ -484,28 +484,28 @@ discard block |
||
484 | 484 | |
485 | 485 | /** |
486 | 486 | * Returns the short date pattern "yy/MM/dd" (default). |
487 | - * This is culture sensitive. |
|
488 | - * @return string pattern "yy/MM/dd". |
|
487 | + * This is culture sensitive. |
|
488 | + * @return string pattern "yy/MM/dd". |
|
489 | 489 | */ |
490 | 490 | function getShortDatePattern() |
491 | 491 | { |
492 | 492 | return $this->data['DateTimePatterns'][7]; |
493 | 493 | } |
494 | 494 | |
495 | - /** |
|
496 | - * Returns the date time order pattern, "{1} {0}" (default). |
|
497 | - * This is culture sensitive. |
|
498 | - * @return string pattern "{1} {0}". |
|
499 | - */ |
|
500 | - function getDateTimeOrderPattern() |
|
501 | - { |
|
502 | - return $this->data['DateTimePatterns'][8]; |
|
503 | - } |
|
495 | + /** |
|
496 | + * Returns the date time order pattern, "{1} {0}" (default). |
|
497 | + * This is culture sensitive. |
|
498 | + * @return string pattern "{1} {0}". |
|
499 | + */ |
|
500 | + function getDateTimeOrderPattern() |
|
501 | + { |
|
502 | + return $this->data['DateTimePatterns'][8]; |
|
503 | + } |
|
504 | 504 | |
505 | 505 | /** |
506 | 506 | * Formats the date and time in a culture sensitive paterrn. |
507 | - * The default is "Date Time". |
|
508 | - * @return string date and time formated |
|
507 | + * The default is "Date Time". |
|
508 | + * @return string date and time formated |
|
509 | 509 | */ |
510 | 510 | function formatDateTime($date, $time) |
511 | 511 | { |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the CultureInfo class. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/CultureInfo.php'); |
|
23 | +require_once(dirname(__FILE__) . '/CultureInfo.php'); |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | */ |
97 | 97 | function __get($name) |
98 | 98 | { |
99 | - $getProperty = 'get'.$name; |
|
100 | - if(in_array($getProperty, $this->properties)) |
|
99 | + $getProperty = 'get' . $name; |
|
100 | + if (in_array($getProperty, $this->properties)) |
|
101 | 101 | return $this->$getProperty(); |
102 | 102 | else |
103 | - throw new Exception('Property '.$name.' does not exists.'); |
|
103 | + throw new Exception('Property ' . $name . ' does not exists.'); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | */ |
110 | 110 | function __set($name, $value) |
111 | 111 | { |
112 | - $setProperty = 'set'.$name; |
|
113 | - if(in_array($setProperty, $this->properties)) |
|
112 | + $setProperty = 'set' . $name; |
|
113 | + if (in_array($setProperty, $this->properties)) |
|
114 | 114 | $this->$setProperty($value); |
115 | 115 | else |
116 | - throw new Exception('Property '.$name.' can not be set.'); |
|
116 | + throw new Exception('Property ' . $name . ' can not be set.'); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | * @param array ICU data for date time formatting. |
126 | 126 | * @see getInstance() |
127 | 127 | */ |
128 | - function __construct($data=array()) |
|
128 | + function __construct($data = array()) |
|
129 | 129 | { |
130 | 130 | $this->properties = get_class_methods($this); |
131 | 131 | |
132 | - if(empty($data)) |
|
132 | + if (empty($data)) |
|
133 | 133 | throw new Exception('Please provide the ICU data to initialize.'); |
134 | 134 | |
135 | 135 | $this->data = $data; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | static function getInvariantInfo() |
153 | 153 | { |
154 | 154 | static $invariant; |
155 | - if($invariant === null) |
|
155 | + if ($invariant === null) |
|
156 | 156 | { |
157 | 157 | $culture = CultureInfo::getInvariantCulture(); |
158 | 158 | $invariant = $culture->getDateTimeFormat(); |
@@ -166,12 +166,12 @@ discard block |
||
166 | 166 | * @return DateTimeFormatInfo DateTimeFormatInfo for the specified |
167 | 167 | * culture. |
168 | 168 | */ |
169 | - static function getInstance($culture=null) |
|
169 | + static function getInstance($culture = null) |
|
170 | 170 | { |
171 | 171 | |
172 | 172 | if ($culture instanceof CultureInfo) |
173 | 173 | return $culture->getDateTimeFormat(); |
174 | - else if(is_string($culture)) |
|
174 | + else if (is_string($culture)) |
|
175 | 175 | { |
176 | 176 | $cultureInfo = CultureInfo::getInstance($culture); |
177 | 177 | return $cultureInfo->getDateTimeFormat(); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | function formatDateTime($date, $time) |
511 | 511 | { |
512 | 512 | $pattern = $this->getDateTimeOrderPattern(); |
513 | - return str_replace(array('{0}','{1}'), array($time, $date), $pattern); |
|
513 | + return str_replace(array('{0}', '{1}'), array($time, $date), $pattern); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | } |
@@ -175,8 +175,7 @@ |
||
175 | 175 | { |
176 | 176 | $cultureInfo = CultureInfo::getInstance($culture); |
177 | 177 | return $cultureInfo->getDateTimeFormat(); |
178 | - } |
|
179 | - else |
|
178 | + } else |
|
180 | 179 | { |
181 | 180 | $cultureInfo = CultureInfo::getInvariantCulture(); |
182 | 181 | return $cultureInfo->getDateTimeFormat(); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * _read |
87 | 87 | * |
88 | 88 | * @access private |
89 | - * @return mixed |
|
89 | + * @return string|null |
|
90 | 90 | * @param int $bytes |
91 | 91 | */ |
92 | 92 | function _read($bytes = 1) |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * Load MO file |
166 | 166 | * |
167 | 167 | * @access public |
168 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
168 | + * @return boolean Returns true on success or PEAR_Error on failure. |
|
169 | 169 | * @param string $file |
170 | 170 | */ |
171 | 171 | function load($file = null) |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * Save MO file |
262 | 262 | * |
263 | 263 | * @access public |
264 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
264 | + * @return boolean Returns true on success or PEAR_Error on failure. |
|
265 | 265 | * @param string $file |
266 | 266 | */ |
267 | 267 | function save($file = null) |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @license PHP License |
39 | 39 | */ |
40 | 40 | |
41 | -require_once dirname(__FILE__).'/TGettext.php'; |
|
41 | +require_once dirname(__FILE__) . '/TGettext.php'; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * File_Gettext_MO |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | // done |
350 | 350 | @flock($this->_handle, LOCK_UN); |
351 | 351 | @fclose($this->_handle); |
352 | - chmod($file,PRADO_CHMOD); |
|
352 | + chmod($file, PRADO_CHMOD); |
|
353 | 353 | return true; |
354 | 354 | } |
355 | 355 | } |
@@ -52,304 +52,304 @@ |
||
52 | 52 | */ |
53 | 53 | class TGettext_MO extends TGettext |
54 | 54 | { |
55 | - /** |
|
56 | - * file handle |
|
57 | - * |
|
58 | - * @access private |
|
59 | - * @var resource |
|
60 | - */ |
|
61 | - protected $_handle = null; |
|
62 | - |
|
63 | - /** |
|
64 | - * big endianess |
|
65 | - * |
|
66 | - * Whether to write with big endian byte order. |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @var bool |
|
70 | - */ |
|
71 | - protected $writeBigEndian = false; |
|
72 | - |
|
73 | - /** |
|
74 | - * Constructor |
|
75 | - * |
|
76 | - * @access public |
|
77 | - * @return object File_Gettext_MO |
|
78 | - * @param string $file path to GNU MO file |
|
79 | - */ |
|
80 | - function __construct($file = '') |
|
81 | - { |
|
82 | - $this->file = $file; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * _read |
|
87 | - * |
|
88 | - * @access private |
|
89 | - * @return mixed |
|
90 | - * @param int $bytes |
|
91 | - */ |
|
92 | - function _read($bytes = 1) |
|
93 | - { |
|
94 | - if (0 < $bytes = abs($bytes)) { |
|
95 | - return fread($this->_handle, $bytes); |
|
96 | - } |
|
97 | - return null; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * _readInt |
|
102 | - * |
|
103 | - * @access private |
|
104 | - * @return int |
|
105 | - * @param bool $bigendian |
|
106 | - */ |
|
107 | - function _readInt($bigendian = false) |
|
108 | - { |
|
55 | + /** |
|
56 | + * file handle |
|
57 | + * |
|
58 | + * @access private |
|
59 | + * @var resource |
|
60 | + */ |
|
61 | + protected $_handle = null; |
|
62 | + |
|
63 | + /** |
|
64 | + * big endianess |
|
65 | + * |
|
66 | + * Whether to write with big endian byte order. |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @var bool |
|
70 | + */ |
|
71 | + protected $writeBigEndian = false; |
|
72 | + |
|
73 | + /** |
|
74 | + * Constructor |
|
75 | + * |
|
76 | + * @access public |
|
77 | + * @return object File_Gettext_MO |
|
78 | + * @param string $file path to GNU MO file |
|
79 | + */ |
|
80 | + function __construct($file = '') |
|
81 | + { |
|
82 | + $this->file = $file; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * _read |
|
87 | + * |
|
88 | + * @access private |
|
89 | + * @return mixed |
|
90 | + * @param int $bytes |
|
91 | + */ |
|
92 | + function _read($bytes = 1) |
|
93 | + { |
|
94 | + if (0 < $bytes = abs($bytes)) { |
|
95 | + return fread($this->_handle, $bytes); |
|
96 | + } |
|
97 | + return null; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * _readInt |
|
102 | + * |
|
103 | + * @access private |
|
104 | + * @return int |
|
105 | + * @param bool $bigendian |
|
106 | + */ |
|
107 | + function _readInt($bigendian = false) |
|
108 | + { |
|
109 | 109 | //unpack returns a reference???? |
110 | 110 | $unpacked = unpack($bigendian ? 'N' : 'V', $this->_read(4)); |
111 | - return array_shift($unpacked); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * _writeInt |
|
116 | - * |
|
117 | - * @access private |
|
118 | - * @return int |
|
119 | - * @param int $int |
|
120 | - */ |
|
121 | - function _writeInt($int) |
|
122 | - { |
|
123 | - return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int)); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * _write |
|
128 | - * |
|
129 | - * @access private |
|
130 | - * @return int |
|
131 | - * @param string $data |
|
132 | - */ |
|
133 | - function _write($data) |
|
134 | - { |
|
135 | - return fwrite($this->_handle, $data); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * _writeStr |
|
140 | - * |
|
141 | - * @access private |
|
142 | - * @return int |
|
143 | - * @param string $string |
|
144 | - */ |
|
145 | - function _writeStr($string) |
|
146 | - { |
|
147 | - return $this->_write($string . "\0"); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * _readStr |
|
152 | - * |
|
153 | - * @access private |
|
154 | - * @return string |
|
155 | - * @param array $params associative array with offset and length |
|
156 | - * of the string |
|
157 | - */ |
|
158 | - function _readStr($params) |
|
159 | - { |
|
160 | - fseek($this->_handle, $params['offset']); |
|
161 | - return $this->_read($params['length']); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Load MO file |
|
166 | - * |
|
167 | - * @access public |
|
168 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
169 | - * @param string $file |
|
170 | - */ |
|
171 | - function load($file = null) |
|
172 | - { |
|
173 | - if (!isset($file)) { |
|
174 | - $file = $this->file; |
|
175 | - } |
|
176 | - |
|
177 | - // open MO file |
|
178 | - if (!is_resource($this->_handle = @fopen($file, 'rb'))) { |
|
179 | - return false; |
|
180 | - } |
|
181 | - // lock MO file shared |
|
182 | - if (!@flock($this->_handle, LOCK_SH)) { |
|
183 | - @fclose($this->_handle); |
|
184 | - return false; |
|
185 | - } |
|
186 | - |
|
187 | - // read (part of) magic number from MO file header and define endianess |
|
111 | + return array_shift($unpacked); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * _writeInt |
|
116 | + * |
|
117 | + * @access private |
|
118 | + * @return int |
|
119 | + * @param int $int |
|
120 | + */ |
|
121 | + function _writeInt($int) |
|
122 | + { |
|
123 | + return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int)); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * _write |
|
128 | + * |
|
129 | + * @access private |
|
130 | + * @return int |
|
131 | + * @param string $data |
|
132 | + */ |
|
133 | + function _write($data) |
|
134 | + { |
|
135 | + return fwrite($this->_handle, $data); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * _writeStr |
|
140 | + * |
|
141 | + * @access private |
|
142 | + * @return int |
|
143 | + * @param string $string |
|
144 | + */ |
|
145 | + function _writeStr($string) |
|
146 | + { |
|
147 | + return $this->_write($string . "\0"); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * _readStr |
|
152 | + * |
|
153 | + * @access private |
|
154 | + * @return string |
|
155 | + * @param array $params associative array with offset and length |
|
156 | + * of the string |
|
157 | + */ |
|
158 | + function _readStr($params) |
|
159 | + { |
|
160 | + fseek($this->_handle, $params['offset']); |
|
161 | + return $this->_read($params['length']); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Load MO file |
|
166 | + * |
|
167 | + * @access public |
|
168 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
169 | + * @param string $file |
|
170 | + */ |
|
171 | + function load($file = null) |
|
172 | + { |
|
173 | + if (!isset($file)) { |
|
174 | + $file = $this->file; |
|
175 | + } |
|
176 | + |
|
177 | + // open MO file |
|
178 | + if (!is_resource($this->_handle = @fopen($file, 'rb'))) { |
|
179 | + return false; |
|
180 | + } |
|
181 | + // lock MO file shared |
|
182 | + if (!@flock($this->_handle, LOCK_SH)) { |
|
183 | + @fclose($this->_handle); |
|
184 | + return false; |
|
185 | + } |
|
186 | + |
|
187 | + // read (part of) magic number from MO file header and define endianess |
|
188 | 188 | |
189 | 189 | //unpack returns a reference???? |
190 | 190 | $unpacked = unpack('c', $this->_read(4)); |
191 | - switch ($magic = array_shift($unpacked)) |
|
192 | - { |
|
193 | - case -34: |
|
194 | - $be = false; |
|
195 | - break; |
|
196 | - |
|
197 | - case -107: |
|
198 | - $be = true; |
|
199 | - break; |
|
200 | - |
|
201 | - default: |
|
202 | - return false; |
|
203 | - } |
|
204 | - |
|
205 | - // check file format revision - we currently only support 0 |
|
206 | - if (0 !== ($_rev = $this->_readInt($be))) { |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - // count of strings in this file |
|
211 | - $count = $this->_readInt($be); |
|
212 | - |
|
213 | - // offset of hashing table of the msgids |
|
214 | - $offset_original = $this->_readInt($be); |
|
215 | - // offset of hashing table of the msgstrs |
|
216 | - $offset_translat = $this->_readInt($be); |
|
217 | - |
|
218 | - // move to msgid hash table |
|
219 | - fseek($this->_handle, $offset_original); |
|
220 | - // read lengths and offsets of msgids |
|
221 | - $original = array(); |
|
222 | - for ($i = 0; $i < $count; $i++) { |
|
223 | - $original[$i] = array( |
|
224 | - 'length' => $this->_readInt($be), |
|
225 | - 'offset' => $this->_readInt($be) |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - // move to msgstr hash table |
|
230 | - fseek($this->_handle, $offset_translat); |
|
231 | - // read lengths and offsets of msgstrs |
|
232 | - $translat = array(); |
|
233 | - for ($i = 0; $i < $count; $i++) { |
|
234 | - $translat[$i] = array( |
|
235 | - 'length' => $this->_readInt($be), |
|
236 | - 'offset' => $this->_readInt($be) |
|
237 | - ); |
|
238 | - } |
|
239 | - |
|
240 | - // read all |
|
241 | - for ($i = 0; $i < $count; $i++) { |
|
242 | - $this->strings[$this->_readStr($original[$i])] = |
|
243 | - $this->_readStr($translat[$i]); |
|
244 | - } |
|
245 | - |
|
246 | - // done |
|
247 | - @flock($this->_handle, LOCK_UN); |
|
248 | - @fclose($this->_handle); |
|
249 | - $this->_handle = null; |
|
250 | - |
|
251 | - // check for meta info |
|
252 | - if (isset($this->strings[''])) { |
|
253 | - $this->meta = parent::meta2array($this->strings['']); |
|
254 | - unset($this->strings['']); |
|
255 | - } |
|
256 | - |
|
257 | - return true; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Save MO file |
|
262 | - * |
|
263 | - * @access public |
|
264 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
265 | - * @param string $file |
|
266 | - */ |
|
267 | - function save($file = null) |
|
268 | - { |
|
269 | - if (!isset($file)) { |
|
270 | - $file = $this->file; |
|
271 | - } |
|
272 | - |
|
273 | - // open MO file |
|
274 | - if (!is_resource($this->_handle = @fopen($file, 'wb'))) { |
|
275 | - return false; |
|
276 | - } |
|
277 | - // lock MO file exclusively |
|
278 | - if (!@flock($this->_handle, LOCK_EX)) { |
|
279 | - @fclose($this->_handle); |
|
280 | - return false; |
|
281 | - } |
|
282 | - |
|
283 | - // write magic number |
|
284 | - if ($this->writeBigEndian) { |
|
285 | - $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde)); |
|
286 | - } else { |
|
287 | - $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95)); |
|
288 | - } |
|
289 | - |
|
290 | - // write file format revision |
|
291 | - $this->_writeInt(0); |
|
292 | - |
|
293 | - $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0)); |
|
294 | - // write count of strings |
|
295 | - $this->_writeInt($count); |
|
296 | - |
|
297 | - $offset = 28; |
|
298 | - // write offset of orig. strings hash table |
|
299 | - $this->_writeInt($offset); |
|
300 | - |
|
301 | - $offset += ($count * 8); |
|
302 | - // write offset transl. strings hash table |
|
303 | - $this->_writeInt($offset); |
|
304 | - |
|
305 | - // write size of hash table (we currently ommit the hash table) |
|
306 | - $this->_writeInt(0); |
|
307 | - |
|
308 | - $offset += ($count * 8); |
|
309 | - // write offset of hash table |
|
310 | - $this->_writeInt($offset); |
|
311 | - |
|
312 | - // unshift meta info |
|
313 | - if ($this->meta) { |
|
314 | - $meta = ''; |
|
315 | - foreach ($this->meta as $key => $val) { |
|
316 | - $meta .= $key . ': ' . $val . "\n"; |
|
317 | - } |
|
318 | - $strings = array('' => $meta) + $this->strings; |
|
319 | - } else { |
|
320 | - $strings = $this->strings; |
|
321 | - } |
|
322 | - |
|
323 | - // write offsets for original strings |
|
324 | - foreach (array_keys($strings) as $o) { |
|
325 | - $len = strlen($o); |
|
326 | - $this->_writeInt($len); |
|
327 | - $this->_writeInt($offset); |
|
328 | - $offset += $len + 1; |
|
329 | - } |
|
330 | - |
|
331 | - // write offsets for translated strings |
|
332 | - foreach ($strings as $t) { |
|
333 | - $len = strlen($t); |
|
334 | - $this->_writeInt($len); |
|
335 | - $this->_writeInt($offset); |
|
336 | - $offset += $len + 1; |
|
337 | - } |
|
338 | - |
|
339 | - // write original strings |
|
340 | - foreach (array_keys($strings) as $o) { |
|
341 | - $this->_writeStr($o); |
|
342 | - } |
|
343 | - |
|
344 | - // write translated strings |
|
345 | - foreach ($strings as $t) { |
|
346 | - $this->_writeStr($t); |
|
347 | - } |
|
348 | - |
|
349 | - // done |
|
350 | - @flock($this->_handle, LOCK_UN); |
|
351 | - @fclose($this->_handle); |
|
352 | - chmod($file,PRADO_CHMOD); |
|
353 | - return true; |
|
354 | - } |
|
191 | + switch ($magic = array_shift($unpacked)) |
|
192 | + { |
|
193 | + case -34: |
|
194 | + $be = false; |
|
195 | + break; |
|
196 | + |
|
197 | + case -107: |
|
198 | + $be = true; |
|
199 | + break; |
|
200 | + |
|
201 | + default: |
|
202 | + return false; |
|
203 | + } |
|
204 | + |
|
205 | + // check file format revision - we currently only support 0 |
|
206 | + if (0 !== ($_rev = $this->_readInt($be))) { |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + // count of strings in this file |
|
211 | + $count = $this->_readInt($be); |
|
212 | + |
|
213 | + // offset of hashing table of the msgids |
|
214 | + $offset_original = $this->_readInt($be); |
|
215 | + // offset of hashing table of the msgstrs |
|
216 | + $offset_translat = $this->_readInt($be); |
|
217 | + |
|
218 | + // move to msgid hash table |
|
219 | + fseek($this->_handle, $offset_original); |
|
220 | + // read lengths and offsets of msgids |
|
221 | + $original = array(); |
|
222 | + for ($i = 0; $i < $count; $i++) { |
|
223 | + $original[$i] = array( |
|
224 | + 'length' => $this->_readInt($be), |
|
225 | + 'offset' => $this->_readInt($be) |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + // move to msgstr hash table |
|
230 | + fseek($this->_handle, $offset_translat); |
|
231 | + // read lengths and offsets of msgstrs |
|
232 | + $translat = array(); |
|
233 | + for ($i = 0; $i < $count; $i++) { |
|
234 | + $translat[$i] = array( |
|
235 | + 'length' => $this->_readInt($be), |
|
236 | + 'offset' => $this->_readInt($be) |
|
237 | + ); |
|
238 | + } |
|
239 | + |
|
240 | + // read all |
|
241 | + for ($i = 0; $i < $count; $i++) { |
|
242 | + $this->strings[$this->_readStr($original[$i])] = |
|
243 | + $this->_readStr($translat[$i]); |
|
244 | + } |
|
245 | + |
|
246 | + // done |
|
247 | + @flock($this->_handle, LOCK_UN); |
|
248 | + @fclose($this->_handle); |
|
249 | + $this->_handle = null; |
|
250 | + |
|
251 | + // check for meta info |
|
252 | + if (isset($this->strings[''])) { |
|
253 | + $this->meta = parent::meta2array($this->strings['']); |
|
254 | + unset($this->strings['']); |
|
255 | + } |
|
256 | + |
|
257 | + return true; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Save MO file |
|
262 | + * |
|
263 | + * @access public |
|
264 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
265 | + * @param string $file |
|
266 | + */ |
|
267 | + function save($file = null) |
|
268 | + { |
|
269 | + if (!isset($file)) { |
|
270 | + $file = $this->file; |
|
271 | + } |
|
272 | + |
|
273 | + // open MO file |
|
274 | + if (!is_resource($this->_handle = @fopen($file, 'wb'))) { |
|
275 | + return false; |
|
276 | + } |
|
277 | + // lock MO file exclusively |
|
278 | + if (!@flock($this->_handle, LOCK_EX)) { |
|
279 | + @fclose($this->_handle); |
|
280 | + return false; |
|
281 | + } |
|
282 | + |
|
283 | + // write magic number |
|
284 | + if ($this->writeBigEndian) { |
|
285 | + $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde)); |
|
286 | + } else { |
|
287 | + $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95)); |
|
288 | + } |
|
289 | + |
|
290 | + // write file format revision |
|
291 | + $this->_writeInt(0); |
|
292 | + |
|
293 | + $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0)); |
|
294 | + // write count of strings |
|
295 | + $this->_writeInt($count); |
|
296 | + |
|
297 | + $offset = 28; |
|
298 | + // write offset of orig. strings hash table |
|
299 | + $this->_writeInt($offset); |
|
300 | + |
|
301 | + $offset += ($count * 8); |
|
302 | + // write offset transl. strings hash table |
|
303 | + $this->_writeInt($offset); |
|
304 | + |
|
305 | + // write size of hash table (we currently ommit the hash table) |
|
306 | + $this->_writeInt(0); |
|
307 | + |
|
308 | + $offset += ($count * 8); |
|
309 | + // write offset of hash table |
|
310 | + $this->_writeInt($offset); |
|
311 | + |
|
312 | + // unshift meta info |
|
313 | + if ($this->meta) { |
|
314 | + $meta = ''; |
|
315 | + foreach ($this->meta as $key => $val) { |
|
316 | + $meta .= $key . ': ' . $val . "\n"; |
|
317 | + } |
|
318 | + $strings = array('' => $meta) + $this->strings; |
|
319 | + } else { |
|
320 | + $strings = $this->strings; |
|
321 | + } |
|
322 | + |
|
323 | + // write offsets for original strings |
|
324 | + foreach (array_keys($strings) as $o) { |
|
325 | + $len = strlen($o); |
|
326 | + $this->_writeInt($len); |
|
327 | + $this->_writeInt($offset); |
|
328 | + $offset += $len + 1; |
|
329 | + } |
|
330 | + |
|
331 | + // write offsets for translated strings |
|
332 | + foreach ($strings as $t) { |
|
333 | + $len = strlen($t); |
|
334 | + $this->_writeInt($len); |
|
335 | + $this->_writeInt($offset); |
|
336 | + $offset += $len + 1; |
|
337 | + } |
|
338 | + |
|
339 | + // write original strings |
|
340 | + foreach (array_keys($strings) as $o) { |
|
341 | + $this->_writeStr($o); |
|
342 | + } |
|
343 | + |
|
344 | + // write translated strings |
|
345 | + foreach ($strings as $t) { |
|
346 | + $this->_writeStr($t); |
|
347 | + } |
|
348 | + |
|
349 | + // done |
|
350 | + @flock($this->_handle, LOCK_UN); |
|
351 | + @fclose($this->_handle); |
|
352 | + chmod($file,PRADO_CHMOD); |
|
353 | + return true; |
|
354 | + } |
|
355 | 355 | } |