@@ -163,6 +163,7 @@ |
||
163 | 163 | /** |
164 | 164 | * Creates the DB connection. |
165 | 165 | * @param string the module ID for TDataSourceConfig |
166 | + * @param string $connectionID |
|
166 | 167 | * @return TDbConnection the created DB connection |
167 | 168 | * @throws TConfigurationException if module ID is invalid or empty |
168 | 169 | */ |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | { |
64 | 64 | if($this->_userClass==='') |
65 | 65 | throw new TConfigurationException('dbusermanager_userclass_required'); |
66 | - $this->_userFactory=Prado::createComponent($this->_userClass,$this); |
|
66 | + $this->_userFactory=Prado::createComponent($this->_userClass, $this); |
|
67 | 67 | if(!($this->_userFactory instanceof TDbUser)) |
68 | - throw new TInvalidDataTypeException('dbusermanager_userclass_invalid',$this->_userClass); |
|
68 | + throw new TInvalidDataTypeException('dbusermanager_userclass_invalid', $this->_userClass); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param string password |
107 | 107 | * @return boolean true if validation is successful, false otherwise. |
108 | 108 | */ |
109 | - public function validateUser($username,$password) |
|
109 | + public function validateUser($username, $password) |
|
110 | 110 | { |
111 | - return $this->_userFactory->validateUser($username,$password); |
|
111 | + return $this->_userFactory->validateUser($username, $password); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | if($username===null) |
122 | 122 | { |
123 | - $user=Prado::createComponent($this->_userClass,$this); |
|
123 | + $user=Prado::createComponent($this->_userClass, $this); |
|
124 | 124 | $user->setIsGuest(true); |
125 | 125 | return $user; |
126 | 126 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | if($conn instanceof TDataSourceConfig) |
175 | 175 | return $conn->getDbConnection(); |
176 | 176 | else |
177 | - throw new TConfigurationException('dbusermanager_connectionid_invalid',$connectionID); |
|
177 | + throw new TConfigurationException('dbusermanager_connectionid_invalid', $connectionID); |
|
178 | 178 | } |
179 | 179 | else |
180 | 180 | throw new TConfigurationException('dbusermanager_connectionid_required'); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @param string password |
256 | 256 | * @return boolean whether the validation succeeds |
257 | 257 | */ |
258 | - abstract public function validateUser($username,$password); |
|
258 | + abstract public function validateUser($username, $password); |
|
259 | 259 | |
260 | 260 | /** |
261 | 261 | * Creates a new user instance given the username. |
@@ -189,8 +189,7 @@ discard block |
||
189 | 189 | return file_put_contents($fileName,file_get_contents($this->_localName))!==false; |
190 | 190 | else |
191 | 191 | return false; |
192 | - } |
|
193 | - else |
|
192 | + } else |
|
194 | 193 | return false; |
195 | 194 | } |
196 | 195 | |
@@ -211,8 +210,7 @@ discard block |
||
211 | 210 | $this->_errorCode=$_FILES[$key]['error']; |
212 | 211 | $this->_localName=$_FILES[$key]['tmp_name']; |
213 | 212 | return $this->_dataChanged=true; |
214 | - } |
|
215 | - else |
|
213 | + } else |
|
216 | 214 | return false; |
217 | 215 | } |
218 | 216 |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TDbUserManager class |
|
4 | - * |
|
5 | - * @author Qiang Xue <[email protected]> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2016 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Security |
|
10 | - */ |
|
3 | + * TDbUserManager class |
|
4 | + * |
|
5 | + * @author Qiang Xue <[email protected]> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2016 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Security |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Using IUserManager interface |
@@ -342,6 +342,7 @@ discard block |
||
342 | 342 | * to determine the application configuration file, |
343 | 343 | * application root path and the runtime path. |
344 | 344 | * @param string the application root path or the application configuration file |
345 | + * @param string $basePath |
|
345 | 346 | * @see setBasePath |
346 | 347 | * @see setRuntimePath |
347 | 348 | * @see setConfigurationFile |
@@ -440,6 +441,7 @@ discard block |
||
440 | 441 | * A global value is one that is persistent across users sessions and requests. |
441 | 442 | * @param string the name of the value to be returned |
442 | 443 | * @param mixed the default value. If $key is not found, $defaultValue will be returned |
444 | + * @param integer $defaultValue |
|
443 | 445 | * @return mixed the global value corresponding to $key |
444 | 446 | */ |
445 | 447 | public function getGlobalState($key,$defaultValue=null) |
@@ -456,6 +458,7 @@ discard block |
||
456 | 458 | * @param mixed the global value to be set |
457 | 459 | * @param mixed the default value. If $key is not found, $defaultValue will be returned |
458 | 460 | * @param boolean wheter to force an immediate GlobalState save. defaults to false |
461 | + * @param string $key |
|
459 | 462 | */ |
460 | 463 | public function setGlobalState($key,$value,$defaultValue=null,$forceSave=false) |
461 | 464 | { |
@@ -545,7 +548,7 @@ discard block |
||
545 | 548 | } |
546 | 549 | |
547 | 550 | /** |
548 | - * @return TApplicationMode application mode. Defaults to TApplicationMode::Debug. |
|
551 | + * @return string application mode. Defaults to TApplicationMode::Debug. |
|
549 | 552 | */ |
550 | 553 | public function getMode() |
551 | 554 | { |
@@ -570,6 +573,7 @@ discard block |
||
570 | 573 | |
571 | 574 | /** |
572 | 575 | * @param string the directory containing the application configuration file |
576 | + * @param string $value |
|
573 | 577 | */ |
574 | 578 | public function setBasePath($value) |
575 | 579 | { |
@@ -586,6 +590,7 @@ discard block |
||
586 | 590 | |
587 | 591 | /** |
588 | 592 | * @param string the application configuration file (absolute path) |
593 | + * @param string $value |
|
589 | 594 | */ |
590 | 595 | public function setConfigurationFile($value) |
591 | 596 | { |
@@ -602,6 +607,7 @@ discard block |
||
602 | 607 | |
603 | 608 | /** |
604 | 609 | * @param string the application configuration type. 'xml' and 'php' are valid values |
610 | + * @param string $value |
|
605 | 611 | */ |
606 | 612 | public function setConfigurationType($value) |
607 | 613 | { |
@@ -657,6 +663,7 @@ discard block |
||
657 | 663 | |
658 | 664 | /** |
659 | 665 | * @param string the directory storing cache data and application-level persistent data. (absolute path) |
666 | + * @param string $value |
|
660 | 667 | */ |
661 | 668 | public function setRuntimePath($value) |
662 | 669 | { |
@@ -677,6 +684,7 @@ discard block |
||
677 | 684 | |
678 | 685 | /** |
679 | 686 | * @param IService the currently requested service |
687 | + * @param IService $value |
|
680 | 688 | */ |
681 | 689 | public function setService($value) |
682 | 690 | { |
@@ -1126,6 +1134,7 @@ discard block |
||
1126 | 1134 | * This method is invoked when an exception is raised during the lifecycles |
1127 | 1135 | * of the application. |
1128 | 1136 | * @param mixed event parameter |
1137 | + * @param Exception $param |
|
1129 | 1138 | */ |
1130 | 1139 | public function onError($param) |
1131 | 1140 | { |
@@ -602,7 +602,7 @@ |
||
602 | 602 | |
603 | 603 | /** |
604 | 604 | * @param string the application configuration type. 'xml' and 'php' are valid values |
605 | - */ |
|
605 | + */ |
|
606 | 606 | public function setConfigurationType($value) |
607 | 607 | { |
608 | 608 | $this->_configType = $value; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | /** |
134 | 134 | * Configuration file type, application.xml and config.xml |
135 | 135 | */ |
136 | - const CONFIG_TYPE_XML = 'xml'; |
|
136 | + const CONFIG_TYPE_XML='xml'; |
|
137 | 137 | /** |
138 | 138 | * Application configuration file name |
139 | 139 | */ |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * Configuration file type, application.php and config.php |
147 | 147 | */ |
148 | - const CONFIG_TYPE_PHP = 'php'; |
|
148 | + const CONFIG_TYPE_PHP='php'; |
|
149 | 149 | /** |
150 | 150 | * Runtime directory name |
151 | 151 | */ |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | /** |
299 | 299 | * @var string Customizable page service ID |
300 | 300 | */ |
301 | - private $_pageServiceID = self::PAGE_SERVICE_ID; |
|
301 | + private $_pageServiceID=self::PAGE_SERVICE_ID; |
|
302 | 302 | |
303 | 303 | /** |
304 | 304 | * Constructor. |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | * @param boolean whether to cache application configuration. Defaults to true. |
319 | 319 | * @throws TConfigurationException if configuration file cannot be read or the runtime path is invalid. |
320 | 320 | */ |
321 | - public function __construct($basePath='protected',$cacheConfig=true, $configType=self::CONFIG_TYPE_XML) |
|
321 | + public function __construct($basePath='protected', $cacheConfig=true, $configType=self::CONFIG_TYPE_XML) |
|
322 | 322 | { |
323 | 323 | // register application as a singleton |
324 | 324 | Prado::setApplication($this); |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | // generates unique ID by hashing the runtime path |
332 | 332 | $this->_uniqueID=md5($this->_runtimePath); |
333 | 333 | $this->_parameters=new TMap; |
334 | - $this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null)); |
|
334 | + $this->_services=array($this->getPageServiceID()=>array('TPageService', array(), null)); |
|
335 | 335 | |
336 | - Prado::setPathOfAlias('Application',$this->_basePath); |
|
336 | + Prado::setPathOfAlias('Application', $this->_basePath); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | { |
351 | 351 | // determine configuration path and file |
352 | 352 | if(empty($basePath) || ($basePath=realpath($basePath))===false) |
353 | - throw new TConfigurationException('application_basepath_invalid',$basePath); |
|
353 | + throw new TConfigurationException('application_basepath_invalid', $basePath); |
|
354 | 354 | if(is_dir($basePath) && is_file($basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName())) |
355 | 355 | $configFile=$basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName(); |
356 | 356 | else if(is_file($basePath)) |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | if(!is_dir($runtimePath)) |
372 | 372 | { |
373 | 373 | if(@mkdir($runtimePath)===false) |
374 | - throw new TConfigurationException('application_runtimepath_failed',$runtimePath); |
|
374 | + throw new TConfigurationException('application_runtimepath_failed', $runtimePath); |
|
375 | 375 | @chmod($runtimePath, PRADO_CHMOD); //make it deletable |
376 | 376 | } |
377 | 377 | $this->setConfigurationFile($configFile); |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | $this->setRuntimePath($runtimePath); |
381 | 381 | } |
382 | 382 | else |
383 | - throw new TConfigurationException('application_runtimepath_invalid',$runtimePath); |
|
383 | + throw new TConfigurationException('application_runtimepath_invalid', $runtimePath); |
|
384 | 384 | |
385 | 385 | } |
386 | 386 | |
@@ -397,14 +397,14 @@ discard block |
||
397 | 397 | $n=count(self::$_steps); |
398 | 398 | $this->_step=0; |
399 | 399 | $this->_requestCompleted=false; |
400 | - while($this->_step<$n) |
|
400 | + while($this->_step < $n) |
|
401 | 401 | { |
402 | 402 | if($this->_mode===self::STATE_OFF) |
403 | - throw new THttpException(503,'application_unavailable'); |
|
403 | + throw new THttpException(503, 'application_unavailable'); |
|
404 | 404 | if($this->_requestCompleted) |
405 | 405 | break; |
406 | 406 | $method=self::$_steps[$this->_step]; |
407 | - Prado::trace("Executing $method()",'System.TApplication'); |
|
407 | + Prado::trace("Executing $method()", 'System.TApplication'); |
|
408 | 408 | $this->$method(); |
409 | 409 | $this->_step++; |
410 | 410 | } |
@@ -442,9 +442,9 @@ discard block |
||
442 | 442 | * @param mixed the default value. If $key is not found, $defaultValue will be returned |
443 | 443 | * @return mixed the global value corresponding to $key |
444 | 444 | */ |
445 | - public function getGlobalState($key,$defaultValue=null) |
|
445 | + public function getGlobalState($key, $defaultValue=null) |
|
446 | 446 | { |
447 | - return isset($this->_globals[$key])?$this->_globals[$key]:$defaultValue; |
|
447 | + return isset($this->_globals[$key]) ? $this->_globals[$key] : $defaultValue; |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @param mixed the default value. If $key is not found, $defaultValue will be returned |
458 | 458 | * @param boolean wheter to force an immediate GlobalState save. defaults to false |
459 | 459 | */ |
460 | - public function setGlobalState($key,$value,$defaultValue=null,$forceSave=false) |
|
460 | + public function setGlobalState($key, $value, $defaultValue=null, $forceSave=false) |
|
461 | 461 | { |
462 | 462 | $this->_stateChanged=true; |
463 | 463 | if($value===$defaultValue) |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | */ |
558 | 558 | public function setMode($value) |
559 | 559 | { |
560 | - $this->_mode=TPropertyValue::ensureEnum($value,'TApplicationMode'); |
|
560 | + $this->_mode=TPropertyValue::ensureEnum($value, 'TApplicationMode'); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | */ |
606 | 606 | public function setConfigurationType($value) |
607 | 607 | { |
608 | - $this->_configType = $value; |
|
608 | + $this->_configType=$value; |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | /** |
@@ -618,10 +618,10 @@ discard block |
||
618 | 618 | switch($this->_configType) |
619 | 619 | { |
620 | 620 | case TApplication::CONFIG_TYPE_PHP: |
621 | - $this->_configFileExt = TApplication::CONFIG_FILE_EXT_PHP; |
|
621 | + $this->_configFileExt=TApplication::CONFIG_FILE_EXT_PHP; |
|
622 | 622 | break; |
623 | 623 | default: |
624 | - $this->_configFileExt = TApplication::CONFIG_FILE_EXT_XML; |
|
624 | + $this->_configFileExt=TApplication::CONFIG_FILE_EXT_XML; |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 | return $this->_configFileExt; |
@@ -633,15 +633,15 @@ discard block |
||
633 | 633 | public function getConfigurationFileName() |
634 | 634 | { |
635 | 635 | static $fileName; |
636 | - if($fileName == null) |
|
636 | + if($fileName==null) |
|
637 | 637 | { |
638 | 638 | switch($this->_configType) |
639 | 639 | { |
640 | 640 | case TApplication::CONFIG_TYPE_PHP: |
641 | - $fileName = TApplication::CONFIG_FILE_PHP; |
|
641 | + $fileName=TApplication::CONFIG_FILE_PHP; |
|
642 | 642 | break; |
643 | 643 | default: |
644 | - $fileName = TApplication::CONFIG_FILE_XML; |
|
644 | + $fileName=TApplication::CONFIG_FILE_XML; |
|
645 | 645 | } |
646 | 646 | } |
647 | 647 | return $fileName; |
@@ -689,10 +689,10 @@ discard block |
||
689 | 689 | * @param string ID of the module |
690 | 690 | * @param IModule module object or null if the module has not been loaded yet |
691 | 691 | */ |
692 | - public function setModule($id,IModule $module=null) |
|
692 | + public function setModule($id, IModule $module=null) |
|
693 | 693 | { |
694 | 694 | if(isset($this->_modules[$id])) |
695 | - throw new TConfigurationException('application_moduleid_duplicated',$id); |
|
695 | + throw new TConfigurationException('application_moduleid_duplicated', $id); |
|
696 | 696 | else |
697 | 697 | $this->_modules[$id]=$module; |
698 | 698 | } |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | // force loading of a lazy module |
709 | 709 | if($this->_modules[$id]===null) |
710 | 710 | { |
711 | - $module = $this->internalLoadModule($id, true); |
|
711 | + $module=$this->internalLoadModule($id, true); |
|
712 | 712 | $module[0]->init($module[1]); |
713 | 713 | } |
714 | 714 | |
@@ -957,37 +957,37 @@ discard block |
||
957 | 957 | list($moduleClass, $initProperties, $configElement)=$this->_lazyModules[$id]; |
958 | 958 | if(isset($initProperties['lazy']) && $initProperties['lazy'] && !$force) |
959 | 959 | { |
960 | - Prado::trace("Postponed loading of lazy module $id ({$moduleClass})",'System.TApplication'); |
|
960 | + Prado::trace("Postponed loading of lazy module $id ({$moduleClass})", 'System.TApplication'); |
|
961 | 961 | $this->setModule($id, null); |
962 | 962 | return null; |
963 | 963 | } |
964 | 964 | |
965 | - Prado::trace("Loading module $id ({$moduleClass})",'System.TApplication'); |
|
965 | + Prado::trace("Loading module $id ({$moduleClass})", 'System.TApplication'); |
|
966 | 966 | $module=Prado::createComponent($moduleClass); |
967 | 967 | foreach($initProperties as $name=>$value) |
968 | 968 | { |
969 | 969 | if($name==='lazy') continue; |
970 | - $module->setSubProperty($name,$value); |
|
970 | + $module->setSubProperty($name, $value); |
|
971 | 971 | } |
972 | - $this->setModule($id,$module); |
|
972 | + $this->setModule($id, $module); |
|
973 | 973 | // keep the key to avoid reuse of the old module id |
974 | 974 | $this->_lazyModules[$id]=null; |
975 | 975 | |
976 | - return array($module,$configElement); |
|
976 | + return array($module, $configElement); |
|
977 | 977 | } |
978 | 978 | /** |
979 | 979 | * Applies an application configuration. |
980 | 980 | * @param TApplicationConfiguration the configuration |
981 | 981 | * @param boolean whether the configuration is specified within a service. |
982 | 982 | */ |
983 | - public function applyConfiguration($config,$withinService=false) |
|
983 | + public function applyConfiguration($config, $withinService=false) |
|
984 | 984 | { |
985 | 985 | if($config->getIsEmpty()) |
986 | 986 | return; |
987 | 987 | |
988 | 988 | // set path aliases and using namespaces |
989 | 989 | foreach($config->getAliases() as $alias=>$path) |
990 | - Prado::setPathOfAlias($alias,$path); |
|
990 | + Prado::setPathOfAlias($alias, $path); |
|
991 | 991 | foreach($config->getUsings() as $using) |
992 | 992 | Prado::using($using); |
993 | 993 | |
@@ -995,11 +995,11 @@ discard block |
||
995 | 995 | if(!$withinService) |
996 | 996 | { |
997 | 997 | foreach($config->getProperties() as $name=>$value) |
998 | - $this->setSubProperty($name,$value); |
|
998 | + $this->setSubProperty($name, $value); |
|
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | if(empty($this->_services)) |
1002 | - $this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null)); |
|
1002 | + $this->_services=array($this->getPageServiceID()=>array('TPageService', array(), null)); |
|
1003 | 1003 | |
1004 | 1004 | // load parameters |
1005 | 1005 | foreach($config->getParameters() as $id=>$parameter) |
@@ -1008,11 +1008,11 @@ discard block |
||
1008 | 1008 | { |
1009 | 1009 | $component=Prado::createComponent($parameter[0]); |
1010 | 1010 | foreach($parameter[1] as $name=>$value) |
1011 | - $component->setSubProperty($name,$value); |
|
1012 | - $this->_parameters->add($id,$component); |
|
1011 | + $component->setSubProperty($name, $value); |
|
1012 | + $this->_parameters->add($id, $component); |
|
1013 | 1013 | } |
1014 | 1014 | else |
1015 | - $this->_parameters->add($id,$parameter); |
|
1015 | + $this->_parameters->add($id, $parameter); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | // load and init modules specified in app config |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | if(!is_string($id)) |
1023 | 1023 | $id='_module'.count($this->_lazyModules); |
1024 | 1024 | $this->_lazyModules[$id]=$moduleConfig; |
1025 | - if($module = $this->internalLoadModule($id)) |
|
1025 | + if($module=$this->internalLoadModule($id)) |
|
1026 | 1026 | $modules[]=$module; |
1027 | 1027 | } |
1028 | 1028 | foreach($modules as $module) |
@@ -1039,12 +1039,12 @@ discard block |
||
1039 | 1039 | $condition=$this->evaluateExpression($condition); |
1040 | 1040 | if($condition) |
1041 | 1041 | { |
1042 | - if(($path=Prado::getPathOfNamespace($filePath,$this->getConfigurationFileExt()))===null || !is_file($path)) |
|
1043 | - throw new TConfigurationException('application_includefile_invalid',$filePath); |
|
1042 | + if(($path=Prado::getPathOfNamespace($filePath, $this->getConfigurationFileExt()))===null || !is_file($path)) |
|
1043 | + throw new TConfigurationException('application_includefile_invalid', $filePath); |
|
1044 | 1044 | $cn=$this->getApplicationConfigurationClass(); |
1045 | 1045 | $c=new $cn; |
1046 | 1046 | $c->loadFromFile($path); |
1047 | - $this->applyConfiguration($c,$withinService); |
|
1047 | + $this->applyConfiguration($c, $withinService); |
|
1048 | 1048 | } |
1049 | 1049 | } |
1050 | 1050 | } |
@@ -1060,21 +1060,21 @@ discard block |
||
1060 | 1060 | */ |
1061 | 1061 | protected function initApplication() |
1062 | 1062 | { |
1063 | - Prado::trace('Initializing application','System.TApplication'); |
|
1063 | + Prado::trace('Initializing application', 'System.TApplication'); |
|
1064 | 1064 | |
1065 | 1065 | if($this->_configFile!==null) |
1066 | 1066 | { |
1067 | - if($this->_cacheFile===null || @filemtime($this->_cacheFile)<filemtime($this->_configFile)) |
|
1067 | + if($this->_cacheFile===null || @filemtime($this->_cacheFile) < filemtime($this->_configFile)) |
|
1068 | 1068 | { |
1069 | 1069 | $config=new TApplicationConfiguration; |
1070 | 1070 | $config->loadFromFile($this->_configFile); |
1071 | 1071 | if($this->_cacheFile!==null) |
1072 | - file_put_contents($this->_cacheFile,serialize($config),LOCK_EX); |
|
1072 | + file_put_contents($this->_cacheFile, serialize($config), LOCK_EX); |
|
1073 | 1073 | } |
1074 | 1074 | else |
1075 | 1075 | $config=unserialize(file_get_contents($this->_cacheFile)); |
1076 | 1076 | |
1077 | - $this->applyConfiguration($config,false); |
|
1077 | + $this->applyConfiguration($config, false); |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | if(($serviceID=$this->getRequest()->resolveRequest(array_keys($this->_services)))===null) |
@@ -1093,32 +1093,32 @@ discard block |
||
1093 | 1093 | { |
1094 | 1094 | if(isset($this->_services[$serviceID])) |
1095 | 1095 | { |
1096 | - list($serviceClass,$initProperties,$configElement)=$this->_services[$serviceID]; |
|
1096 | + list($serviceClass, $initProperties, $configElement)=$this->_services[$serviceID]; |
|
1097 | 1097 | $service=Prado::createComponent($serviceClass); |
1098 | 1098 | if(!($service instanceof IService)) |
1099 | - throw new THttpException(500,'application_service_invalid',$serviceClass); |
|
1099 | + throw new THttpException(500, 'application_service_invalid', $serviceClass); |
|
1100 | 1100 | if(!$service->getEnabled()) |
1101 | - throw new THttpException(500,'application_service_unavailable',$serviceClass); |
|
1101 | + throw new THttpException(500, 'application_service_unavailable', $serviceClass); |
|
1102 | 1102 | $service->setID($serviceID); |
1103 | 1103 | $this->setService($service); |
1104 | 1104 | |
1105 | 1105 | foreach($initProperties as $name=>$value) |
1106 | - $service->setSubProperty($name,$value); |
|
1106 | + $service->setSubProperty($name, $value); |
|
1107 | 1107 | |
1108 | 1108 | if($configElement!==null) |
1109 | 1109 | { |
1110 | 1110 | $config=new TApplicationConfiguration; |
1111 | 1111 | if($this->getConfigurationType()==self::CONFIG_TYPE_PHP) |
1112 | - $config->loadFromPhp($configElement,$this->getBasePath()); |
|
1112 | + $config->loadFromPhp($configElement, $this->getBasePath()); |
|
1113 | 1113 | else |
1114 | - $config->loadFromXml($configElement,$this->getBasePath()); |
|
1115 | - $this->applyConfiguration($config,true); |
|
1114 | + $config->loadFromXml($configElement, $this->getBasePath()); |
|
1115 | + $this->applyConfiguration($config, true); |
|
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | $service->init($configElement); |
1119 | 1119 | } |
1120 | 1120 | else |
1121 | - throw new THttpException(500,'application_service_unknown',$serviceID); |
|
1121 | + throw new THttpException(500, 'application_service_unknown', $serviceID); |
|
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | /** |
@@ -1129,9 +1129,9 @@ discard block |
||
1129 | 1129 | */ |
1130 | 1130 | public function onError($param) |
1131 | 1131 | { |
1132 | - Prado::log($param->getMessage(),TLogger::ERROR,'System.TApplication'); |
|
1133 | - $this->raiseEvent('OnError',$this,$param); |
|
1134 | - $this->getErrorHandler()->handleError($this,$param); |
|
1132 | + Prado::log($param->getMessage(), TLogger::ERROR, 'System.TApplication'); |
|
1133 | + $this->raiseEvent('OnError', $this, $param); |
|
1134 | + $this->getErrorHandler()->handleError($this, $param); |
|
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | /** |
@@ -1143,7 +1143,7 @@ discard block |
||
1143 | 1143 | */ |
1144 | 1144 | public function onBeginRequest() |
1145 | 1145 | { |
1146 | - $this->raiseEvent('OnBeginRequest',$this,null); |
|
1146 | + $this->raiseEvent('OnBeginRequest', $this, null); |
|
1147 | 1147 | } |
1148 | 1148 | |
1149 | 1149 | /** |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | public function onAuthentication() |
1154 | 1154 | { |
1155 | - $this->raiseEvent('OnAuthentication',$this,null); |
|
1155 | + $this->raiseEvent('OnAuthentication', $this, null); |
|
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | /** |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | */ |
1162 | 1162 | public function onAuthenticationComplete() |
1163 | 1163 | { |
1164 | - $this->raiseEvent('OnAuthenticationComplete',$this,null); |
|
1164 | + $this->raiseEvent('OnAuthenticationComplete', $this, null); |
|
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | /** |
@@ -1170,7 +1170,7 @@ discard block |
||
1170 | 1170 | */ |
1171 | 1171 | public function onAuthorization() |
1172 | 1172 | { |
1173 | - $this->raiseEvent('OnAuthorization',$this,null); |
|
1173 | + $this->raiseEvent('OnAuthorization', $this, null); |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | /** |
@@ -1179,7 +1179,7 @@ discard block |
||
1179 | 1179 | */ |
1180 | 1180 | public function onAuthorizationComplete() |
1181 | 1181 | { |
1182 | - $this->raiseEvent('OnAuthorizationComplete',$this,null); |
|
1182 | + $this->raiseEvent('OnAuthorizationComplete', $this, null); |
|
1183 | 1183 | } |
1184 | 1184 | |
1185 | 1185 | /** |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | public function onLoadState() |
1190 | 1190 | { |
1191 | 1191 | $this->loadGlobals(); |
1192 | - $this->raiseEvent('OnLoadState',$this,null); |
|
1192 | + $this->raiseEvent('OnLoadState', $this, null); |
|
1193 | 1193 | } |
1194 | 1194 | |
1195 | 1195 | /** |
@@ -1198,7 +1198,7 @@ discard block |
||
1198 | 1198 | */ |
1199 | 1199 | public function onLoadStateComplete() |
1200 | 1200 | { |
1201 | - $this->raiseEvent('OnLoadStateComplete',$this,null); |
|
1201 | + $this->raiseEvent('OnLoadStateComplete', $this, null); |
|
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | /** |
@@ -1207,7 +1207,7 @@ discard block |
||
1207 | 1207 | */ |
1208 | 1208 | public function onPreRunService() |
1209 | 1209 | { |
1210 | - $this->raiseEvent('OnPreRunService',$this,null); |
|
1210 | + $this->raiseEvent('OnPreRunService', $this, null); |
|
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | /** |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | */ |
1226 | 1226 | public function onSaveState() |
1227 | 1227 | { |
1228 | - $this->raiseEvent('OnSaveState',$this,null); |
|
1228 | + $this->raiseEvent('OnSaveState', $this, null); |
|
1229 | 1229 | $this->saveGlobals(); |
1230 | 1230 | } |
1231 | 1231 | |
@@ -1235,7 +1235,7 @@ discard block |
||
1235 | 1235 | */ |
1236 | 1236 | public function onSaveStateComplete() |
1237 | 1237 | { |
1238 | - $this->raiseEvent('OnSaveStateComplete',$this,null); |
|
1238 | + $this->raiseEvent('OnSaveStateComplete', $this, null); |
|
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | /** |
@@ -1244,14 +1244,14 @@ discard block |
||
1244 | 1244 | */ |
1245 | 1245 | public function onPreFlushOutput() |
1246 | 1246 | { |
1247 | - $this->raiseEvent('OnPreFlushOutput',$this,null); |
|
1247 | + $this->raiseEvent('OnPreFlushOutput', $this, null); |
|
1248 | 1248 | } |
1249 | 1249 | |
1250 | 1250 | /** |
1251 | 1251 | * Flushes output to client side. |
1252 | 1252 | * @param boolean whether to continue buffering after flush if buffering was active |
1253 | 1253 | */ |
1254 | - public function flushOutput($continueBuffering = true) |
|
1254 | + public function flushOutput($continueBuffering=true) |
|
1255 | 1255 | { |
1256 | 1256 | $this->getResponse()->flush($continueBuffering); |
1257 | 1257 | } |
@@ -1263,8 +1263,8 @@ discard block |
||
1263 | 1263 | public function onEndRequest() |
1264 | 1264 | { |
1265 | 1265 | $this->flushOutput(false); // flush all remaining content in the buffer |
1266 | - $this->saveGlobals(); // save global state |
|
1267 | - $this->raiseEvent('OnEndRequest',$this,null); |
|
1266 | + $this->saveGlobals(); // save global state |
|
1267 | + $this->raiseEvent('OnEndRequest', $this, null); |
|
1268 | 1268 | } |
1269 | 1269 | } |
1270 | 1270 | |
@@ -1344,14 +1344,14 @@ discard block |
||
1344 | 1344 | { |
1345 | 1345 | if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
1346 | 1346 | { |
1347 | - $fcontent = include $fname; |
|
1348 | - $this->loadFromPhp($fcontent,dirname($fname)); |
|
1347 | + $fcontent=include $fname; |
|
1348 | + $this->loadFromPhp($fcontent, dirname($fname)); |
|
1349 | 1349 | } |
1350 | 1350 | else |
1351 | 1351 | { |
1352 | 1352 | $dom=new TXmlDocument; |
1353 | 1353 | $dom->loadFromFile($fname); |
1354 | - $this->loadFromXml($dom,dirname($fname)); |
|
1354 | + $this->loadFromXml($dom, dirname($fname)); |
|
1355 | 1355 | } |
1356 | 1356 | } |
1357 | 1357 | |
@@ -1377,23 +1377,23 @@ discard block |
||
1377 | 1377 | { |
1378 | 1378 | $this->_properties[$name]=$value; |
1379 | 1379 | } |
1380 | - $this->_empty = false; |
|
1380 | + $this->_empty=false; |
|
1381 | 1381 | } |
1382 | 1382 | |
1383 | 1383 | if(isset($config['paths']) && is_array($config['paths'])) |
1384 | - $this->loadPathsPhp($config['paths'],$configPath); |
|
1384 | + $this->loadPathsPhp($config['paths'], $configPath); |
|
1385 | 1385 | |
1386 | 1386 | if(isset($config['modules']) && is_array($config['modules'])) |
1387 | - $this->loadModulesPhp($config['modules'],$configPath); |
|
1387 | + $this->loadModulesPhp($config['modules'], $configPath); |
|
1388 | 1388 | |
1389 | 1389 | if(isset($config['services']) && is_array($config['services'])) |
1390 | - $this->loadServicesPhp($config['services'],$configPath); |
|
1390 | + $this->loadServicesPhp($config['services'], $configPath); |
|
1391 | 1391 | |
1392 | 1392 | if(isset($config['parameters']) && is_array($config['parameters'])) |
1393 | 1393 | $this->loadParametersPhp($config['parameters'], $configPath); |
1394 | 1394 | |
1395 | 1395 | if(isset($config['includes']) && is_array($config['includes'])) |
1396 | - $this->loadExternalXml($config['includes'],$configPath); |
|
1396 | + $this->loadExternalXml($config['includes'], $configPath); |
|
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | /** |
@@ -1401,7 +1401,7 @@ discard block |
||
1401 | 1401 | * @param TXmlElement the XML element |
1402 | 1402 | * @param string the context path (for specifying relative paths) |
1403 | 1403 | */ |
1404 | - public function loadFromXml($dom,$configPath) |
|
1404 | + public function loadFromXml($dom, $configPath) |
|
1405 | 1405 | { |
1406 | 1406 | // application properties |
1407 | 1407 | foreach($dom->getAttributes() as $name=>$value) |
@@ -1415,19 +1415,19 @@ discard block |
||
1415 | 1415 | switch($element->getTagName()) |
1416 | 1416 | { |
1417 | 1417 | case 'paths': |
1418 | - $this->loadPathsXml($element,$configPath); |
|
1418 | + $this->loadPathsXml($element, $configPath); |
|
1419 | 1419 | break; |
1420 | 1420 | case 'modules': |
1421 | - $this->loadModulesXml($element,$configPath); |
|
1421 | + $this->loadModulesXml($element, $configPath); |
|
1422 | 1422 | break; |
1423 | 1423 | case 'services': |
1424 | - $this->loadServicesXml($element,$configPath); |
|
1424 | + $this->loadServicesXml($element, $configPath); |
|
1425 | 1425 | break; |
1426 | 1426 | case 'parameters': |
1427 | - $this->loadParametersXml($element,$configPath); |
|
1427 | + $this->loadParametersXml($element, $configPath); |
|
1428 | 1428 | break; |
1429 | 1429 | case 'include': |
1430 | - $this->loadExternalXml($element,$configPath); |
|
1430 | + $this->loadExternalXml($element, $configPath); |
|
1431 | 1431 | break; |
1432 | 1432 | default: |
1433 | 1433 | //throw new TConfigurationException('appconfig_tag_invalid',$element->getTagName()); |
@@ -1447,15 +1447,15 @@ discard block |
||
1447 | 1447 | { |
1448 | 1448 | foreach($pathsNode['aliases'] as $id=>$path) |
1449 | 1449 | { |
1450 | - $path=str_replace('\\','/',$path); |
|
1451 | - if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) // if absolute path |
|
1450 | + $path=str_replace('\\', '/', $path); |
|
1451 | + if(preg_match('/^\\/|.:\\/|.:\\\\/', $path)) // if absolute path |
|
1452 | 1452 | $p=realpath($path); |
1453 | 1453 | else |
1454 | 1454 | $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
1455 | 1455 | if($p===false || !is_dir($p)) |
1456 | - throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
1456 | + throw new TConfigurationException('appconfig_aliaspath_invalid', $id, $path); |
|
1457 | 1457 | if(isset($this->_aliases[$id])) |
1458 | - throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
1458 | + throw new TConfigurationException('appconfig_alias_redefined', $id); |
|
1459 | 1459 | $this->_aliases[$id]=$p; |
1460 | 1460 | } |
1461 | 1461 | } |
@@ -1464,7 +1464,7 @@ discard block |
||
1464 | 1464 | { |
1465 | 1465 | foreach($pathsNode['using'] as $namespace) |
1466 | 1466 | { |
1467 | - $this->_usings[] = $namespace; |
|
1467 | + $this->_usings[]=$namespace; |
|
1468 | 1468 | } |
1469 | 1469 | } |
1470 | 1470 | } |
@@ -1474,7 +1474,7 @@ discard block |
||
1474 | 1474 | * @param TXmlElement the paths XML node |
1475 | 1475 | * @param string the context path (for specifying relative paths) |
1476 | 1476 | */ |
1477 | - protected function loadPathsXml($pathsNode,$configPath) |
|
1477 | + protected function loadPathsXml($pathsNode, $configPath) |
|
1478 | 1478 | { |
1479 | 1479 | foreach($pathsNode->getElements() as $element) |
1480 | 1480 | { |
@@ -1484,15 +1484,15 @@ discard block |
||
1484 | 1484 | { |
1485 | 1485 | if(($id=$element->getAttribute('id'))!==null && ($path=$element->getAttribute('path'))!==null) |
1486 | 1486 | { |
1487 | - $path=str_replace('\\','/',$path); |
|
1488 | - if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) // if absolute path |
|
1487 | + $path=str_replace('\\', '/', $path); |
|
1488 | + if(preg_match('/^\\/|.:\\/|.:\\\\/', $path)) // if absolute path |
|
1489 | 1489 | $p=realpath($path); |
1490 | 1490 | else |
1491 | 1491 | $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
1492 | 1492 | if($p===false || !is_dir($p)) |
1493 | - throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
1493 | + throw new TConfigurationException('appconfig_aliaspath_invalid', $id, $path); |
|
1494 | 1494 | if(isset($this->_aliases[$id])) |
1495 | - throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
1495 | + throw new TConfigurationException('appconfig_alias_redefined', $id); |
|
1496 | 1496 | $this->_aliases[$id]=$p; |
1497 | 1497 | } |
1498 | 1498 | else |
@@ -1510,7 +1510,7 @@ discard block |
||
1510 | 1510 | break; |
1511 | 1511 | } |
1512 | 1512 | default: |
1513 | - throw new TConfigurationException('appconfig_paths_invalid',$element->getTagName()); |
|
1513 | + throw new TConfigurationException('appconfig_paths_invalid', $element->getTagName()); |
|
1514 | 1514 | } |
1515 | 1515 | } |
1516 | 1516 | } |
@@ -1525,17 +1525,17 @@ discard block |
||
1525 | 1525 | foreach($modulesNode as $id=>$module) |
1526 | 1526 | { |
1527 | 1527 | if(!isset($module['class'])) |
1528 | - throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
1529 | - $type = $module['class']; |
|
1528 | + throw new TConfigurationException('appconfig_moduletype_required', $id); |
|
1529 | + $type=$module['class']; |
|
1530 | 1530 | unset($module['class']); |
1531 | - $properties = array(); |
|
1531 | + $properties=array(); |
|
1532 | 1532 | if(isset($module['properties'])) |
1533 | 1533 | { |
1534 | - $properties = $module['properties']; |
|
1534 | + $properties=$module['properties']; |
|
1535 | 1535 | unset($module['properties']); |
1536 | 1536 | } |
1537 | - $properties['id'] = $id; |
|
1538 | - $this->_modules[$id]=array($type,$properties,$module); |
|
1537 | + $properties['id']=$id; |
|
1538 | + $this->_modules[$id]=array($type, $properties, $module); |
|
1539 | 1539 | $this->_empty=false; |
1540 | 1540 | } |
1541 | 1541 | } |
@@ -1545,7 +1545,7 @@ discard block |
||
1545 | 1545 | * @param TXmlElement the modules XML node |
1546 | 1546 | * @param string the context path (for specifying relative paths) |
1547 | 1547 | */ |
1548 | - protected function loadModulesXml($modulesNode,$configPath) |
|
1548 | + protected function loadModulesXml($modulesNode, $configPath) |
|
1549 | 1549 | { |
1550 | 1550 | foreach($modulesNode->getElements() as $element) |
1551 | 1551 | { |
@@ -1555,16 +1555,16 @@ discard block |
||
1555 | 1555 | $id=$properties->itemAt('id'); |
1556 | 1556 | $type=$properties->remove('class'); |
1557 | 1557 | if($type===null) |
1558 | - throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
1558 | + throw new TConfigurationException('appconfig_moduletype_required', $id); |
|
1559 | 1559 | $element->setParent(null); |
1560 | 1560 | if($id===null) |
1561 | - $this->_modules[]=array($type,$properties->toArray(),$element); |
|
1561 | + $this->_modules[]=array($type, $properties->toArray(), $element); |
|
1562 | 1562 | else |
1563 | - $this->_modules[$id]=array($type,$properties->toArray(),$element); |
|
1563 | + $this->_modules[$id]=array($type, $properties->toArray(), $element); |
|
1564 | 1564 | $this->_empty=false; |
1565 | 1565 | } |
1566 | 1566 | else |
1567 | - throw new TConfigurationException('appconfig_modules_invalid',$element->getTagName()); |
|
1567 | + throw new TConfigurationException('appconfig_modules_invalid', $element->getTagName()); |
|
1568 | 1568 | } |
1569 | 1569 | } |
1570 | 1570 | |
@@ -1573,18 +1573,18 @@ discard block |
||
1573 | 1573 | * @param array the services PHP array |
1574 | 1574 | * @param string the context path (for specifying relative paths) |
1575 | 1575 | */ |
1576 | - protected function loadServicesPhp($servicesNode,$configPath) |
|
1576 | + protected function loadServicesPhp($servicesNode, $configPath) |
|
1577 | 1577 | { |
1578 | 1578 | foreach($servicesNode as $id => $service) |
1579 | 1579 | { |
1580 | 1580 | if(!isset($service['class'])) |
1581 | 1581 | throw new TConfigurationException('appconfig_servicetype_required'); |
1582 | - $type = $service['class']; |
|
1583 | - $properties = isset($service['properties']) ? $service['properties'] : array(); |
|
1582 | + $type=$service['class']; |
|
1583 | + $properties=isset($service['properties']) ? $service['properties'] : array(); |
|
1584 | 1584 | unset($service['properties']); |
1585 | - $properties['id'] = $id; |
|
1586 | - $this->_services[$id] = array($type,$properties,$service); |
|
1587 | - $this->_empty = false; |
|
1585 | + $properties['id']=$id; |
|
1586 | + $this->_services[$id]=array($type, $properties, $service); |
|
1587 | + $this->_empty=false; |
|
1588 | 1588 | } |
1589 | 1589 | } |
1590 | 1590 | |
@@ -1593,7 +1593,7 @@ discard block |
||
1593 | 1593 | * @param TXmlElement the services XML node |
1594 | 1594 | * @param string the context path (for specifying relative paths) |
1595 | 1595 | */ |
1596 | - protected function loadServicesXml($servicesNode,$configPath) |
|
1596 | + protected function loadServicesXml($servicesNode, $configPath) |
|
1597 | 1597 | { |
1598 | 1598 | foreach($servicesNode->getElements() as $element) |
1599 | 1599 | { |
@@ -1603,13 +1603,13 @@ discard block |
||
1603 | 1603 | if(($id=$properties->itemAt('id'))===null) |
1604 | 1604 | throw new TConfigurationException('appconfig_serviceid_required'); |
1605 | 1605 | if(($type=$properties->remove('class'))===null) |
1606 | - throw new TConfigurationException('appconfig_servicetype_required',$id); |
|
1606 | + throw new TConfigurationException('appconfig_servicetype_required', $id); |
|
1607 | 1607 | $element->setParent(null); |
1608 | - $this->_services[$id]=array($type,$properties->toArray(),$element); |
|
1608 | + $this->_services[$id]=array($type, $properties->toArray(), $element); |
|
1609 | 1609 | $this->_empty=false; |
1610 | 1610 | } |
1611 | 1611 | else |
1612 | - throw new TConfigurationException('appconfig_services_invalid',$element->getTagName()); |
|
1612 | + throw new TConfigurationException('appconfig_services_invalid', $element->getTagName()); |
|
1613 | 1613 | } |
1614 | 1614 | } |
1615 | 1615 | |
@@ -1618,7 +1618,7 @@ discard block |
||
1618 | 1618 | * @param array the parameters PHP array |
1619 | 1619 | * @param string the context path (for specifying relative paths) |
1620 | 1620 | */ |
1621 | - protected function loadParametersPhp($parametersNode,$configPath) |
|
1621 | + protected function loadParametersPhp($parametersNode, $configPath) |
|
1622 | 1622 | { |
1623 | 1623 | foreach($parametersNode as $id => $parameter) |
1624 | 1624 | { |
@@ -1626,16 +1626,16 @@ discard block |
||
1626 | 1626 | { |
1627 | 1627 | if(isset($parameter['class'])) |
1628 | 1628 | { |
1629 | - $type = $parameter['class']; |
|
1629 | + $type=$parameter['class']; |
|
1630 | 1630 | unset($parameter['class']); |
1631 | - $properties = isset($service['properties']) ? $service['properties'] : array(); |
|
1632 | - $properties['id'] = $id; |
|
1633 | - $this->_parameters[$id] = array($type,$properties); |
|
1631 | + $properties=isset($service['properties']) ? $service['properties'] : array(); |
|
1632 | + $properties['id']=$id; |
|
1633 | + $this->_parameters[$id]=array($type, $properties); |
|
1634 | 1634 | } |
1635 | 1635 | } |
1636 | 1636 | else |
1637 | 1637 | { |
1638 | - $this->_parameters[$id] = $parameter; |
|
1638 | + $this->_parameters[$id]=$parameter; |
|
1639 | 1639 | } |
1640 | 1640 | } |
1641 | 1641 | } |
@@ -1645,7 +1645,7 @@ discard block |
||
1645 | 1645 | * @param TXmlElement the parameters XML node |
1646 | 1646 | * @param string the context path (for specifying relative paths) |
1647 | 1647 | */ |
1648 | - protected function loadParametersXml($parametersNode,$configPath) |
|
1648 | + protected function loadParametersXml($parametersNode, $configPath) |
|
1649 | 1649 | { |
1650 | 1650 | foreach($parametersNode->getElements() as $element) |
1651 | 1651 | { |
@@ -1662,11 +1662,11 @@ discard block |
||
1662 | 1662 | $this->_parameters[$id]=$value; |
1663 | 1663 | } |
1664 | 1664 | else |
1665 | - $this->_parameters[$id]=array($type,$properties->toArray()); |
|
1665 | + $this->_parameters[$id]=array($type, $properties->toArray()); |
|
1666 | 1666 | $this->_empty=false; |
1667 | 1667 | } |
1668 | 1668 | else |
1669 | - throw new TConfigurationException('appconfig_parameters_invalid',$element->getTagName()); |
|
1669 | + throw new TConfigurationException('appconfig_parameters_invalid', $element->getTagName()); |
|
1670 | 1670 | } |
1671 | 1671 | } |
1672 | 1672 | |
@@ -1675,14 +1675,14 @@ discard block |
||
1675 | 1675 | * @param array the application PHP array |
1676 | 1676 | * @param string the context path (for specifying relative paths) |
1677 | 1677 | */ |
1678 | - protected function loadExternalPhp($includeNode,$configPath) |
|
1678 | + protected function loadExternalPhp($includeNode, $configPath) |
|
1679 | 1679 | { |
1680 | 1680 | foreach($includeNode as $include) |
1681 | 1681 | { |
1682 | - $when = isset($include['when'])?true:false; |
|
1682 | + $when=isset($include['when']) ? true : false; |
|
1683 | 1683 | if(!isset($include['file'])) |
1684 | 1684 | throw new TConfigurationException('appconfig_includefile_required'); |
1685 | - $filePath = $include['file']; |
|
1685 | + $filePath=$include['file']; |
|
1686 | 1686 | if(isset($this->_includes[$filePath])) |
1687 | 1687 | $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')'; |
1688 | 1688 | else |
@@ -1696,7 +1696,7 @@ discard block |
||
1696 | 1696 | * @param TXmlElement the application DOM element |
1697 | 1697 | * @param string the context path (for specifying relative paths) |
1698 | 1698 | */ |
1699 | - protected function loadExternalXml($includeNode,$configPath) |
|
1699 | + protected function loadExternalXml($includeNode, $configPath) |
|
1700 | 1700 | { |
1701 | 1701 | if(($when=$includeNode->getAttribute('when'))===null) |
1702 | 1702 | $when=true; |
@@ -1862,12 +1862,12 @@ discard block |
||
1862 | 1862 | if($cache->get(self::CACHE_NAME)===$content) |
1863 | 1863 | $saveFile=false; |
1864 | 1864 | else |
1865 | - $cache->set(self::CACHE_NAME,$content); |
|
1865 | + $cache->set(self::CACHE_NAME, $content); |
|
1866 | 1866 | } |
1867 | 1867 | if($saveFile) |
1868 | 1868 | { |
1869 | 1869 | $fileName=$this->getStateFilePath(); |
1870 | - file_put_contents($fileName,$content,LOCK_EX); |
|
1870 | + file_put_contents($fileName, $content, LOCK_EX); |
|
1871 | 1871 | } |
1872 | 1872 | } |
1873 | 1873 |
@@ -357,8 +357,7 @@ discard block |
||
357 | 357 | { |
358 | 358 | $configFile=$basePath; |
359 | 359 | $basePath=dirname($configFile); |
360 | - } |
|
361 | - else |
|
360 | + } else |
|
362 | 361 | $configFile=null; |
363 | 362 | |
364 | 363 | // determine runtime path |
@@ -378,8 +377,7 @@ discard block |
||
378 | 377 | } |
379 | 378 | $this->setBasePath($basePath); |
380 | 379 | $this->setRuntimePath($runtimePath); |
381 | - } |
|
382 | - else |
|
380 | + } else |
|
383 | 381 | throw new TConfigurationException('application_runtimepath_invalid',$runtimePath); |
384 | 382 | |
385 | 383 | } |
@@ -408,8 +406,7 @@ discard block |
||
408 | 406 | $this->$method(); |
409 | 407 | $this->_step++; |
410 | 408 | } |
411 | - } |
|
412 | - catch(Exception $e) |
|
409 | + } catch(Exception $e) |
|
413 | 410 | { |
414 | 411 | $this->onError($e); |
415 | 412 | } |
@@ -1010,8 +1007,7 @@ discard block |
||
1010 | 1007 | foreach($parameter[1] as $name=>$value) |
1011 | 1008 | $component->setSubProperty($name,$value); |
1012 | 1009 | $this->_parameters->add($id,$component); |
1013 | - } |
|
1014 | - else |
|
1010 | + } else |
|
1015 | 1011 | $this->_parameters->add($id,$parameter); |
1016 | 1012 | } |
1017 | 1013 | |
@@ -1070,8 +1066,7 @@ discard block |
||
1070 | 1066 | $config->loadFromFile($this->_configFile); |
1071 | 1067 | if($this->_cacheFile!==null) |
1072 | 1068 | file_put_contents($this->_cacheFile,serialize($config),LOCK_EX); |
1073 | - } |
|
1074 | - else |
|
1069 | + } else |
|
1075 | 1070 | $config=unserialize(file_get_contents($this->_cacheFile)); |
1076 | 1071 | |
1077 | 1072 | $this->applyConfiguration($config,false); |
@@ -1116,8 +1111,7 @@ discard block |
||
1116 | 1111 | } |
1117 | 1112 | |
1118 | 1113 | $service->init($configElement); |
1119 | - } |
|
1120 | - else |
|
1114 | + } else |
|
1121 | 1115 | throw new THttpException(500,'application_service_unknown',$serviceID); |
1122 | 1116 | } |
1123 | 1117 | |
@@ -1346,8 +1340,7 @@ discard block |
||
1346 | 1340 | { |
1347 | 1341 | $fcontent = include $fname; |
1348 | 1342 | $this->loadFromPhp($fcontent,dirname($fname)); |
1349 | - } |
|
1350 | - else |
|
1343 | + } else |
|
1351 | 1344 | { |
1352 | 1345 | $dom=new TXmlDocument; |
1353 | 1346 | $dom->loadFromFile($fname); |
@@ -1494,8 +1487,7 @@ discard block |
||
1494 | 1487 | if(isset($this->_aliases[$id])) |
1495 | 1488 | throw new TConfigurationException('appconfig_alias_redefined',$id); |
1496 | 1489 | $this->_aliases[$id]=$p; |
1497 | - } |
|
1498 | - else |
|
1490 | + } else |
|
1499 | 1491 | throw new TConfigurationException('appconfig_alias_invalid'); |
1500 | 1492 | $this->_empty=false; |
1501 | 1493 | break; |
@@ -1562,8 +1554,7 @@ discard block |
||
1562 | 1554 | else |
1563 | 1555 | $this->_modules[$id]=array($type,$properties->toArray(),$element); |
1564 | 1556 | $this->_empty=false; |
1565 | - } |
|
1566 | - else |
|
1557 | + } else |
|
1567 | 1558 | throw new TConfigurationException('appconfig_modules_invalid',$element->getTagName()); |
1568 | 1559 | } |
1569 | 1560 | } |
@@ -1607,8 +1598,7 @@ discard block |
||
1607 | 1598 | $element->setParent(null); |
1608 | 1599 | $this->_services[$id]=array($type,$properties->toArray(),$element); |
1609 | 1600 | $this->_empty=false; |
1610 | - } |
|
1611 | - else |
|
1601 | + } else |
|
1612 | 1602 | throw new TConfigurationException('appconfig_services_invalid',$element->getTagName()); |
1613 | 1603 | } |
1614 | 1604 | } |
@@ -1632,8 +1622,7 @@ discard block |
||
1632 | 1622 | $properties['id'] = $id; |
1633 | 1623 | $this->_parameters[$id] = array($type,$properties); |
1634 | 1624 | } |
1635 | - } |
|
1636 | - else |
|
1625 | + } else |
|
1637 | 1626 | { |
1638 | 1627 | $this->_parameters[$id] = $parameter; |
1639 | 1628 | } |
@@ -1660,12 +1649,10 @@ discard block |
||
1660 | 1649 | $this->_parameters[$id]=$element; |
1661 | 1650 | else |
1662 | 1651 | $this->_parameters[$id]=$value; |
1663 | - } |
|
1664 | - else |
|
1652 | + } else |
|
1665 | 1653 | $this->_parameters[$id]=array($type,$properties->toArray()); |
1666 | 1654 | $this->_empty=false; |
1667 | - } |
|
1668 | - else |
|
1655 | + } else |
|
1669 | 1656 | throw new TConfigurationException('appconfig_parameters_invalid',$element->getTagName()); |
1670 | 1657 | } |
1671 | 1658 | } |
@@ -98,6 +98,7 @@ |
||
98 | 98 | * @param integer level filter |
99 | 99 | * @param array category filter |
100 | 100 | * @param array control filter |
101 | + * @param integer $levels |
|
101 | 102 | * @return array list of messages. Each array elements represents one message |
102 | 103 | * with the following structure: |
103 | 104 | * array( |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | * @param string category of the message |
64 | 64 | * @param string|TControl control of the message |
65 | 65 | */ |
66 | - public function log($message,$level,$category='Uncategorized', $ctl=null) |
|
66 | + public function log($message, $level, $category='Uncategorized', $ctl=null) |
|
67 | 67 | { |
68 | 68 | if($ctl) { |
69 | 69 | if($ctl instanceof TControl) |
70 | - $ctl = $ctl->ClientId; |
|
70 | + $ctl=$ctl->ClientId; |
|
71 | 71 | else if(!is_string($ctl)) |
72 | - $ctl = null; |
|
72 | + $ctl=null; |
|
73 | 73 | } else |
74 | - $ctl = null; |
|
75 | - $this->_logs[]=array($message,$level,$category,microtime(true),memory_get_usage(),$ctl); |
|
74 | + $ctl=null; |
|
75 | + $this->_logs[]=array($message, $level, $category, microtime(true), memory_get_usage(), $ctl); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * [4] => memory in bytes |
109 | 109 | * [5] => control client id |
110 | 110 | */ |
111 | - public function getLogs($levels=null,$categories=null,$controls=null,$timestamp=null) |
|
111 | + public function getLogs($levels=null, $categories=null, $controls=null, $timestamp=null) |
|
112 | 112 | { |
113 | 113 | $this->_levels=$levels; |
114 | 114 | $this->_categories=$categories; |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | $this->_timestamp=$timestamp; |
117 | 117 | if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp)) |
118 | 118 | return $this->_logs; |
119 | - $logs = $this->_logs; |
|
119 | + $logs=$this->_logs; |
|
120 | 120 | if(!empty($levels)) |
121 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByLevels')) )); |
|
121 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByLevels')))); |
|
122 | 122 | if(!empty($categories)) |
123 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByCategories')) )); |
|
123 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByCategories')))); |
|
124 | 124 | if(!empty($controls)) |
125 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByControl')) )); |
|
125 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByControl')))); |
|
126 | 126 | if(!is_null($timestamp)) |
127 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByTimeStamp')) )); |
|
127 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByTimeStamp')))); |
|
128 | 128 | return $logs; |
129 | 129 | } |
130 | 130 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param array category filter |
153 | 153 | * @param array control filter |
154 | 154 | */ |
155 | - public function deleteLogs($levels=null,$categories=null,$controls=null,$timestamp=null) |
|
155 | + public function deleteLogs($levels=null, $categories=null, $controls=null, $timestamp=null) |
|
156 | 156 | { |
157 | 157 | $this->_levels=$levels; |
158 | 158 | $this->_categories=$categories; |
@@ -163,16 +163,16 @@ discard block |
||
163 | 163 | $this->_logs=array(); |
164 | 164 | return; |
165 | 165 | } |
166 | - $logs = $this->_logs; |
|
166 | + $logs=$this->_logs; |
|
167 | 167 | if(!empty($levels)) |
168 | - $logs = array_filter( array_filter($logs,array($this,'filterByLevels')) ); |
|
168 | + $logs=array_filter(array_filter($logs, array($this, 'filterByLevels'))); |
|
169 | 169 | if(!empty($categories)) |
170 | - $logs = array_filter( array_filter($logs,array($this,'filterByCategories')) ); |
|
170 | + $logs=array_filter(array_filter($logs, array($this, 'filterByCategories'))); |
|
171 | 171 | if(!empty($controls)) |
172 | - $logs = array_filter( array_filter($logs,array($this,'filterByControl')) ); |
|
172 | + $logs=array_filter(array_filter($logs, array($this, 'filterByControl'))); |
|
173 | 173 | if(!is_null($timestamp)) |
174 | - $logs = array_filter( array_filter($logs,array($this,'filterByTimeStamp')) ); |
|
175 | - $this->_logs = array_values( array_diff_key($this->_logs, $logs) ); |
|
174 | + $logs=array_filter(array_filter($logs, array($this, 'filterByTimeStamp'))); |
|
175 | + $this->_logs=array_values(array_diff_key($this->_logs, $logs)); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | foreach($this->_categories as $category) |
185 | 185 | { |
186 | 186 | // element 2 is the category |
187 | - if($value[2]===$category || strpos($value[2],$category.'.')===0) |
|
187 | + if($value[2]===$category || strpos($value[2], $category.'.')===0) |
|
188 | 188 | return $value; |
189 | 189 | } |
190 | 190 | return false; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | // element 5 are the control client ids |
213 | 213 | foreach($this->_controls as $control) |
214 | 214 | { |
215 | - if($value[5]===$control || strpos($value[5],$control)===0) |
|
215 | + if($value[5]===$control || strpos($value[5], $control)===0) |
|
216 | 216 | return $value; |
217 | 217 | } |
218 | 218 | return false; |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TLogger class file |
|
4 | - * |
|
5 | - * @author Qiang Xue <[email protected]> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2016 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Util |
|
10 | - */ |
|
3 | + * TLogger class file |
|
4 | + * |
|
5 | + * @author Qiang Xue <[email protected]> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2016 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Util |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * TLogger class. |
@@ -105,6 +105,9 @@ |
||
105 | 105 | * @param string RPC server URL |
106 | 106 | * @param array payload data |
107 | 107 | * @param string request mime type |
108 | + * @param string $serverUrl |
|
109 | + * @param string $mimeType |
|
110 | + * @return string |
|
108 | 111 | */ |
109 | 112 | protected function performRequest($serverUrl, $payload, $mimeType) |
110 | 113 | { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * @var boolean whether the request is a notification and therefore should not care about the result (default: false) |
57 | 57 | */ |
58 | - private $_isNotification = false; |
|
58 | + private $_isNotification=false; |
|
59 | 59 | |
60 | 60 | // magics |
61 | 61 | |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | * @param string url to RPC server |
64 | 64 | * @param boolean whether requests are considered to be notifications (completely ignoring the response) (default: false) |
65 | 65 | */ |
66 | - public function __construct($serverUrl, $isNotification = false) |
|
66 | + public function __construct($serverUrl, $isNotification=false) |
|
67 | 67 | { |
68 | - $this->_serverUrl = $serverUrl; |
|
69 | - $this->_isNotification = TPropertyValue::ensureBoolean($isNotification); |
|
68 | + $this->_serverUrl=$serverUrl; |
|
69 | + $this->_isNotification=TPropertyValue::ensureBoolean($isNotification); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | // methods |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | * @return TRpcClient instance |
77 | 77 | * @throws TApplicationException if an unsupported RPC client type was specified |
78 | 78 | */ |
79 | - public static function create($type, $serverUrl, $isNotification = false) |
|
79 | + public static function create($type, $serverUrl, $isNotification=false) |
|
80 | 80 | { |
81 | - if(($_handler = constant('TRpcClientTypesEnumerable::'.strtoupper($type))) === null) |
|
81 | + if(($_handler=constant('TRpcClientTypesEnumerable::'.strtoupper($type)))===null) |
|
82 | 82 | throw new TApplicationException('rpcclient_unsupported_handler'); |
83 | 83 | |
84 | 84 | return new $_handler($serverUrl, $isNotification); |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function performRequest($serverUrl, $payload, $mimeType) |
110 | 110 | { |
111 | - if(($_response = @file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType))) === false) |
|
111 | + if(($_response=@file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType)))===false) |
|
112 | 112 | throw new TRpcClientRequestException('Request failed ("'.$http_response_header[0].'")'); |
113 | 113 | |
114 | 114 | return $_response; |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function setIsNotification($bool) |
131 | 131 | { |
132 | - $this->_isNotification = TPropertyValue::ensureBoolean($bool); |
|
132 | + $this->_isNotification=TPropertyValue::ensureBoolean($bool); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function setServerUrl($value) |
147 | 147 | { |
148 | - $this->_serverUrl = $value; |
|
148 | + $this->_serverUrl=$value; |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | |
161 | 161 | class TRpcClientTypesEnumerable extends TEnumerable |
162 | 162 | { |
163 | - const JSON = 'TJsonRpcClient'; |
|
164 | - const XML = 'TXmlRpcClient'; |
|
163 | + const JSON='TJsonRpcClient'; |
|
164 | + const XML='TXmlRpcClient'; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @param string error message |
198 | 198 | * @param integer error code (optional) |
199 | 199 | */ |
200 | - public function __construct($errorMessage, $errorCode = null) |
|
200 | + public function __construct($errorMessage, $errorCode=null) |
|
201 | 201 | { |
202 | 202 | $this->setErrorCode($errorCode); |
203 | 203 | |
@@ -239,14 +239,14 @@ discard block |
||
239 | 239 | public function __call($method, $parameters) |
240 | 240 | { |
241 | 241 | // send request |
242 | - $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'application/json'); |
|
242 | + $_response=$this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'application/json'); |
|
243 | 243 | |
244 | 244 | // skip response handling if the request was just a notification request |
245 | 245 | if($this->isNotification) |
246 | 246 | return true; |
247 | 247 | |
248 | 248 | // decode response |
249 | - if(($_response = json_decode($_response, true)) === null) |
|
249 | + if(($_response=json_decode($_response, true))===null) |
|
250 | 250 | throw new TRpcClientResponseException('Empty response received'); |
251 | 251 | |
252 | 252 | // handle error response |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | public function encodeRequest($method, $parameters) |
266 | 266 | { |
267 | 267 | static $_requestId; |
268 | - $_requestId = ($_requestId === null) ? 1 : $_requestId + 1; |
|
268 | + $_requestId=($_requestId===null) ? 1 : $_requestId + 1; |
|
269 | 269 | |
270 | 270 | return json_encode(array( |
271 | 271 | 'method' => $method, |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | * @param string url of the rpc server |
280 | 280 | * @param boolean whether the requests are considered to be notifications (completely ignoring the response) (default: false) |
281 | 281 | */ |
282 | - public static function create($type, $serverUrl, $isNotification = false) |
|
282 | + public static function create($type, $serverUrl, $isNotification=false) |
|
283 | 283 | { |
284 | 284 | return new self($serverUrl, $isNotification); |
285 | 285 | } |
@@ -317,14 +317,14 @@ discard block |
||
317 | 317 | public function __call($method, $parameters) |
318 | 318 | { |
319 | 319 | // send request |
320 | - $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'text/xml'); |
|
320 | + $_response=$this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'text/xml'); |
|
321 | 321 | |
322 | 322 | // skip response handling if the request was just a notification request |
323 | 323 | if($this->isNotification) |
324 | 324 | return true; |
325 | 325 | |
326 | 326 | // decode response |
327 | - if(($_response = xmlrpc_decode($_response)) === null) |
|
327 | + if(($_response=xmlrpc_decode($_response))===null) |
|
328 | 328 | throw new TRpcClientResponseException('Empty response received'); |
329 | 329 | |
330 | 330 | // handle error response |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | * @param string url of the rpc server |
351 | 351 | * @param boolean whether the requests are considered to be notifications (completely ignoring the response) (default: false) |
352 | 352 | */ |
353 | - public static function create($type, $serverUrl, $isNotification = false) |
|
353 | + public static function create($type, $serverUrl, $isNotification=false) |
|
354 | 354 | { |
355 | 355 | return new self($serverUrl, $isNotification); |
356 | 356 | } |
@@ -55,6 +55,9 @@ |
||
55 | 55 | return self::$_output; |
56 | 56 | } |
57 | 57 | |
58 | + /** |
|
59 | + * @param integer $level |
|
60 | + */ |
|
58 | 61 | private static function dumpInternal($var,$level) |
59 | 62 | { |
60 | 63 | switch(gettype($var)) |
@@ -58,8 +58,7 @@ |
||
58 | 58 | if ($this->sourcepath === NULL) |
59 | 59 | { |
60 | 60 | $this->sourcepath = $sourcepath; |
61 | - } |
|
62 | - else |
|
61 | + } else |
|
63 | 62 | { |
64 | 63 | $this->sourcepath->append($sourcepath); |
65 | 64 | } |
@@ -40,27 +40,27 @@ discard block |
||
40 | 40 | * @param integer maximum depth that the dumper should go into the variable. Defaults to 10. |
41 | 41 | * @return string the string representation of the variable |
42 | 42 | */ |
43 | - public static function dump($var,$depth=10,$highlight=false) |
|
43 | + public static function dump($var, $depth=10, $highlight=false) |
|
44 | 44 | { |
45 | 45 | self::$_output=''; |
46 | 46 | self::$_objects=array(); |
47 | 47 | self::$_depth=$depth; |
48 | - self::dumpInternal($var,0); |
|
48 | + self::dumpInternal($var, 0); |
|
49 | 49 | if($highlight) |
50 | 50 | { |
51 | - $result=highlight_string("<?php\n".self::$_output,true); |
|
52 | - return preg_replace('/<\\?php<br \\/>/','',$result,1); |
|
51 | + $result=highlight_string("<?php\n".self::$_output, true); |
|
52 | + return preg_replace('/<\\?php<br \\/>/', '', $result, 1); |
|
53 | 53 | } |
54 | 54 | else |
55 | 55 | return self::$_output; |
56 | 56 | } |
57 | 57 | |
58 | - private static function dumpInternal($var,$level) |
|
58 | + private static function dumpInternal($var, $level) |
|
59 | 59 | { |
60 | 60 | switch(gettype($var)) |
61 | 61 | { |
62 | 62 | case 'boolean': |
63 | - self::$_output.=$var?'true':'false'; |
|
63 | + self::$_output.=$var ? 'true' : 'false'; |
|
64 | 64 | break; |
65 | 65 | case 'integer': |
66 | 66 | self::$_output.="$var"; |
@@ -81,41 +81,41 @@ discard block |
||
81 | 81 | self::$_output.='{unknown}'; |
82 | 82 | break; |
83 | 83 | case 'array': |
84 | - if(self::$_depth<=$level) |
|
84 | + if(self::$_depth <= $level) |
|
85 | 85 | self::$_output.='array(...)'; |
86 | 86 | else if(empty($var)) |
87 | 87 | self::$_output.='array()'; |
88 | 88 | else |
89 | 89 | { |
90 | 90 | $keys=array_keys($var); |
91 | - $spaces=str_repeat(' ',$level*4); |
|
91 | + $spaces=str_repeat(' ', $level * 4); |
|
92 | 92 | self::$_output.="array\n".$spaces.'('; |
93 | 93 | foreach($keys as $key) |
94 | 94 | { |
95 | 95 | self::$_output.="\n".$spaces." [$key] => "; |
96 | - self::$_output.=self::dumpInternal($var[$key],$level+1); |
|
96 | + self::$_output.=self::dumpInternal($var[$key], $level + 1); |
|
97 | 97 | } |
98 | 98 | self::$_output.="\n".$spaces.')'; |
99 | 99 | } |
100 | 100 | break; |
101 | 101 | case 'object': |
102 | - if(($id=array_search($var,self::$_objects,true))!==false) |
|
103 | - self::$_output.=get_class($var).'#'.($id+1).'(...)'; |
|
104 | - else if(self::$_depth<=$level) |
|
102 | + if(($id=array_search($var, self::$_objects, true))!==false) |
|
103 | + self::$_output.=get_class($var).'#'.($id + 1).'(...)'; |
|
104 | + else if(self::$_depth <= $level) |
|
105 | 105 | self::$_output.=get_class($var).'(...)'; |
106 | 106 | else |
107 | 107 | { |
108 | - $id=array_push(self::$_objects,$var); |
|
108 | + $id=array_push(self::$_objects, $var); |
|
109 | 109 | $className=get_class($var); |
110 | - $members=(array)$var; |
|
110 | + $members=(array) $var; |
|
111 | 111 | $keys=array_keys($members); |
112 | - $spaces=str_repeat(' ',$level*4); |
|
112 | + $spaces=str_repeat(' ', $level * 4); |
|
113 | 113 | self::$_output.="$className#$id\n".$spaces.'('; |
114 | 114 | foreach($keys as $key) |
115 | 115 | { |
116 | - $keyDisplay=strtr(trim($key),array("\0"=>':')); |
|
116 | + $keyDisplay=strtr(trim($key), array("\0"=>':')); |
|
117 | 117 | self::$_output.="\n".$spaces." [$keyDisplay] => "; |
118 | - self::$_output.=self::dumpInternal($members[$key],$level+1); |
|
118 | + self::$_output.=self::dumpInternal($members[$key], $level + 1); |
|
119 | 119 | } |
120 | 120 | self::$_output.="\n".$spaces.')'; |
121 | 121 | } |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TVarDumper class file |
|
4 | - * |
|
5 | - * @author Qiang Xue <[email protected]> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2016 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Util |
|
10 | - */ |
|
3 | + * TVarDumper class file |
|
4 | + * |
|
5 | + * @author Qiang Xue <[email protected]> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2016 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Util |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * TVarDumper class. |
@@ -73,6 +73,9 @@ discard block |
||
73 | 73 | |
74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
75 | 75 | |
76 | + /** |
|
77 | + * @param integer $d |
|
78 | + */ |
|
76 | 79 | protected function action($d) { |
77 | 80 | switch($d) { |
78 | 81 | case 1: |
@@ -132,6 +135,9 @@ discard block |
||
132 | 135 | } |
133 | 136 | } |
134 | 137 | |
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
135 | 141 | protected function get() { |
136 | 142 | $c = $this->lookAhead; |
137 | 143 | $this->lookAhead = null; |
@@ -156,6 +162,9 @@ discard block |
||
156 | 162 | return ' '; |
157 | 163 | } |
158 | 164 | |
165 | + /** |
|
166 | + * @param string $c |
|
167 | + */ |
|
159 | 168 | protected function isAlphaNum($c) { |
160 | 169 | return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
161 | 170 | } |
@@ -60,229 +60,229 @@ |
||
60 | 60 | // -- Public Static Methods -------------------------------------------------- |
61 | 61 | |
62 | 62 | public static function minify($js) { |
63 | - $jsmin = new JSMin($js); |
|
64 | - return $jsmin->min(); |
|
63 | + $jsmin = new JSMin($js); |
|
64 | + return $jsmin->min(); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // -- Public Instance Methods ------------------------------------------------ |
68 | 68 | |
69 | 69 | public function __construct($input) { |
70 | - $this->input = str_replace("\r\n", "\n", $input); |
|
71 | - $this->inputLength = strlen($this->input); |
|
70 | + $this->input = str_replace("\r\n", "\n", $input); |
|
71 | + $this->inputLength = strlen($this->input); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
75 | 75 | |
76 | 76 | protected function action($d) { |
77 | - switch($d) { |
|
78 | - case 1: |
|
79 | - $this->output .= $this->a; |
|
80 | - |
|
81 | - case 2: |
|
82 | - $this->a = $this->b; |
|
83 | - |
|
84 | - if ($this->a === "'" || $this->a === '"') { |
|
85 | - for (;;) { |
|
86 | - $this->output .= $this->a; |
|
87 | - $this->a = $this->get(); |
|
88 | - |
|
89 | - if ($this->a === $this->b) { |
|
90 | - break; |
|
91 | - } |
|
92 | - |
|
93 | - if (ord($this->a) <= self::ORD_LF) { |
|
94 | - throw new JSMinException('Unterminated string literal.'); |
|
95 | - } |
|
96 | - |
|
97 | - if ($this->a === '\\') { |
|
98 | - $this->output .= $this->a; |
|
99 | - $this->a = $this->get(); |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - case 3: |
|
105 | - $this->b = $this->next(); |
|
106 | - |
|
107 | - if ($this->b === '/' && ( |
|
108 | - $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
109 | - $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
110 | - $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
111 | - |
|
112 | - $this->output .= $this->a . $this->b; |
|
113 | - |
|
114 | - for (;;) { |
|
115 | - $this->a = $this->get(); |
|
116 | - |
|
117 | - if ($this->a === '/') { |
|
118 | - break; |
|
119 | - } elseif ($this->a === '\\') { |
|
120 | - $this->output .= $this->a; |
|
121 | - $this->a = $this->get(); |
|
122 | - } elseif (ord($this->a) <= self::ORD_LF) { |
|
123 | - throw new JSMinException('Unterminated regular expression '. |
|
124 | - 'literal.'); |
|
125 | - } |
|
126 | - |
|
127 | - $this->output .= $this->a; |
|
128 | - } |
|
129 | - |
|
130 | - $this->b = $this->next(); |
|
131 | - } |
|
132 | - } |
|
77 | + switch($d) { |
|
78 | + case 1: |
|
79 | + $this->output .= $this->a; |
|
80 | + |
|
81 | + case 2: |
|
82 | + $this->a = $this->b; |
|
83 | + |
|
84 | + if ($this->a === "'" || $this->a === '"') { |
|
85 | + for (;;) { |
|
86 | + $this->output .= $this->a; |
|
87 | + $this->a = $this->get(); |
|
88 | + |
|
89 | + if ($this->a === $this->b) { |
|
90 | + break; |
|
91 | + } |
|
92 | + |
|
93 | + if (ord($this->a) <= self::ORD_LF) { |
|
94 | + throw new JSMinException('Unterminated string literal.'); |
|
95 | + } |
|
96 | + |
|
97 | + if ($this->a === '\\') { |
|
98 | + $this->output .= $this->a; |
|
99 | + $this->a = $this->get(); |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + case 3: |
|
105 | + $this->b = $this->next(); |
|
106 | + |
|
107 | + if ($this->b === '/' && ( |
|
108 | + $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
109 | + $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
110 | + $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
111 | + |
|
112 | + $this->output .= $this->a . $this->b; |
|
113 | + |
|
114 | + for (;;) { |
|
115 | + $this->a = $this->get(); |
|
116 | + |
|
117 | + if ($this->a === '/') { |
|
118 | + break; |
|
119 | + } elseif ($this->a === '\\') { |
|
120 | + $this->output .= $this->a; |
|
121 | + $this->a = $this->get(); |
|
122 | + } elseif (ord($this->a) <= self::ORD_LF) { |
|
123 | + throw new JSMinException('Unterminated regular expression '. |
|
124 | + 'literal.'); |
|
125 | + } |
|
126 | + |
|
127 | + $this->output .= $this->a; |
|
128 | + } |
|
129 | + |
|
130 | + $this->b = $this->next(); |
|
131 | + } |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | protected function get() { |
136 | - $c = $this->lookAhead; |
|
137 | - $this->lookAhead = null; |
|
138 | - |
|
139 | - if ($c === null) { |
|
140 | - if ($this->inputIndex < $this->inputLength) { |
|
141 | - $c = $this->input[$this->inputIndex]; |
|
142 | - $this->inputIndex += 1; |
|
143 | - } else { |
|
144 | - $c = null; |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - if ($c === "\r") { |
|
149 | - return "\n"; |
|
150 | - } |
|
151 | - |
|
152 | - if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
153 | - return $c; |
|
154 | - } |
|
155 | - |
|
156 | - return ' '; |
|
136 | + $c = $this->lookAhead; |
|
137 | + $this->lookAhead = null; |
|
138 | + |
|
139 | + if ($c === null) { |
|
140 | + if ($this->inputIndex < $this->inputLength) { |
|
141 | + $c = $this->input[$this->inputIndex]; |
|
142 | + $this->inputIndex += 1; |
|
143 | + } else { |
|
144 | + $c = null; |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + if ($c === "\r") { |
|
149 | + return "\n"; |
|
150 | + } |
|
151 | + |
|
152 | + if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
153 | + return $c; |
|
154 | + } |
|
155 | + |
|
156 | + return ' '; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | protected function isAlphaNum($c) { |
160 | - return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
160 | + return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | protected function min() { |
164 | - $this->a = "\n"; |
|
165 | - $this->action(3); |
|
166 | - |
|
167 | - while ($this->a !== null) { |
|
168 | - switch ($this->a) { |
|
169 | - case ' ': |
|
170 | - if ($this->isAlphaNum($this->b)) { |
|
171 | - $this->action(1); |
|
172 | - } else { |
|
173 | - $this->action(2); |
|
174 | - } |
|
175 | - break; |
|
176 | - |
|
177 | - case "\n": |
|
178 | - switch ($this->b) { |
|
179 | - case '{': |
|
180 | - case '[': |
|
181 | - case '(': |
|
182 | - case '+': |
|
183 | - case '-': |
|
184 | - $this->action(1); |
|
185 | - break; |
|
186 | - |
|
187 | - case ' ': |
|
188 | - $this->action(3); |
|
189 | - break; |
|
190 | - |
|
191 | - default: |
|
192 | - if ($this->isAlphaNum($this->b)) { |
|
193 | - $this->action(1); |
|
194 | - } |
|
195 | - else { |
|
196 | - $this->action(2); |
|
197 | - } |
|
198 | - } |
|
199 | - break; |
|
200 | - |
|
201 | - default: |
|
202 | - switch ($this->b) { |
|
203 | - case ' ': |
|
204 | - if ($this->isAlphaNum($this->a)) { |
|
205 | - $this->action(1); |
|
206 | - break; |
|
207 | - } |
|
208 | - |
|
209 | - $this->action(3); |
|
210 | - break; |
|
211 | - |
|
212 | - case "\n": |
|
213 | - switch ($this->a) { |
|
214 | - case '}': |
|
215 | - case ']': |
|
216 | - case ')': |
|
217 | - case '+': |
|
218 | - case '-': |
|
219 | - case '"': |
|
220 | - case "'": |
|
221 | - $this->action(1); |
|
222 | - break; |
|
223 | - |
|
224 | - default: |
|
225 | - if ($this->isAlphaNum($this->a)) { |
|
226 | - $this->action(1); |
|
227 | - } |
|
228 | - else { |
|
229 | - $this->action(3); |
|
230 | - } |
|
231 | - } |
|
232 | - break; |
|
233 | - |
|
234 | - default: |
|
235 | - $this->action(1); |
|
236 | - break; |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - return $this->output; |
|
164 | + $this->a = "\n"; |
|
165 | + $this->action(3); |
|
166 | + |
|
167 | + while ($this->a !== null) { |
|
168 | + switch ($this->a) { |
|
169 | + case ' ': |
|
170 | + if ($this->isAlphaNum($this->b)) { |
|
171 | + $this->action(1); |
|
172 | + } else { |
|
173 | + $this->action(2); |
|
174 | + } |
|
175 | + break; |
|
176 | + |
|
177 | + case "\n": |
|
178 | + switch ($this->b) { |
|
179 | + case '{': |
|
180 | + case '[': |
|
181 | + case '(': |
|
182 | + case '+': |
|
183 | + case '-': |
|
184 | + $this->action(1); |
|
185 | + break; |
|
186 | + |
|
187 | + case ' ': |
|
188 | + $this->action(3); |
|
189 | + break; |
|
190 | + |
|
191 | + default: |
|
192 | + if ($this->isAlphaNum($this->b)) { |
|
193 | + $this->action(1); |
|
194 | + } |
|
195 | + else { |
|
196 | + $this->action(2); |
|
197 | + } |
|
198 | + } |
|
199 | + break; |
|
200 | + |
|
201 | + default: |
|
202 | + switch ($this->b) { |
|
203 | + case ' ': |
|
204 | + if ($this->isAlphaNum($this->a)) { |
|
205 | + $this->action(1); |
|
206 | + break; |
|
207 | + } |
|
208 | + |
|
209 | + $this->action(3); |
|
210 | + break; |
|
211 | + |
|
212 | + case "\n": |
|
213 | + switch ($this->a) { |
|
214 | + case '}': |
|
215 | + case ']': |
|
216 | + case ')': |
|
217 | + case '+': |
|
218 | + case '-': |
|
219 | + case '"': |
|
220 | + case "'": |
|
221 | + $this->action(1); |
|
222 | + break; |
|
223 | + |
|
224 | + default: |
|
225 | + if ($this->isAlphaNum($this->a)) { |
|
226 | + $this->action(1); |
|
227 | + } |
|
228 | + else { |
|
229 | + $this->action(3); |
|
230 | + } |
|
231 | + } |
|
232 | + break; |
|
233 | + |
|
234 | + default: |
|
235 | + $this->action(1); |
|
236 | + break; |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + return $this->output; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | protected function next() { |
245 | - $c = $this->get(); |
|
246 | - |
|
247 | - if ($c === '/') { |
|
248 | - switch($this->peek()) { |
|
249 | - case '/': |
|
250 | - for (;;) { |
|
251 | - $c = $this->get(); |
|
252 | - |
|
253 | - if (ord($c) <= self::ORD_LF) { |
|
254 | - return $c; |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - case '*': |
|
259 | - $this->get(); |
|
260 | - |
|
261 | - for (;;) { |
|
262 | - switch($this->get()) { |
|
263 | - case '*': |
|
264 | - if ($this->peek() === '/') { |
|
265 | - $this->get(); |
|
266 | - return ' '; |
|
267 | - } |
|
268 | - break; |
|
269 | - |
|
270 | - case null: |
|
271 | - throw new JSMinException('Unterminated comment.'); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - default: |
|
276 | - return $c; |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - return $c; |
|
245 | + $c = $this->get(); |
|
246 | + |
|
247 | + if ($c === '/') { |
|
248 | + switch($this->peek()) { |
|
249 | + case '/': |
|
250 | + for (;;) { |
|
251 | + $c = $this->get(); |
|
252 | + |
|
253 | + if (ord($c) <= self::ORD_LF) { |
|
254 | + return $c; |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + case '*': |
|
259 | + $this->get(); |
|
260 | + |
|
261 | + for (;;) { |
|
262 | + switch($this->get()) { |
|
263 | + case '*': |
|
264 | + if ($this->peek() === '/') { |
|
265 | + $this->get(); |
|
266 | + return ' '; |
|
267 | + } |
|
268 | + break; |
|
269 | + |
|
270 | + case null: |
|
271 | + throw new JSMinException('Unterminated comment.'); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + default: |
|
276 | + return $c; |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + return $c; |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | protected function peek() { |
284 | - $this->lookAhead = $this->get(); |
|
285 | - return $this->lookAhead; |
|
284 | + $this->lookAhead = $this->get(); |
|
285 | + return $this->lookAhead; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 |
@@ -191,8 +191,7 @@ discard block |
||
191 | 191 | default: |
192 | 192 | if ($this->isAlphaNum($this->b)) { |
193 | 193 | $this->action(1); |
194 | - } |
|
195 | - else { |
|
194 | + } else { |
|
196 | 195 | $this->action(2); |
197 | 196 | } |
198 | 197 | } |
@@ -224,8 +223,7 @@ discard block |
||
224 | 223 | default: |
225 | 224 | if ($this->isAlphaNum($this->a)) { |
226 | 225 | $this->action(1); |
227 | - } |
|
228 | - else { |
|
226 | + } else { |
|
229 | 227 | $this->action(3); |
230 | 228 | } |
231 | 229 | } |
@@ -46,29 +46,29 @@ discard block |
||
46 | 46 | */ |
47 | 47 | |
48 | 48 | class JSMin { |
49 | - const ORD_LF = 10; |
|
50 | - const ORD_SPACE = 32; |
|
49 | + const ORD_LF=10; |
|
50 | + const ORD_SPACE=32; |
|
51 | 51 | |
52 | - protected $a = ''; |
|
53 | - protected $b = ''; |
|
54 | - protected $input = ''; |
|
55 | - protected $inputIndex = 0; |
|
56 | - protected $inputLength = 0; |
|
57 | - protected $lookAhead = null; |
|
58 | - protected $output = ''; |
|
52 | + protected $a=''; |
|
53 | + protected $b=''; |
|
54 | + protected $input=''; |
|
55 | + protected $inputIndex=0; |
|
56 | + protected $inputLength=0; |
|
57 | + protected $lookAhead=null; |
|
58 | + protected $output=''; |
|
59 | 59 | |
60 | 60 | // -- Public Static Methods -------------------------------------------------- |
61 | 61 | |
62 | 62 | public static function minify($js) { |
63 | - $jsmin = new JSMin($js); |
|
63 | + $jsmin=new JSMin($js); |
|
64 | 64 | return $jsmin->min(); |
65 | 65 | } |
66 | 66 | |
67 | 67 | // -- Public Instance Methods ------------------------------------------------ |
68 | 68 | |
69 | 69 | public function __construct($input) { |
70 | - $this->input = str_replace("\r\n", "\n", $input); |
|
71 | - $this->inputLength = strlen($this->input); |
|
70 | + $this->input=str_replace("\r\n", "\n", $input); |
|
71 | + $this->inputLength=strlen($this->input); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
@@ -76,80 +76,80 @@ discard block |
||
76 | 76 | protected function action($d) { |
77 | 77 | switch($d) { |
78 | 78 | case 1: |
79 | - $this->output .= $this->a; |
|
79 | + $this->output.=$this->a; |
|
80 | 80 | |
81 | 81 | case 2: |
82 | - $this->a = $this->b; |
|
82 | + $this->a=$this->b; |
|
83 | 83 | |
84 | - if ($this->a === "'" || $this->a === '"') { |
|
85 | - for (;;) { |
|
86 | - $this->output .= $this->a; |
|
87 | - $this->a = $this->get(); |
|
84 | + if($this->a==="'" || $this->a==='"') { |
|
85 | + for(;;) { |
|
86 | + $this->output.=$this->a; |
|
87 | + $this->a=$this->get(); |
|
88 | 88 | |
89 | - if ($this->a === $this->b) { |
|
89 | + if($this->a===$this->b) { |
|
90 | 90 | break; |
91 | 91 | } |
92 | 92 | |
93 | - if (ord($this->a) <= self::ORD_LF) { |
|
93 | + if(ord($this->a) <= self::ORD_LF) { |
|
94 | 94 | throw new JSMinException('Unterminated string literal.'); |
95 | 95 | } |
96 | 96 | |
97 | - if ($this->a === '\\') { |
|
98 | - $this->output .= $this->a; |
|
99 | - $this->a = $this->get(); |
|
97 | + if($this->a==='\\') { |
|
98 | + $this->output.=$this->a; |
|
99 | + $this->a=$this->get(); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | 104 | case 3: |
105 | - $this->b = $this->next(); |
|
105 | + $this->b=$this->next(); |
|
106 | 106 | |
107 | - if ($this->b === '/' && ( |
|
108 | - $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
109 | - $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
110 | - $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
107 | + if($this->b==='/' && ( |
|
108 | + $this->a==='(' || $this->a===',' || $this->a==='=' || |
|
109 | + $this->a===':' || $this->a==='[' || $this->a==='!' || |
|
110 | + $this->a==='&' || $this->a==='|' || $this->a==='?')) { |
|
111 | 111 | |
112 | - $this->output .= $this->a . $this->b; |
|
112 | + $this->output.=$this->a.$this->b; |
|
113 | 113 | |
114 | - for (;;) { |
|
115 | - $this->a = $this->get(); |
|
114 | + for(;;) { |
|
115 | + $this->a=$this->get(); |
|
116 | 116 | |
117 | - if ($this->a === '/') { |
|
117 | + if($this->a==='/') { |
|
118 | 118 | break; |
119 | - } elseif ($this->a === '\\') { |
|
120 | - $this->output .= $this->a; |
|
121 | - $this->a = $this->get(); |
|
122 | - } elseif (ord($this->a) <= self::ORD_LF) { |
|
119 | + } elseif($this->a==='\\') { |
|
120 | + $this->output.=$this->a; |
|
121 | + $this->a=$this->get(); |
|
122 | + } elseif(ord($this->a) <= self::ORD_LF) { |
|
123 | 123 | throw new JSMinException('Unterminated regular expression '. |
124 | 124 | 'literal.'); |
125 | 125 | } |
126 | 126 | |
127 | - $this->output .= $this->a; |
|
127 | + $this->output.=$this->a; |
|
128 | 128 | } |
129 | 129 | |
130 | - $this->b = $this->next(); |
|
130 | + $this->b=$this->next(); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | 135 | protected function get() { |
136 | - $c = $this->lookAhead; |
|
137 | - $this->lookAhead = null; |
|
136 | + $c=$this->lookAhead; |
|
137 | + $this->lookAhead=null; |
|
138 | 138 | |
139 | - if ($c === null) { |
|
140 | - if ($this->inputIndex < $this->inputLength) { |
|
141 | - $c = $this->input[$this->inputIndex]; |
|
142 | - $this->inputIndex += 1; |
|
139 | + if($c===null) { |
|
140 | + if($this->inputIndex < $this->inputLength) { |
|
141 | + $c=$this->input[$this->inputIndex]; |
|
142 | + $this->inputIndex+=1; |
|
143 | 143 | } else { |
144 | - $c = null; |
|
144 | + $c=null; |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | - if ($c === "\r") { |
|
148 | + if($c==="\r") { |
|
149 | 149 | return "\n"; |
150 | 150 | } |
151 | 151 | |
152 | - if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
152 | + if($c===null || $c==="\n" || ord($c) >= self::ORD_SPACE) { |
|
153 | 153 | return $c; |
154 | 154 | } |
155 | 155 | |
@@ -157,17 +157,17 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | protected function isAlphaNum($c) { |
160 | - return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
160 | + return ord($c) > 126 || $c==='\\' || preg_match('/^[\w\$]$/', $c)===1; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | protected function min() { |
164 | - $this->a = "\n"; |
|
164 | + $this->a="\n"; |
|
165 | 165 | $this->action(3); |
166 | 166 | |
167 | - while ($this->a !== null) { |
|
168 | - switch ($this->a) { |
|
167 | + while($this->a!==null) { |
|
168 | + switch($this->a) { |
|
169 | 169 | case ' ': |
170 | - if ($this->isAlphaNum($this->b)) { |
|
170 | + if($this->isAlphaNum($this->b)) { |
|
171 | 171 | $this->action(1); |
172 | 172 | } else { |
173 | 173 | $this->action(2); |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | break; |
176 | 176 | |
177 | 177 | case "\n": |
178 | - switch ($this->b) { |
|
178 | + switch($this->b) { |
|
179 | 179 | case '{': |
180 | 180 | case '[': |
181 | 181 | case '(': |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | break; |
190 | 190 | |
191 | 191 | default: |
192 | - if ($this->isAlphaNum($this->b)) { |
|
192 | + if($this->isAlphaNum($this->b)) { |
|
193 | 193 | $this->action(1); |
194 | 194 | } |
195 | 195 | else { |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | break; |
200 | 200 | |
201 | 201 | default: |
202 | - switch ($this->b) { |
|
202 | + switch($this->b) { |
|
203 | 203 | case ' ': |
204 | - if ($this->isAlphaNum($this->a)) { |
|
204 | + if($this->isAlphaNum($this->a)) { |
|
205 | 205 | $this->action(1); |
206 | 206 | break; |
207 | 207 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | break; |
211 | 211 | |
212 | 212 | case "\n": |
213 | - switch ($this->a) { |
|
213 | + switch($this->a) { |
|
214 | 214 | case '}': |
215 | 215 | case ']': |
216 | 216 | case ')': |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | break; |
223 | 223 | |
224 | 224 | default: |
225 | - if ($this->isAlphaNum($this->a)) { |
|
225 | + if($this->isAlphaNum($this->a)) { |
|
226 | 226 | $this->action(1); |
227 | 227 | } |
228 | 228 | else { |
@@ -242,15 +242,15 @@ discard block |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | protected function next() { |
245 | - $c = $this->get(); |
|
245 | + $c=$this->get(); |
|
246 | 246 | |
247 | - if ($c === '/') { |
|
247 | + if($c==='/') { |
|
248 | 248 | switch($this->peek()) { |
249 | 249 | case '/': |
250 | - for (;;) { |
|
251 | - $c = $this->get(); |
|
250 | + for(;;) { |
|
251 | + $c=$this->get(); |
|
252 | 252 | |
253 | - if (ord($c) <= self::ORD_LF) { |
|
253 | + if(ord($c) <= self::ORD_LF) { |
|
254 | 254 | return $c; |
255 | 255 | } |
256 | 256 | } |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | case '*': |
259 | 259 | $this->get(); |
260 | 260 | |
261 | - for (;;) { |
|
261 | + for(;;) { |
|
262 | 262 | switch($this->get()) { |
263 | 263 | case '*': |
264 | - if ($this->peek() === '/') { |
|
264 | + if($this->peek()==='/') { |
|
265 | 265 | $this->get(); |
266 | 266 | return ' '; |
267 | 267 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | protected function peek() { |
284 | - $this->lookAhead = $this->get(); |
|
284 | + $this->lookAhead=$this->get(); |
|
285 | 285 | return $this->lookAhead; |
286 | 286 | } |
287 | 287 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | - * @return Marks a string as a javascript function. Once marke, the string is considered as a |
|
96 | + * @return TJavaScriptLiteral a string as a javascript function. Once marke, the string is considered as a |
|
97 | 97 | * raw javascript function that is not supposed to be encoded by {@link encode} |
98 | 98 | */ |
99 | 99 | public static function quoteJsLiteral($js) |
@@ -256,6 +256,7 @@ discard block |
||
256 | 256 | * @param string string to be decoded |
257 | 257 | * @param bool whether to convert returned objects to associative arrays |
258 | 258 | * @param int recursion depth |
259 | + * @param string $value |
|
259 | 260 | * @return mixed decoded variable |
260 | 261 | */ |
261 | 262 | public static function jsonDecode($value, $assoc = false, $depth = 512) |
@@ -298,7 +299,8 @@ discard block |
||
298 | 299 | * Minimize the size of a javascript script. |
299 | 300 | * This method is based on Douglas Crockford's JSMin. |
300 | 301 | * @param string code that you want to minimzie |
301 | - * @return minimized version of the code |
|
302 | + * @param string $code |
|
303 | + * @return string version of the code |
|
302 | 304 | */ |
303 | 305 | public static function JSMin($code) |
304 | 306 | { |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | $str=''; |
32 | 32 | foreach($files as $file) |
33 | - $str.= self::renderScriptFile($file); |
|
33 | + $str.=self::renderScriptFile($file); |
|
34 | 34 | return $str; |
35 | 35 | } |
36 | 36 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public static function renderScriptBlocks($scripts) |
53 | 53 | { |
54 | 54 | if(count($scripts)) |
55 | - return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n",$scripts)."\n/*]]>*/\n</script>\n"; |
|
55 | + return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n", $scripts)."\n/*]]>*/\n</script>\n"; |
|
56 | 56 | else |
57 | 57 | return ''; |
58 | 58 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | public static function renderScriptBlocksCallback($scripts) |
66 | 66 | { |
67 | 67 | if(count($scripts)) |
68 | - return implode("\n",$scripts)."\n"; |
|
68 | + return implode("\n", $scripts)."\n"; |
|
69 | 69 | else |
70 | 70 | return ''; |
71 | 71 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public static function quoteString($js) |
91 | 91 | { |
92 | - return self::jsonEncode($js,JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG); |
|
92 | + return self::jsonEncode($js, JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | * @param boolean wether to encode empty strings too. Default to false for BC. |
151 | 151 | * @return string the encoded string |
152 | 152 | */ |
153 | - public static function encode($value,$toMap=true,$encodeEmptyStrings=false) |
|
153 | + public static function encode($value, $toMap=true, $encodeEmptyStrings=false) |
|
154 | 154 | { |
155 | 155 | if(is_string($value)) |
156 | 156 | return self::quoteString($value); |
157 | 157 | else if(is_bool($value)) |
158 | - return $value?'true':'false'; |
|
158 | + return $value ? 'true' : 'false'; |
|
159 | 159 | else if(is_array($value)) |
160 | 160 | { |
161 | 161 | $results=''; |
162 | - if(($n=count($value))>0 && array_keys($value)!==range(0,$n-1)) |
|
162 | + if(($n=count($value)) > 0 && array_keys($value)!==range(0, $n - 1)) |
|
163 | 163 | { |
164 | 164 | foreach($value as $k=>$v) |
165 | 165 | { |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | { |
168 | 168 | if($results!=='') |
169 | 169 | $results.=','; |
170 | - $results.="'$k':".self::encode($v,$toMap,$encodeEmptyStrings); |
|
170 | + $results.="'$k':".self::encode($v, $toMap, $encodeEmptyStrings); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | return '{'.$results.'}'; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | if($results!=='') |
182 | 182 | $results.=','; |
183 | - $results.=self::encode($v,$toMap, $encodeEmptyStrings); |
|
183 | + $results.=self::encode($v, $toMap, $encodeEmptyStrings); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | return '['.$results.']'; |
@@ -208,10 +208,10 @@ discard block |
||
208 | 208 | } |
209 | 209 | } |
210 | 210 | else if(is_object($value)) |
211 | - if ($value instanceof TJavaScriptLiteral) |
|
211 | + if($value instanceof TJavaScriptLiteral) |
|
212 | 212 | return $value->toJavaScriptLiteral(); |
213 | 213 | else |
214 | - return self::encode(get_object_vars($value),$toMap); |
|
214 | + return self::encode(get_object_vars($value), $toMap); |
|
215 | 215 | else if($value===null) |
216 | 216 | return 'null'; |
217 | 217 | else |
@@ -223,14 +223,14 @@ discard block |
||
223 | 223 | * @param mixed variable to be encoded |
224 | 224 | * @return string encoded string |
225 | 225 | */ |
226 | - public static function jsonEncode($value, $options = 0) |
|
226 | + public static function jsonEncode($value, $options=0) |
|
227 | 227 | { |
228 | - if (($g=Prado::getApplication()->getGlobalization(false))!==null && |
|
228 | + if(($g=Prado::getApplication()->getGlobalization(false))!==null && |
|
229 | 229 | strtoupper($enc=$g->getCharset())!='UTF-8') { |
230 | 230 | self::convertToUtf8($value, $enc); |
231 | 231 | } |
232 | 232 | |
233 | - $s = @json_encode($value,$options); |
|
233 | + $s=@json_encode($value, $options); |
|
234 | 234 | self::checkJsonError(); |
235 | 235 | return $s; |
236 | 236 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | private static function convertToUtf8(&$value, $sourceEncoding) { |
244 | 244 | if(is_string($value)) |
245 | 245 | $value=iconv($sourceEncoding, 'UTF-8', $value); |
246 | - else if (is_array($value)) |
|
246 | + else if(is_array($value)) |
|
247 | 247 | { |
248 | 248 | foreach($value as &$element) |
249 | 249 | self::convertToUtf8($element, $sourceEncoding); |
@@ -258,37 +258,37 @@ discard block |
||
258 | 258 | * @param int recursion depth |
259 | 259 | * @return mixed decoded variable |
260 | 260 | */ |
261 | - public static function jsonDecode($value, $assoc = false, $depth = 512) |
|
261 | + public static function jsonDecode($value, $assoc=false, $depth=512) |
|
262 | 262 | { |
263 | - $s= @json_decode($value, $assoc, $depth); |
|
263 | + $s=@json_decode($value, $assoc, $depth); |
|
264 | 264 | self::checkJsonError(); |
265 | 265 | return $s; |
266 | 266 | } |
267 | 267 | |
268 | 268 | private static function checkJsonError() |
269 | 269 | { |
270 | - switch ($err = json_last_error()) |
|
270 | + switch($err=json_last_error()) |
|
271 | 271 | { |
272 | 272 | case JSON_ERROR_NONE: |
273 | 273 | return; |
274 | 274 | break; |
275 | 275 | case JSON_ERROR_DEPTH: |
276 | - $msg = 'Maximum stack depth exceeded'; |
|
276 | + $msg='Maximum stack depth exceeded'; |
|
277 | 277 | break; |
278 | 278 | case JSON_ERROR_STATE_MISMATCH: |
279 | - $msg = 'Underflow or the modes mismatch'; |
|
279 | + $msg='Underflow or the modes mismatch'; |
|
280 | 280 | break; |
281 | 281 | case JSON_ERROR_CTRL_CHAR: |
282 | - $msg = 'Unexpected control character found'; |
|
282 | + $msg='Unexpected control character found'; |
|
283 | 283 | break; |
284 | 284 | case JSON_ERROR_SYNTAX: |
285 | - $msg = 'Syntax error, malformed JSON'; |
|
285 | + $msg='Syntax error, malformed JSON'; |
|
286 | 286 | break; |
287 | 287 | case JSON_ERROR_UTF8: |
288 | - $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
288 | + $msg='Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
289 | 289 | break; |
290 | 290 | default: |
291 | - $msg = 'Unknown error'; |
|
291 | + $msg='Unknown error'; |
|
292 | 292 | break; |
293 | 293 | } |
294 | 294 | throw new Exception("JSON error ($err): $msg"); |
@@ -171,8 +171,7 @@ discard block |
||
171 | 171 | } |
172 | 172 | } |
173 | 173 | return '{'.$results.'}'; |
174 | - } |
|
175 | - else |
|
174 | + } else |
|
176 | 175 | { |
177 | 176 | foreach($value as $v) |
178 | 177 | { |
@@ -185,8 +184,7 @@ discard block |
||
185 | 184 | } |
186 | 185 | return '['.$results.']'; |
187 | 186 | } |
188 | - } |
|
189 | - else if(is_integer($value)) |
|
187 | + } else if(is_integer($value)) |
|
190 | 188 | return "$value"; |
191 | 189 | else if(is_float($value)) |
192 | 190 | { |
@@ -206,8 +204,7 @@ discard block |
||
206 | 204 | return str_replace($locale['decimal_point'], '.', "$value"); |
207 | 205 | break; |
208 | 206 | } |
209 | - } |
|
210 | - else if(is_object($value)) |
|
207 | + } else if(is_object($value)) |
|
211 | 208 | if ($value instanceof TJavaScriptLiteral) |
212 | 209 | return $value->toJavaScriptLiteral(); |
213 | 210 | else |
@@ -140,6 +140,7 @@ |
||
140 | 140 | /** |
141 | 141 | * Renders content provided by TJsonResponse::getJsonContent() as |
142 | 142 | * javascript in JSON format. |
143 | + * @param TJsonResponse $service |
|
143 | 144 | */ |
144 | 145 | protected function createJsonResponse($service,$properties,$config) |
145 | 146 | { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | if(is_array($config)) |
78 | 78 | { |
79 | 79 | foreach($config['json'] as $id => $json) |
80 | - $this->_services[$id] = $json; |
|
80 | + $this->_services[$id]=$json; |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | else |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | $service=Prado::createComponent($serviceConfig['class']); |
110 | 110 | if($service instanceof TJsonResponse) |
111 | 111 | { |
112 | - $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array(); |
|
113 | - $this->createJsonResponse($service,$properties,$serviceConfig); |
|
112 | + $properties=isset($serviceConfig['properties']) ? $serviceConfig['properties'] : array(); |
|
113 | + $this->createJsonResponse($service, $properties, $serviceConfig); |
|
114 | 114 | } |
115 | 115 | else |
116 | - throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
116 | + throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
117 | 117 | } |
118 | 118 | else |
119 | - throw new TConfigurationException('jsonservice_class_required',$id); |
|
119 | + throw new TConfigurationException('jsonservice_class_required', $id); |
|
120 | 120 | } |
121 | 121 | else |
122 | 122 | { |
@@ -125,33 +125,33 @@ discard block |
||
125 | 125 | { |
126 | 126 | $service=Prado::createComponent($class); |
127 | 127 | if($service instanceof TJsonResponse) |
128 | - $this->createJsonResponse($service,$properties,$serviceConfig); |
|
128 | + $this->createJsonResponse($service, $properties, $serviceConfig); |
|
129 | 129 | else |
130 | - throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
130 | + throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
131 | 131 | } |
132 | 132 | else |
133 | - throw new TConfigurationException('jsonservice_class_required',$id); |
|
133 | + throw new TConfigurationException('jsonservice_class_required', $id); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | else |
137 | - throw new THttpException(404,'jsonservice_provider_unknown',$id); |
|
137 | + throw new THttpException(404, 'jsonservice_provider_unknown', $id); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Renders content provided by TJsonResponse::getJsonContent() as |
142 | 142 | * javascript in JSON format. |
143 | 143 | */ |
144 | - protected function createJsonResponse($service,$properties,$config) |
|
144 | + protected function createJsonResponse($service, $properties, $config) |
|
145 | 145 | { |
146 | 146 | // init service properties |
147 | 147 | foreach($properties as $name=>$value) |
148 | - $service->setSubproperty($name,$value); |
|
148 | + $service->setSubproperty($name, $value); |
|
149 | 149 | $service->init($config); |
150 | 150 | |
151 | 151 | //send content if not null |
152 | 152 | if(($content=$service->getJsonContent())!==null) |
153 | 153 | { |
154 | - $response = $this->getResponse(); |
|
154 | + $response=$this->getResponse(); |
|
155 | 155 | $response->setContentType('application/json'); |
156 | 156 | $response->setCharset('UTF-8'); |
157 | 157 | //send content |
@@ -79,8 +79,7 @@ discard block |
||
79 | 79 | foreach($config['json'] as $id => $json) |
80 | 80 | $this->_services[$id] = $json; |
81 | 81 | } |
82 | - } |
|
83 | - else |
|
82 | + } else |
|
84 | 83 | { |
85 | 84 | foreach($config->getElementsByTagName('json') as $json) |
86 | 85 | { |
@@ -111,14 +110,11 @@ discard block |
||
111 | 110 | { |
112 | 111 | $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array(); |
113 | 112 | $this->createJsonResponse($service,$properties,$serviceConfig); |
114 | - } |
|
115 | - else |
|
113 | + } else |
|
116 | 114 | throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
117 | - } |
|
118 | - else |
|
115 | + } else |
|
119 | 116 | throw new TConfigurationException('jsonservice_class_required',$id); |
120 | - } |
|
121 | - else |
|
117 | + } else |
|
122 | 118 | { |
123 | 119 | $properties=$serviceConfig->getAttributes(); |
124 | 120 | if(($class=$properties->remove('class'))!==null) |
@@ -128,12 +124,10 @@ discard block |
||
128 | 124 | $this->createJsonResponse($service,$properties,$serviceConfig); |
129 | 125 | else |
130 | 126 | throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
131 | - } |
|
132 | - else |
|
127 | + } else |
|
133 | 128 | throw new TConfigurationException('jsonservice_class_required',$id); |
134 | 129 | } |
135 | - } |
|
136 | - else |
|
130 | + } else |
|
137 | 131 | throw new THttpException(404,'jsonservice_provider_unknown',$id); |
138 | 132 | } |
139 | 133 |
@@ -369,6 +369,7 @@ discard block |
||
369 | 369 | |
370 | 370 | /** |
371 | 371 | * @param string default page path to be served if no explicit page is request |
372 | + * @param string $value |
|
372 | 373 | * @throws TInvalidOperationException if the page service is initialized |
373 | 374 | */ |
374 | 375 | public function setDefaultPage($value) |
@@ -528,6 +529,7 @@ discard block |
||
528 | 529 | * @param array list of GET parameters, null if no GET parameters required |
529 | 530 | * @param boolean whether to encode the ampersand in URL, defaults to true. |
530 | 531 | * @param boolean whether to encode the GET parameters (their names and values), defaults to true. |
532 | + * @param string $pagePath |
|
531 | 533 | * @return string URL for the page and GET parameters |
532 | 534 | */ |
533 | 535 | public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=true,$encodeGetItems=true) |
@@ -670,6 +672,9 @@ discard block |
||
670 | 672 | } |
671 | 673 | } |
672 | 674 | |
675 | + /** |
|
676 | + * @param string $configPath |
|
677 | + */ |
|
673 | 678 | public function loadFromPhp($config,$configPath,$configPagePath) |
674 | 679 | { |
675 | 680 | $this->loadApplicationConfigurationFromPhp($config,$configPath); |
@@ -683,6 +688,8 @@ discard block |
||
683 | 688 | * @param TXmlElement config xml element |
684 | 689 | * @param string the directory containing this configuration |
685 | 690 | * @param string the page path that the config XML is associated with. The page path doesn't include the page name. |
691 | + * @param TXmlDocument $dom |
|
692 | + * @param string $configPath |
|
686 | 693 | */ |
687 | 694 | public function loadFromXml($dom,$configPath,$configPagePath) |
688 | 695 | { |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function init($config) |
149 | 149 | { |
150 | - Prado::trace("Initializing TPageService",'System.Web.Services.TPageService'); |
|
150 | + Prado::trace("Initializing TPageService", 'System.Web.Services.TPageService'); |
|
151 | 151 | |
152 | 152 | $pageConfig=$this->loadPageConfig($config); |
153 | 153 | |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | // external configurations |
186 | 186 | foreach($config->getExternalConfigurations() as $filePath=>$params) |
187 | 187 | { |
188 | - list($configPagePath,$condition)=$params; |
|
188 | + list($configPagePath, $condition)=$params; |
|
189 | 189 | if($condition!==true) |
190 | 190 | $condition=$this->evaluateExpression($condition); |
191 | 191 | if($condition) |
192 | 192 | { |
193 | - if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path)) |
|
194 | - throw new TConfigurationException('pageservice_includefile_invalid',$filePath); |
|
193 | + if(($path=Prado::getPathOfNamespace($filePath, Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path)) |
|
194 | + throw new TConfigurationException('pageservice_includefile_invalid', $filePath); |
|
195 | 195 | $c=new TPageConfiguration($pagePath); |
196 | - $c->loadFromFile($path,$configPagePath); |
|
196 | + $c->loadFromFile($path, $configPagePath); |
|
197 | 197 | $this->applyConfiguration($c); |
198 | 198 | } |
199 | 199 | } |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | if($config!==null) |
228 | 228 | { |
229 | 229 | if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
230 | - $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
230 | + $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); |
|
231 | 231 | else |
232 | - $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
232 | + $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); |
|
233 | 233 | } |
234 | 234 | $pageConfig->loadFromFiles($this->getBasePath()); |
235 | 235 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | $arr=$cache->get(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath); |
241 | 241 | if(is_array($arr)) |
242 | 242 | { |
243 | - list($pageConfig,$timestamps)=$arr; |
|
243 | + list($pageConfig, $timestamps)=$arr; |
|
244 | 244 | if($application->getMode()!==TApplicationMode::Performance) |
245 | 245 | { |
246 | 246 | foreach($timestamps as $fileName=>$timestamp) |
@@ -248,14 +248,14 @@ discard block |
||
248 | 248 | if($fileName===0) // application config file |
249 | 249 | { |
250 | 250 | $appConfigFile=$application->getConfigurationFile(); |
251 | - $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); |
|
252 | - if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0])) |
|
251 | + $currentTimestamp[0]=$appConfigFile===null ? 0 : @filemtime($appConfigFile); |
|
252 | + if($currentTimestamp[0] > $timestamp || ($timestamp > 0 && !$currentTimestamp[0])) |
|
253 | 253 | $configCached=false; |
254 | 254 | } |
255 | 255 | else |
256 | 256 | { |
257 | 257 | $currentTimestamp[$fileName]=@filemtime($fileName); |
258 | - if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName])) |
|
258 | + if($currentTimestamp[$fileName] > $timestamp || ($timestamp > 0 && !$currentTimestamp[$fileName])) |
|
259 | 259 | $configCached=false; |
260 | 260 | } |
261 | 261 | } |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | else |
265 | 265 | { |
266 | 266 | $configCached=false; |
267 | - $paths=explode('.',$pagePath); |
|
267 | + $paths=explode('.', $pagePath); |
|
268 | 268 | $configPath=$this->getBasePath(); |
269 | - $fileName = $this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP |
|
269 | + $fileName=$this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP |
|
270 | 270 | ? self::CONFIG_FILE_PHP |
271 | 271 | : self::CONFIG_FILE_XML; |
272 | 272 | foreach($paths as $path) |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | $configPath.=DIRECTORY_SEPARATOR.$path; |
277 | 277 | } |
278 | 278 | $appConfigFile=$application->getConfigurationFile(); |
279 | - $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); |
|
279 | + $currentTimestamp[0]=$appConfigFile===null ? 0 : @filemtime($appConfigFile); |
|
280 | 280 | } |
281 | 281 | if(!$configCached) |
282 | 282 | { |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | if($config!==null) |
285 | 285 | { |
286 | 286 | if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
287 | - $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
287 | + $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); |
|
288 | 288 | else |
289 | - $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
289 | + $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); |
|
290 | 290 | } |
291 | 291 | $pageConfig->loadFromFiles($this->getBasePath()); |
292 | - $cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath,array($pageConfig,$currentTimestamp)); |
|
292 | + $cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath, array($pageConfig, $currentTimestamp)); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | return $pageConfig; |
@@ -344,9 +344,9 @@ discard block |
||
344 | 344 | { |
345 | 345 | if($this->_pagePath===null) |
346 | 346 | { |
347 | - $this->_pagePath=strtr($this->determineRequestedPagePath(),'/\\','..'); |
|
347 | + $this->_pagePath=strtr($this->determineRequestedPagePath(), '/\\', '..'); |
|
348 | 348 | if(empty($this->_pagePath)) |
349 | - throw new THttpException(404,'pageservice_page_required'); |
|
349 | + throw new THttpException(404, 'pageservice_page_required'); |
|
350 | 350 | } |
351 | 351 | return $this->_pagePath; |
352 | 352 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | { |
400 | 400 | $basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::FALLBACK_BASEPATH; |
401 | 401 | if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) |
402 | - throw new TConfigurationException('pageservice_basepath_invalid',$basePath); |
|
402 | + throw new TConfigurationException('pageservice_basepath_invalid', $basePath); |
|
403 | 403 | } |
404 | 404 | } |
405 | 405 | return $this->_basePath; |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | if($this->_initialized) |
415 | 415 | throw new TInvalidOperationException('pageservice_basepath_unchangeable'); |
416 | 416 | else if(($path=Prado::getPathOfNamespace($value))===null || !is_dir($path)) |
417 | - throw new TConfigurationException('pageservice_basepath_invalid',$value); |
|
417 | + throw new TConfigurationException('pageservice_basepath_invalid', $value); |
|
418 | 418 | $this->_basePath=realpath($path); |
419 | 419 | } |
420 | 420 | |
@@ -463,9 +463,9 @@ discard block |
||
463 | 463 | */ |
464 | 464 | public function run() |
465 | 465 | { |
466 | - Prado::trace("Running page service",'System.Web.Services.TPageService'); |
|
466 | + Prado::trace("Running page service", 'System.Web.Services.TPageService'); |
|
467 | 467 | $this->_page=$this->createPage($this->getRequestedPagePath()); |
468 | - $this->runPage($this->_page,$this->_properties); |
|
468 | + $this->runPage($this->_page, $this->_properties); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
@@ -477,29 +477,29 @@ discard block |
||
477 | 477 | */ |
478 | 478 | protected function createPage($pagePath) |
479 | 479 | { |
480 | - $path=$this->getBasePath().DIRECTORY_SEPARATOR.strtr($pagePath,'.',DIRECTORY_SEPARATOR); |
|
480 | + $path=$this->getBasePath().DIRECTORY_SEPARATOR.strtr($pagePath, '.', DIRECTORY_SEPARATOR); |
|
481 | 481 | $hasTemplateFile=is_file($path.self::PAGE_FILE_EXT); |
482 | 482 | $hasClassFile=is_file($path.Prado::CLASS_FILE_EXT); |
483 | 483 | |
484 | 484 | if(!$hasTemplateFile && !$hasClassFile) |
485 | - throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
485 | + throw new THttpException(404, 'pageservice_page_unknown', $pagePath); |
|
486 | 486 | |
487 | 487 | if($hasClassFile) |
488 | 488 | { |
489 | 489 | $className=basename($path); |
490 | - if(!class_exists($className,false)) |
|
490 | + if(!class_exists($className, false)) |
|
491 | 491 | include_once($path.Prado::CLASS_FILE_EXT); |
492 | 492 | } |
493 | 493 | else |
494 | 494 | { |
495 | 495 | $className=$this->getBasePageClass(); |
496 | 496 | Prado::using($className); |
497 | - if(($pos=strrpos($className,'.'))!==false) |
|
498 | - $className=substr($className,$pos+1); |
|
497 | + if(($pos=strrpos($className, '.'))!==false) |
|
498 | + $className=substr($className, $pos + 1); |
|
499 | 499 | } |
500 | 500 | |
501 | - if(!class_exists($className,false) || ($className!=='TPage' && !is_subclass_of($className,'TPage'))) |
|
502 | - throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
501 | + if(!class_exists($className, false) || ($className!=='TPage' && !is_subclass_of($className, 'TPage'))) |
|
502 | + throw new THttpException(404, 'pageservice_page_unknown', $pagePath); |
|
503 | 503 | |
504 | 504 | $page=Prado::createComponent($className); |
505 | 505 | $page->setPagePath($pagePath); |
@@ -515,10 +515,10 @@ discard block |
||
515 | 515 | * @param TPage the page instance to be run |
516 | 516 | * @param array list of initial page properties |
517 | 517 | */ |
518 | - protected function runPage($page,$properties) |
|
518 | + protected function runPage($page, $properties) |
|
519 | 519 | { |
520 | 520 | foreach($properties as $name=>$value) |
521 | - $page->setSubProperty($name,$value); |
|
521 | + $page->setSubProperty($name, $value); |
|
522 | 522 | $page->run($this->getResponse()->createHtmlWriter()); |
523 | 523 | } |
524 | 524 | |
@@ -530,9 +530,9 @@ discard block |
||
530 | 530 | * @param boolean whether to encode the GET parameters (their names and values), defaults to true. |
531 | 531 | * @return string URL for the page and GET parameters |
532 | 532 | */ |
533 | - public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=true,$encodeGetItems=true) |
|
533 | + public function constructUrl($pagePath, $getParams=null, $encodeAmpersand=true, $encodeGetItems=true) |
|
534 | 534 | { |
535 | - return $this->getRequest()->constructUrl($this->getID(),$pagePath,$getParams,$encodeAmpersand,$encodeGetItems); |
|
535 | + return $this->getRequest()->constructUrl($this->getID(), $pagePath, $getParams, $encodeAmpersand, $encodeGetItems); |
|
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
@@ -624,23 +624,23 @@ discard block |
||
624 | 624 | */ |
625 | 625 | public function loadFromFiles($basePath) |
626 | 626 | { |
627 | - $paths=explode('.',$this->_pagePath); |
|
627 | + $paths=explode('.', $this->_pagePath); |
|
628 | 628 | $page=array_pop($paths); |
629 | 629 | $path=$basePath; |
630 | 630 | $configPagePath=''; |
631 | - $fileName = Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP |
|
631 | + $fileName=Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP |
|
632 | 632 | ? TPageService::CONFIG_FILE_PHP |
633 | 633 | : TPageService::CONFIG_FILE_XML; |
634 | 634 | foreach($paths as $p) |
635 | 635 | { |
636 | - $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath); |
|
636 | + $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName, $configPagePath); |
|
637 | 637 | $path.=DIRECTORY_SEPARATOR.$p; |
638 | 638 | if($configPagePath==='') |
639 | 639 | $configPagePath=$p; |
640 | 640 | else |
641 | 641 | $configPagePath.='.'.$p; |
642 | 642 | } |
643 | - $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath); |
|
643 | + $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName, $configPagePath); |
|
644 | 644 | $this->_rules=new TAuthorizationRuleCollection($this->_rules); |
645 | 645 | } |
646 | 646 | |
@@ -649,31 +649,31 @@ discard block |
||
649 | 649 | * @param string config file name |
650 | 650 | * @param string the page path that the config file is associated with. The page path doesn't include the page name. |
651 | 651 | */ |
652 | - public function loadFromFile($fname,$configPagePath) |
|
652 | + public function loadFromFile($fname, $configPagePath) |
|
653 | 653 | { |
654 | - Prado::trace("Loading page configuration file $fname",'System.Web.Services.TPageService'); |
|
654 | + Prado::trace("Loading page configuration file $fname", 'System.Web.Services.TPageService'); |
|
655 | 655 | if(empty($fname) || !is_file($fname)) |
656 | 656 | return; |
657 | 657 | |
658 | 658 | if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
659 | 659 | { |
660 | - $fcontent = include $fname; |
|
661 | - $this->loadFromPhp($fcontent,dirname($fname),$configPagePath); |
|
660 | + $fcontent=include $fname; |
|
661 | + $this->loadFromPhp($fcontent, dirname($fname), $configPagePath); |
|
662 | 662 | } |
663 | 663 | else |
664 | 664 | { |
665 | 665 | $dom=new TXmlDocument; |
666 | 666 | if($dom->loadFromFile($fname)) |
667 | - $this->loadFromXml($dom,dirname($fname),$configPagePath); |
|
667 | + $this->loadFromXml($dom, dirname($fname), $configPagePath); |
|
668 | 668 | else |
669 | - throw new TConfigurationException('pageserviceconf_file_invalid',$fname); |
|
669 | + throw new TConfigurationException('pageserviceconf_file_invalid', $fname); |
|
670 | 670 | } |
671 | 671 | } |
672 | 672 | |
673 | - public function loadFromPhp($config,$configPath,$configPagePath) |
|
673 | + public function loadFromPhp($config, $configPath, $configPagePath) |
|
674 | 674 | { |
675 | - $this->loadApplicationConfigurationFromPhp($config,$configPath); |
|
676 | - $this->loadPageConfigurationFromPhp($config,$configPath,$configPagePath); |
|
675 | + $this->loadApplicationConfigurationFromPhp($config, $configPath); |
|
676 | + $this->loadPageConfigurationFromPhp($config, $configPath, $configPagePath); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | /** |
@@ -684,16 +684,16 @@ discard block |
||
684 | 684 | * @param string the directory containing this configuration |
685 | 685 | * @param string the page path that the config XML is associated with. The page path doesn't include the page name. |
686 | 686 | */ |
687 | - public function loadFromXml($dom,$configPath,$configPagePath) |
|
687 | + public function loadFromXml($dom, $configPath, $configPagePath) |
|
688 | 688 | { |
689 | - $this->loadApplicationConfigurationFromXml($dom,$configPath); |
|
690 | - $this->loadPageConfigurationFromXml($dom,$configPath,$configPagePath); |
|
689 | + $this->loadApplicationConfigurationFromXml($dom, $configPath); |
|
690 | + $this->loadPageConfigurationFromXml($dom, $configPath, $configPagePath); |
|
691 | 691 | } |
692 | 692 | |
693 | - public function loadApplicationConfigurationFromPhp($config,$configPath) |
|
693 | + public function loadApplicationConfigurationFromPhp($config, $configPath) |
|
694 | 694 | { |
695 | 695 | $appConfig=new TApplicationConfiguration; |
696 | - $appConfig->loadFromPhp($config,$configPath); |
|
696 | + $appConfig->loadFromPhp($config, $configPath); |
|
697 | 697 | $this->_appConfigs[]=$appConfig; |
698 | 698 | } |
699 | 699 | |
@@ -702,10 +702,10 @@ discard block |
||
702 | 702 | * @param TXmlElement config xml element |
703 | 703 | * @param string base path corresponding to this xml element |
704 | 704 | */ |
705 | - public function loadApplicationConfigurationFromXml($dom,$configPath) |
|
705 | + public function loadApplicationConfigurationFromXml($dom, $configPath) |
|
706 | 706 | { |
707 | 707 | $appConfig=new TApplicationConfiguration; |
708 | - $appConfig->loadFromXml($dom,$configPath); |
|
708 | + $appConfig->loadFromXml($dom, $configPath); |
|
709 | 709 | $this->_appConfigs[]=$appConfig; |
710 | 710 | } |
711 | 711 | |
@@ -714,30 +714,30 @@ discard block |
||
714 | 714 | // authorization |
715 | 715 | if(isset($config['authorization']) && is_array($config['authorization'])) |
716 | 716 | { |
717 | - $rules = array(); |
|
717 | + $rules=array(); |
|
718 | 718 | foreach($config['authorization'] as $authorization) |
719 | 719 | { |
720 | - $patterns=isset($authorization['pages'])?$authorization['pages']:''; |
|
720 | + $patterns=isset($authorization['pages']) ? $authorization['pages'] : ''; |
|
721 | 721 | $ruleApplies=false; |
722 | 722 | if(empty($patterns) || trim($patterns)==='*') // null or empty string |
723 | 723 | $ruleApplies=true; |
724 | 724 | else |
725 | 725 | { |
726 | - foreach(explode(',',$patterns) as $pattern) |
|
726 | + foreach(explode(',', $patterns) as $pattern) |
|
727 | 727 | { |
728 | 728 | if(($pattern=trim($pattern))!=='') |
729 | 729 | { |
730 | 730 | // we know $configPagePath and $this->_pagePath |
731 | 731 | if($configPagePath!=='') // prepend the pattern with ConfigPagePath |
732 | 732 | $pattern=$configPagePath.'.'.$pattern; |
733 | - if(strcasecmp($pattern,$this->_pagePath)===0) |
|
733 | + if(strcasecmp($pattern, $this->_pagePath)===0) |
|
734 | 734 | { |
735 | 735 | $ruleApplies=true; |
736 | 736 | break; |
737 | 737 | } |
738 | - if($pattern[strlen($pattern)-1]==='*') // try wildcard matching |
|
738 | + if($pattern[strlen($pattern) - 1]==='*') // try wildcard matching |
|
739 | 739 | { |
740 | - if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0) |
|
740 | + if(strncasecmp($this->_pagePath, $pattern, strlen($pattern) - 1)===0) |
|
741 | 741 | { |
742 | 742 | $ruleApplies=true; |
743 | 743 | break; |
@@ -748,40 +748,40 @@ discard block |
||
748 | 748 | } |
749 | 749 | if($ruleApplies) |
750 | 750 | { |
751 | - $action = isset($authorization['action'])?$authorization['action']:''; |
|
752 | - $users = isset($authorization['users'])?$authorization['users']:''; |
|
753 | - $roles = isset($authorization['roles'])?$authorization['roles']:''; |
|
754 | - $verb = isset($authorization['verb'])?$authorization['verb']:''; |
|
755 | - $ips = isset($authorization['ips'])?$authorization['ips']:''; |
|
756 | - $rules[]=new TAuthorizationRule($action,$users,$roles,$verb,$ips); |
|
751 | + $action=isset($authorization['action']) ? $authorization['action'] : ''; |
|
752 | + $users=isset($authorization['users']) ? $authorization['users'] : ''; |
|
753 | + $roles=isset($authorization['roles']) ? $authorization['roles'] : ''; |
|
754 | + $verb=isset($authorization['verb']) ? $authorization['verb'] : ''; |
|
755 | + $ips=isset($authorization['ips']) ? $authorization['ips'] : ''; |
|
756 | + $rules[]=new TAuthorizationRule($action, $users, $roles, $verb, $ips); |
|
757 | 757 | } |
758 | 758 | } |
759 | - $this->_rules=array_merge($rules,$this->_rules); |
|
759 | + $this->_rules=array_merge($rules, $this->_rules); |
|
760 | 760 | } |
761 | 761 | // pages |
762 | 762 | if(isset($config['pages']) && is_array($config['pages'])) |
763 | 763 | { |
764 | 764 | if(isset($config['pages']['properties'])) |
765 | 765 | { |
766 | - $this->_properties = array_merge($this->_properties, $config['pages']['properties']); |
|
766 | + $this->_properties=array_merge($this->_properties, $config['pages']['properties']); |
|
767 | 767 | unset($config['pages']['properties']); |
768 | 768 | } |
769 | 769 | foreach($config['pages'] as $id => $page) |
770 | 770 | { |
771 | - $properties = array(); |
|
771 | + $properties=array(); |
|
772 | 772 | if(isset($page['properties'])) |
773 | 773 | { |
774 | 774 | $properties=$page['properties']; |
775 | 775 | unset($page['properties']); |
776 | 776 | } |
777 | 777 | $matching=false; |
778 | - $id=($configPagePath==='')?$id:$configPagePath.'.'.$id; |
|
779 | - if(strcasecmp($id,$this->_pagePath)===0) |
|
778 | + $id=($configPagePath==='') ? $id : $configPagePath.'.'.$id; |
|
779 | + if(strcasecmp($id, $this->_pagePath)===0) |
|
780 | 780 | $matching=true; |
781 | - else if($id[strlen($id)-1]==='*') // try wildcard matching |
|
782 | - $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
|
781 | + else if($id[strlen($id) - 1]==='*') // try wildcard matching |
|
782 | + $matching=strncasecmp($this->_pagePath, $id, strlen($id) - 1)===0; |
|
783 | 783 | if($matching) |
784 | - $this->_properties=array_merge($this->_properties,$properties); |
|
784 | + $this->_properties=array_merge($this->_properties, $properties); |
|
785 | 785 | } |
786 | 786 | } |
787 | 787 | |
@@ -790,14 +790,14 @@ discard block |
||
790 | 790 | { |
791 | 791 | foreach($config['includes'] as $include) |
792 | 792 | { |
793 | - $when = isset($include['when'])?true:false; |
|
793 | + $when=isset($include['when']) ? true : false; |
|
794 | 794 | if(!isset($include['file'])) |
795 | 795 | throw new TConfigurationException('pageserviceconf_includefile_required'); |
796 | - $filePath = $include['file']; |
|
796 | + $filePath=$include['file']; |
|
797 | 797 | if(isset($this->_includes[$filePath])) |
798 | - $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
798 | + $this->_includes[$filePath]=array($configPagePath, '('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
799 | 799 | else |
800 | - $this->_includes[$filePath]=array($configPagePath,$when); |
|
800 | + $this->_includes[$filePath]=array($configPagePath, $when); |
|
801 | 801 | } |
802 | 802 | } |
803 | 803 | } |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | * @param string base path corresponding to this xml element |
809 | 809 | * @param string the page path that the config XML is associated with. The page path doesn't include the page name. |
810 | 810 | */ |
811 | - public function loadPageConfigurationFromXml($dom,$configPath,$configPagePath) |
|
811 | + public function loadPageConfigurationFromXml($dom, $configPath, $configPagePath) |
|
812 | 812 | { |
813 | 813 | // authorization |
814 | 814 | if(($authorizationNode=$dom->getElementByTagName('authorization'))!==null) |
@@ -822,21 +822,21 @@ discard block |
||
822 | 822 | $ruleApplies=true; |
823 | 823 | else |
824 | 824 | { |
825 | - foreach(explode(',',$patterns) as $pattern) |
|
825 | + foreach(explode(',', $patterns) as $pattern) |
|
826 | 826 | { |
827 | 827 | if(($pattern=trim($pattern))!=='') |
828 | 828 | { |
829 | 829 | // we know $configPagePath and $this->_pagePath |
830 | 830 | if($configPagePath!=='') // prepend the pattern with ConfigPagePath |
831 | 831 | $pattern=$configPagePath.'.'.$pattern; |
832 | - if(strcasecmp($pattern,$this->_pagePath)===0) |
|
832 | + if(strcasecmp($pattern, $this->_pagePath)===0) |
|
833 | 833 | { |
834 | 834 | $ruleApplies=true; |
835 | 835 | break; |
836 | 836 | } |
837 | - if($pattern[strlen($pattern)-1]==='*') // try wildcard matching |
|
837 | + if($pattern[strlen($pattern) - 1]==='*') // try wildcard matching |
|
838 | 838 | { |
839 | - if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0) |
|
839 | + if(strncasecmp($this->_pagePath, $pattern, strlen($pattern) - 1)===0) |
|
840 | 840 | { |
841 | 841 | $ruleApplies=true; |
842 | 842 | break; |
@@ -846,30 +846,30 @@ discard block |
||
846 | 846 | } |
847 | 847 | } |
848 | 848 | if($ruleApplies) |
849 | - $rules[]=new TAuthorizationRule($node->getTagName(),$node->getAttribute('users'),$node->getAttribute('roles'),$node->getAttribute('verb'),$node->getAttribute('ips')); |
|
849 | + $rules[]=new TAuthorizationRule($node->getTagName(), $node->getAttribute('users'), $node->getAttribute('roles'), $node->getAttribute('verb'), $node->getAttribute('ips')); |
|
850 | 850 | } |
851 | - $this->_rules=array_merge($rules,$this->_rules); |
|
851 | + $this->_rules=array_merge($rules, $this->_rules); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | // pages |
855 | 855 | if(($pagesNode=$dom->getElementByTagName('pages'))!==null) |
856 | 856 | { |
857 | - $this->_properties=array_merge($this->_properties,$pagesNode->getAttributes()->toArray()); |
|
857 | + $this->_properties=array_merge($this->_properties, $pagesNode->getAttributes()->toArray()); |
|
858 | 858 | // at the page folder |
859 | 859 | foreach($pagesNode->getElementsByTagName('page') as $node) |
860 | 860 | { |
861 | 861 | $properties=$node->getAttributes(); |
862 | 862 | $id=$properties->remove('id'); |
863 | 863 | if(empty($id)) |
864 | - throw new TConfigurationException('pageserviceconf_page_invalid',$configPath); |
|
864 | + throw new TConfigurationException('pageserviceconf_page_invalid', $configPath); |
|
865 | 865 | $matching=false; |
866 | - $id=($configPagePath==='')?$id:$configPagePath.'.'.$id; |
|
867 | - if(strcasecmp($id,$this->_pagePath)===0) |
|
866 | + $id=($configPagePath==='') ? $id : $configPagePath.'.'.$id; |
|
867 | + if(strcasecmp($id, $this->_pagePath)===0) |
|
868 | 868 | $matching=true; |
869 | - else if($id[strlen($id)-1]==='*') // try wildcard matching |
|
870 | - $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
|
869 | + else if($id[strlen($id) - 1]==='*') // try wildcard matching |
|
870 | + $matching=strncasecmp($this->_pagePath, $id, strlen($id) - 1)===0; |
|
871 | 871 | if($matching) |
872 | - $this->_properties=array_merge($this->_properties,$properties->toArray()); |
|
872 | + $this->_properties=array_merge($this->_properties, $properties->toArray()); |
|
873 | 873 | } |
874 | 874 | } |
875 | 875 | |
@@ -881,9 +881,9 @@ discard block |
||
881 | 881 | if(($filePath=$node->getAttribute('file'))===null) |
882 | 882 | throw new TConfigurationException('pageserviceconf_includefile_required'); |
883 | 883 | if(isset($this->_includes[$filePath])) |
884 | - $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
884 | + $this->_includes[$filePath]=array($configPagePath, '('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
885 | 885 | else |
886 | - $this->_includes[$filePath]=array($configPagePath,$when); |
|
886 | + $this->_includes[$filePath]=array($configPagePath, $when); |
|
887 | 887 | } |
888 | 888 | } |
889 | 889 | } |
@@ -232,8 +232,7 @@ discard block |
||
232 | 232 | $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
233 | 233 | } |
234 | 234 | $pageConfig->loadFromFiles($this->getBasePath()); |
235 | - } |
|
236 | - else |
|
235 | + } else |
|
237 | 236 | { |
238 | 237 | $configCached=true; |
239 | 238 | $currentTimestamp=array(); |
@@ -251,8 +250,7 @@ discard block |
||
251 | 250 | $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); |
252 | 251 | if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0])) |
253 | 252 | $configCached=false; |
254 | - } |
|
255 | - else |
|
253 | + } else |
|
256 | 254 | { |
257 | 255 | $currentTimestamp[$fileName]=@filemtime($fileName); |
258 | 256 | if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName])) |
@@ -260,8 +258,7 @@ discard block |
||
260 | 258 | } |
261 | 259 | } |
262 | 260 | } |
263 | - } |
|
264 | - else |
|
261 | + } else |
|
265 | 262 | { |
266 | 263 | $configCached=false; |
267 | 264 | $paths=explode('.',$pagePath); |
@@ -489,8 +486,7 @@ discard block |
||
489 | 486 | $className=basename($path); |
490 | 487 | if(!class_exists($className,false)) |
491 | 488 | include_once($path.Prado::CLASS_FILE_EXT); |
492 | - } |
|
493 | - else |
|
489 | + } else |
|
494 | 490 | { |
495 | 491 | $className=$this->getBasePageClass(); |
496 | 492 | Prado::using($className); |
@@ -659,8 +655,7 @@ discard block |
||
659 | 655 | { |
660 | 656 | $fcontent = include $fname; |
661 | 657 | $this->loadFromPhp($fcontent,dirname($fname),$configPagePath); |
662 | - } |
|
663 | - else |
|
658 | + } else |
|
664 | 659 | { |
665 | 660 | $dom=new TXmlDocument; |
666 | 661 | if($dom->loadFromFile($fname)) |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TPageService class file. |
|
4 | - * |
|
5 | - * @author Qiang Xue <[email protected]> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2016 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Web.Services |
|
10 | - */ |
|
3 | + * TPageService class file. |
|
4 | + * |
|
5 | + * @author Qiang Xue <[email protected]> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2016 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Web.Services |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Include classes to be used by page service |