@@ -18,8 +18,8 @@ |
||
| 18 | 18 | if(!defined('PRADO_DIR')) |
| 19 | 19 | define('PRADO_DIR',dirname(__FILE__)); |
| 20 | 20 | /** |
| 21 | - * Defines the default permission for writable directories and files |
|
| 22 | - */ |
|
| 21 | + * Defines the default permission for writable directories and files |
|
| 22 | + */ |
|
| 23 | 23 | if(!defined('PRADO_CHMOD')) |
| 24 | 24 | define('PRADO_CHMOD',0777); |
| 25 | 25 | |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | * Defines the PRADO framework installation path. |
| 17 | 17 | */ |
| 18 | 18 | if(!defined('PRADO_DIR')) |
| 19 | - define('PRADO_DIR',dirname(__FILE__)); |
|
| 19 | + define('PRADO_DIR', dirname(__FILE__)); |
|
| 20 | 20 | /** |
| 21 | 21 | * Defines the default permission for writable directories and files |
| 22 | 22 | */ |
| 23 | 23 | if(!defined('PRADO_CHMOD')) |
| 24 | - define('PRADO_CHMOD',0777); |
|
| 24 | + define('PRADO_CHMOD', 0777); |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * PradoBase class. |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | /** |
| 63 | 63 | * @var array list of class exists checks |
| 64 | 64 | */ |
| 65 | - protected static $classExists = array(); |
|
| 65 | + protected static $classExists=array(); |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @return string the version of Prado framework |
@@ -82,15 +82,15 @@ discard block |
||
| 82 | 82 | /** |
| 83 | 83 | * Sets error handler to be Prado::phpErrorHandler |
| 84 | 84 | */ |
| 85 | - set_error_handler(array('PradoBase','phpErrorHandler')); |
|
| 85 | + set_error_handler(array('PradoBase', 'phpErrorHandler')); |
|
| 86 | 86 | /** |
| 87 | 87 | * Sets shutdown function to be Prado::phpFatalErrorHandler |
| 88 | 88 | */ |
| 89 | - register_shutdown_function(array('PradoBase','phpFatalErrorHandler')); |
|
| 89 | + register_shutdown_function(array('PradoBase', 'phpFatalErrorHandler')); |
|
| 90 | 90 | /** |
| 91 | 91 | * Sets exception handler to be Prado::exceptionHandler |
| 92 | 92 | */ |
| 93 | - set_exception_handler(array('PradoBase','exceptionHandler')); |
|
| 93 | + set_exception_handler(array('PradoBase', 'exceptionHandler')); |
|
| 94 | 94 | /** |
| 95 | 95 | * Disable php's builtin error reporting to avoid duplicated reports |
| 96 | 96 | */ |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public static function poweredByPrado($logoType=0) |
| 115 | 115 | { |
| 116 | - $logoName=$logoType==1?'powered2':'powered'; |
|
| 116 | + $logoName=$logoType==1 ? 'powered2' : 'powered'; |
|
| 117 | 117 | if(self::$_application!==null) |
| 118 | 118 | { |
| 119 | 119 | $am=self::$_application->getAssetManager(); |
| 120 | - $url=$am->publishFilePath(self::getPathOfNamespace('System.'.$logoName,'.gif')); |
|
| 120 | + $url=$am->publishFilePath(self::getPathOfNamespace('System.'.$logoName, '.gif')); |
|
| 121 | 121 | } |
| 122 | 122 | else |
| 123 | 123 | $url='http://pradosoft.github.io/docs/'.$logoName.'.gif'; |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | * @param string the filename that the error was raised in |
| 135 | 135 | * @param integer the line number the error was raised at |
| 136 | 136 | */ |
| 137 | - public static function phpErrorHandler($errno,$errstr,$errfile,$errline) |
|
| 137 | + public static function phpErrorHandler($errno, $errstr, $errfile, $errline) |
|
| 138 | 138 | { |
| 139 | 139 | if(error_reporting() & $errno) |
| 140 | - throw new TPhpErrorException($errno,$errstr,$errfile,$errline); |
|
| 140 | + throw new TPhpErrorException($errno, $errstr, $errfile, $errline); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -148,12 +148,12 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public static function phpFatalErrorHandler() |
| 150 | 150 | { |
| 151 | - $error = error_get_last(); |
|
| 151 | + $error=error_get_last(); |
|
| 152 | 152 | if($error && |
| 153 | 153 | TPhpErrorException::isFatalError($error) && |
| 154 | 154 | error_reporting() & $error['type']) |
| 155 | 155 | { |
| 156 | - self::exceptionHandler(new TPhpErrorException($error['type'],$error['message'],$error['file'],$error['line'])); |
|
| 156 | + self::exceptionHandler(new TPhpErrorException($error['type'], $error['message'], $error['file'], $error['line'])); |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | { |
| 171 | 171 | if(self::$_application!==null && ($errorHandler=self::$_application->getErrorHandler())!==null) |
| 172 | 172 | { |
| 173 | - $errorHandler->handleError(null,$exception); |
|
| 173 | + $errorHandler->handleError(null, $exception); |
|
| 174 | 174 | } |
| 175 | 175 | else |
| 176 | 176 | { |
@@ -227,19 +227,19 @@ discard block |
||
| 227 | 227 | public static function createComponent($type) |
| 228 | 228 | { |
| 229 | 229 | if(!isset(self::$classExists[$type])) |
| 230 | - self::$classExists[$type] = class_exists($type, false); |
|
| 230 | + self::$classExists[$type]=class_exists($type, false); |
|
| 231 | 231 | |
| 232 | - if( !isset(self::$_usings[$type]) && !self::$classExists[$type]) { |
|
| 232 | + if(!isset(self::$_usings[$type]) && !self::$classExists[$type]) { |
|
| 233 | 233 | self::using($type); |
| 234 | - self::$classExists[$type] = class_exists($type, false); |
|
| 234 | + self::$classExists[$type]=class_exists($type, false); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if( ($pos = strrpos($type, '.')) !== false) |
|
| 238 | - $type = substr($type,$pos+1); |
|
| 237 | + if(($pos=strrpos($type, '.'))!==false) |
|
| 238 | + $type=substr($type, $pos + 1); |
|
| 239 | 239 | |
| 240 | - if(($n=func_num_args())>1) |
|
| 240 | + if(($n=func_num_args()) > 1) |
|
| 241 | 241 | { |
| 242 | - $args = func_get_args(); |
|
| 242 | + $args=func_get_args(); |
|
| 243 | 243 | switch($n) { |
| 244 | 244 | case 2: |
| 245 | 245 | return new $type($args[1]); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | break; |
| 256 | 256 | default: |
| 257 | 257 | $s='$args[1]'; |
| 258 | - for($i=2;$i<$n;++$i) |
|
| 258 | + for($i=2; $i < $n; ++$i) |
|
| 259 | 259 | $s.=",\$args[$i]"; |
| 260 | 260 | eval("\$component=new $type($s);"); |
| 261 | 261 | return $component; |
@@ -275,11 +275,11 @@ discard block |
||
| 275 | 275 | * @param boolean whether to check the existence of the class after the class file is included |
| 276 | 276 | * @throws TInvalidDataValueException if the namespace is invalid |
| 277 | 277 | */ |
| 278 | - public static function using($namespace,$checkClassExistence=true) |
|
| 278 | + public static function using($namespace, $checkClassExistence=true) |
|
| 279 | 279 | { |
| 280 | - if(isset(self::$_usings[$namespace]) || class_exists($namespace,false)) |
|
| 280 | + if(isset(self::$_usings[$namespace]) || class_exists($namespace, false)) |
|
| 281 | 281 | return; |
| 282 | - if(($pos=strrpos($namespace,'.'))===false) // a class name |
|
| 282 | + if(($pos=strrpos($namespace, '.'))===false) // a class name |
|
| 283 | 283 | { |
| 284 | 284 | try |
| 285 | 285 | { |
@@ -287,15 +287,15 @@ discard block |
||
| 287 | 287 | } |
| 288 | 288 | catch(Exception $e) |
| 289 | 289 | { |
| 290 | - if($checkClassExistence && !class_exists($namespace,false)) |
|
| 291 | - throw new TInvalidOperationException('prado_component_unknown',$namespace,$e->getMessage()); |
|
| 290 | + if($checkClassExistence && !class_exists($namespace, false)) |
|
| 291 | + throw new TInvalidOperationException('prado_component_unknown', $namespace, $e->getMessage()); |
|
| 292 | 292 | else |
| 293 | 293 | throw $e; |
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | - else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null) |
|
| 296 | + else if(($path=self::getPathOfNamespace($namespace, self::CLASS_FILE_EXT))!==null) |
|
| 297 | 297 | { |
| 298 | - $className=substr($namespace,$pos+1); |
|
| 298 | + $className=substr($namespace, $pos + 1); |
|
| 299 | 299 | if($className==='*') // a directory |
| 300 | 300 | { |
| 301 | 301 | self::$_usings[$namespace]=$path; |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | else // a file |
| 305 | 305 | { |
| 306 | 306 | self::$_usings[$namespace]=$path; |
| 307 | - if(!$checkClassExistence || !class_exists($className,false)) |
|
| 307 | + if(!$checkClassExistence || !class_exists($className, false)) |
|
| 308 | 308 | { |
| 309 | 309 | try |
| 310 | 310 | { |
@@ -312,8 +312,8 @@ discard block |
||
| 312 | 312 | } |
| 313 | 313 | catch(Exception $e) |
| 314 | 314 | { |
| 315 | - if($checkClassExistence && !class_exists($className,false)) |
|
| 316 | - throw new TInvalidOperationException('prado_component_unknown',$className,$e->getMessage()); |
|
| 315 | + if($checkClassExistence && !class_exists($className, false)) |
|
| 316 | + throw new TInvalidOperationException('prado_component_unknown', $className, $e->getMessage()); |
|
| 317 | 317 | else |
| 318 | 318 | throw $e; |
| 319 | 319 | } |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | } |
| 322 | 322 | } |
| 323 | 323 | else |
| 324 | - throw new TInvalidDataValueException('prado_using_invalid',$namespace); |
|
| 324 | + throw new TInvalidDataValueException('prado_using_invalid', $namespace); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | */ |
| 339 | 339 | public static function getPathOfNamespace($namespace, $ext='') |
| 340 | 340 | { |
| 341 | - if(self::CLASS_FILE_EXT === $ext || empty($ext)) |
|
| 341 | + if(self::CLASS_FILE_EXT===$ext || empty($ext)) |
|
| 342 | 342 | { |
| 343 | 343 | if(isset(self::$_usings[$namespace])) |
| 344 | 344 | return self::$_usings[$namespace]; |
@@ -347,11 +347,11 @@ discard block |
||
| 347 | 347 | return self::$_aliases[$namespace]; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - $segs = explode('.',$namespace); |
|
| 351 | - $alias = array_shift($segs); |
|
| 350 | + $segs=explode('.', $namespace); |
|
| 351 | + $alias=array_shift($segs); |
|
| 352 | 352 | |
| 353 | - if(null !== ($file = array_pop($segs)) && null !== ($root = self::getPathOfAlias($alias))) |
|
| 354 | - return rtrim($root.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR ,$segs),'/\\').(($file === '*') ? '' : DIRECTORY_SEPARATOR.$file.$ext); |
|
| 353 | + if(null!==($file=array_pop($segs)) && null!==($root=self::getPathOfAlias($alias))) |
|
| 354 | + return rtrim($root.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $segs), '/\\').(($file==='*') ? '' : DIRECTORY_SEPARATOR.$file.$ext); |
|
| 355 | 355 | |
| 356 | 356 | return null; |
| 357 | 357 | } |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | public static function getPathOfAlias($alias) |
| 364 | 364 | { |
| 365 | - return isset(self::$_aliases[$alias])?self::$_aliases[$alias]:null; |
|
| 365 | + return isset(self::$_aliases[$alias]) ? self::$_aliases[$alias] : null; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | protected static function getPathAliases() |
@@ -376,19 +376,19 @@ discard block |
||
| 376 | 376 | * @throws TInvalidOperationException if the alias is already defined |
| 377 | 377 | * @throws TInvalidDataValueException if the path is not a valid file path |
| 378 | 378 | */ |
| 379 | - public static function setPathOfAlias($alias,$path) |
|
| 379 | + public static function setPathOfAlias($alias, $path) |
|
| 380 | 380 | { |
| 381 | 381 | if(isset(self::$_aliases[$alias]) && !defined('PRADO_TEST_RUN')) |
| 382 | - throw new TInvalidOperationException('prado_alias_redefined',$alias); |
|
| 382 | + throw new TInvalidOperationException('prado_alias_redefined', $alias); |
|
| 383 | 383 | else if(($rp=realpath($path))!==false && is_dir($rp)) |
| 384 | 384 | { |
| 385 | - if(strpos($alias,'.')===false) |
|
| 385 | + if(strpos($alias, '.')===false) |
|
| 386 | 386 | self::$_aliases[$alias]=$rp; |
| 387 | 387 | else |
| 388 | - throw new TInvalidDataValueException('prado_aliasname_invalid',$alias); |
|
| 388 | + throw new TInvalidDataValueException('prado_aliasname_invalid', $alias); |
|
| 389 | 389 | } |
| 390 | 390 | else |
| 391 | - throw new TInvalidDataValueException('prado_alias_invalid',$alias,$path); |
|
| 391 | + throw new TInvalidDataValueException('prado_alias_invalid', $alias, $path); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -413,13 +413,13 @@ discard block |
||
| 413 | 413 | continue; |
| 414 | 414 | echo '#'.$index.' '; |
| 415 | 415 | if(isset($t['file'])) |
| 416 | - echo basename($t['file']) . ':' . $t['line']; |
|
| 416 | + echo basename($t['file']).':'.$t['line']; |
|
| 417 | 417 | else |
| 418 | 418 | echo '<PHP inner-code>'; |
| 419 | 419 | echo ' -- '; |
| 420 | 420 | if(isset($t['class'])) |
| 421 | - echo $t['class'] . $t['type']; |
|
| 422 | - echo $t['function'] . '('; |
|
| 421 | + echo $t['class'].$t['type']; |
|
| 422 | + echo $t['function'].'('; |
|
| 423 | 423 | if(isset($t['args']) && sizeof($t['args']) > 0) |
| 424 | 424 | { |
| 425 | 425 | $count=0; |
@@ -428,25 +428,25 @@ discard block |
||
| 428 | 428 | if(is_string($item)) |
| 429 | 429 | { |
| 430 | 430 | $str=htmlentities(str_replace("\r\n", "", $item), ENT_QUOTES); |
| 431 | - if (strlen($item) > 70) |
|
| 432 | - echo "'". substr($str, 0, 70) . "...'"; |
|
| 431 | + if(strlen($item) > 70) |
|
| 432 | + echo "'".substr($str, 0, 70)."...'"; |
|
| 433 | 433 | else |
| 434 | - echo "'" . $str . "'"; |
|
| 434 | + echo "'".$str."'"; |
|
| 435 | 435 | } |
| 436 | - else if (is_int($item) || is_float($item)) |
|
| 436 | + else if(is_int($item) || is_float($item)) |
|
| 437 | 437 | echo $item; |
| 438 | - else if (is_object($item)) |
|
| 438 | + else if(is_object($item)) |
|
| 439 | 439 | echo get_class($item); |
| 440 | - else if (is_array($item)) |
|
| 441 | - echo 'array(' . count($item) . ')'; |
|
| 442 | - else if (is_bool($item)) |
|
| 440 | + else if(is_array($item)) |
|
| 441 | + echo 'array('.count($item).')'; |
|
| 442 | + else if(is_bool($item)) |
|
| 443 | 443 | echo $item ? 'true' : 'false'; |
| 444 | - else if ($item === null) |
|
| 444 | + else if($item===null) |
|
| 445 | 445 | echo 'NULL'; |
| 446 | - else if (is_resource($item)) |
|
| 446 | + else if(is_resource($item)) |
|
| 447 | 447 | echo get_resource_type($item); |
| 448 | 448 | $count++; |
| 449 | - if (count($t['args']) > $count) |
|
| 449 | + if(count($t['args']) > $count) |
|
| 450 | 450 | echo ', '; |
| 451 | 451 | } |
| 452 | 452 | } |
@@ -473,10 +473,10 @@ discard block |
||
| 473 | 473 | else |
| 474 | 474 | { |
| 475 | 475 | $languages=array(); |
| 476 | - foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language) |
|
| 476 | + foreach(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language) |
|
| 477 | 477 | { |
| 478 | - $array=explode(';q=',trim($language)); |
|
| 479 | - $languages[trim($array[0])]=isset($array[1])?(float)$array[1]:1.0; |
|
| 478 | + $array=explode(';q=', trim($language)); |
|
| 479 | + $languages[trim($array[0])]=isset($array[1]) ? (float) $array[1] : 1.0; |
|
| 480 | 480 | } |
| 481 | 481 | arsort($languages); |
| 482 | 482 | $languages=array_keys($languages); |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | if($language===null) |
| 498 | 498 | { |
| 499 | 499 | $langs=Prado::getUserLanguages(); |
| 500 | - $lang=explode('-',$langs[0]); |
|
| 500 | + $lang=explode('-', $langs[0]); |
|
| 501 | 501 | if(empty($lang[0]) || !ctype_alpha($lang[0])) |
| 502 | 502 | $language='en'; |
| 503 | 503 | else |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | * @param (string|TControl) control of the message |
| 519 | 519 | * @see log, getLogger |
| 520 | 520 | */ |
| 521 | - public static function trace($msg,$category='Uncategorized',$ctl=null) |
|
| 521 | + public static function trace($msg, $category='Uncategorized', $ctl=null) |
|
| 522 | 522 | { |
| 523 | 523 | if(self::$_application && self::$_application->getMode()===TApplicationMode::Performance) |
| 524 | 524 | return; |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | } |
| 532 | 532 | else |
| 533 | 533 | $level=TLogger::INFO; |
| 534 | - self::log($msg,$level,$category,$ctl); |
|
| 534 | + self::log($msg, $level, $category, $ctl); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | /** |
@@ -546,11 +546,11 @@ discard block |
||
| 546 | 546 | * @param string category of the message |
| 547 | 547 | * @param (string|TControl) control of the message |
| 548 | 548 | */ |
| 549 | - public static function log($msg,$level=TLogger::INFO,$category='Uncategorized',$ctl=null) |
|
| 549 | + public static function log($msg, $level=TLogger::INFO, $category='Uncategorized', $ctl=null) |
|
| 550 | 550 | { |
| 551 | 551 | if(self::$_logger===null) |
| 552 | 552 | self::$_logger=new TLogger; |
| 553 | - self::$_logger->log($msg,$level,$category,$ctl); |
|
| 553 | + self::$_logger->log($msg, $level, $category, $ctl); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -572,10 +572,10 @@ discard block |
||
| 572 | 572 | * @param boolean whether to syntax highlight the output. Defaults to false. |
| 573 | 573 | * @return string the string representation of the variable |
| 574 | 574 | */ |
| 575 | - public static function varDump($var,$depth=10,$highlight=false) |
|
| 575 | + public static function varDump($var, $depth=10, $highlight=false) |
|
| 576 | 576 | { |
| 577 | 577 | Prado::using('System.Util.TVarDumper'); |
| 578 | - return TVarDumper::dump($var,$depth,$highlight); |
|
| 578 | + return TVarDumper::dump($var, $depth, $highlight); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /** |
@@ -591,32 +591,32 @@ discard block |
||
| 591 | 591 | public static function localize($text, $parameters=array(), $catalogue=null, $charset=null) |
| 592 | 592 | { |
| 593 | 593 | Prado::using('System.I18N.Translation'); |
| 594 | - $app = Prado::getApplication()->getGlobalization(false); |
|
| 594 | + $app=Prado::getApplication()->getGlobalization(false); |
|
| 595 | 595 | |
| 596 | - $params = array(); |
|
| 596 | + $params=array(); |
|
| 597 | 597 | foreach($parameters as $key => $value) |
| 598 | - $params['{'.$key.'}'] = $value; |
|
| 598 | + $params['{'.$key.'}']=$value; |
|
| 599 | 599 | |
| 600 | 600 | //no translation handler provided |
| 601 | - if($app===null || ($config = $app->getTranslationConfiguration())===null) |
|
| 601 | + if($app===null || ($config=$app->getTranslationConfiguration())===null) |
|
| 602 | 602 | return strtr($text, $params); |
| 603 | 603 | |
| 604 | - if ($catalogue===null) |
|
| 605 | - $catalogue=isset($config['catalogue'])?$config['catalogue']:'messages'; |
|
| 604 | + if($catalogue===null) |
|
| 605 | + $catalogue=isset($config['catalogue']) ? $config['catalogue'] : 'messages'; |
|
| 606 | 606 | |
| 607 | 607 | Translation::init($catalogue); |
| 608 | 608 | |
| 609 | 609 | //globalization charset |
| 610 | - $appCharset = $app===null ? '' : $app->getCharset(); |
|
| 610 | + $appCharset=$app===null ? '' : $app->getCharset(); |
|
| 611 | 611 | |
| 612 | 612 | //default charset |
| 613 | - $defaultCharset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset(); |
|
| 613 | + $defaultCharset=($app===null) ? 'UTF-8' : $app->getDefaultCharset(); |
|
| 614 | 614 | |
| 615 | 615 | //fall back |
| 616 | - if(empty($charset)) $charset = $appCharset; |
|
| 617 | - if(empty($charset)) $charset = $defaultCharset; |
|
| 616 | + if(empty($charset)) $charset=$appCharset; |
|
| 617 | + if(empty($charset)) $charset=$defaultCharset; |
|
| 618 | 618 | |
| 619 | - return Translation::formatter($catalogue)->format($text,$params,$catalogue,$charset); |
|
| 619 | + return Translation::formatter($catalogue)->format($text, $params, $catalogue, $charset); |
|
| 620 | 620 | } |
| 621 | 621 | } |
| 622 | 622 | |