@@ -41,7 +41,9 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | protected function updateJuiOptions($options) |
| 43 | 43 | { |
| 44 | - foreach ($options as $key => $value) $options[$key] = $key . ': ' . (is_string($value) ? "'{$value}'" : TPropertyValue::ensureString($value)); |
|
| 44 | + foreach ($options as $key => $value) { |
|
| 45 | + $options[$key] = $key . ': ' . (is_string($value) ? "'{$value}'" : TPropertyValue::ensureString($value)); |
|
| 46 | + } |
|
| 45 | 47 | $code = "jQuery('#{$this->_control->getWidgetID()}').{$this->_control->getWidget()}('option', { " . implode(', ', $options) . " });"; |
| 46 | 48 | $this->_control->getPage()->getClientScript()->registerEndScript(sprintf('%08X', crc32($code)), $code); |
| 47 | 49 | } |
@@ -36,14 +36,16 @@ |
||
| 36 | 36 | |
| 37 | 37 | public function write($s) |
| 38 | 38 | { |
| 39 | - foreach($this->_writers as $writer) |
|
| 40 | - $writer->write($s); |
|
| 39 | + foreach($this->_writers as $writer) { |
|
| 40 | + $writer->write($s); |
|
| 41 | + } |
|
| 41 | 42 | } |
| 42 | 43 | |
| 43 | 44 | public function flush() |
| 44 | 45 | { |
| 45 | - foreach($this->_writers as $writer) |
|
| 46 | - $s = $writer->flush(); |
|
| 46 | + foreach($this->_writers as $writer) { |
|
| 47 | + $s = $writer->flush(); |
|
| 48 | + } |
|
| 47 | 49 | return $s; |
| 48 | 50 | } |
| 49 | 51 | } |
| 50 | 52 | \ No newline at end of file |
@@ -44,8 +44,9 @@ discard block |
||
| 44 | 44 | public function attach($owner) |
| 45 | 45 | { |
| 46 | 46 | $this->_owner = $owner; |
| 47 | - foreach($this->events() as $event => $handler) |
|
| 48 | - $owner->attachEventHandler($event, [$this,$handler]); |
|
| 47 | + foreach($this->events() as $event => $handler) { |
|
| 48 | + $owner->attachEventHandler($event, [$this,$handler]); |
|
| 49 | + } |
|
| 49 | 50 | } |
| 50 | 51 | |
| 51 | 52 | /** |
@@ -57,8 +58,9 @@ discard block |
||
| 57 | 58 | */ |
| 58 | 59 | public function detach($owner) |
| 59 | 60 | { |
| 60 | - foreach($this->events() as $event => $handler) |
|
| 61 | - $owner->detachEventHandler($event, [$this,$handler]); |
|
| 61 | + foreach($this->events() as $event => $handler) { |
|
| 62 | + $owner->detachEventHandler($event, [$this,$handler]); |
|
| 63 | + } |
|
| 62 | 64 | $this->_owner = null; |
| 63 | 65 | } |
| 64 | 66 | |
@@ -111,8 +111,9 @@ |
||
| 111 | 111 | $fkeys = $this->findForeignKeys($fkObjects[0], $source); |
| 112 | 112 | for($i = 0;$i < $total;$i++) |
| 113 | 113 | { |
| 114 | - foreach($fkeys as $fKey => $srcKey) |
|
| 115 | - $fkObjects[$i]->setColumnValue($fKey, $source->getColumnValue($srcKey)); |
|
| 114 | + foreach($fkeys as $fKey => $srcKey) { |
|
| 115 | + $fkObjects[$i]->setColumnValue($fKey, $source->getColumnValue($srcKey)); |
|
| 116 | + } |
|
| 116 | 117 | $success = $fkObjects[$i]->save() && $success; |
| 117 | 118 | } |
| 118 | 119 | } |
@@ -9,8 +9,9 @@ discard block |
||
| 9 | 9 | * @license https://github.com/pradosoft/prado/blob/master/LICENSE |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -if(!isset($_SERVER['argv']) || php_sapi_name() !== 'cli') |
|
| 12 | +if(!isset($_SERVER['argv']) || php_sapi_name() !== 'cli') { |
|
| 13 | 13 | die('Must be run from the command line'); |
| 14 | +} |
|
| 14 | 15 | |
| 15 | 16 | // Locate composer's autoloader |
| 16 | 17 | if(file_exists($autoloader = realpath(__DIR__ . '/../vendor/autoload.php'))) |
@@ -78,8 +79,9 @@ discard block |
||
| 78 | 79 | public static function getInstance() |
| 79 | 80 | { |
| 80 | 81 | static $instance; |
| 81 | - if($instance === null) |
|
| 82 | - $instance = new self; |
|
| 82 | + if($instance === null) { |
|
| 83 | + $instance = new self; |
|
| 84 | + } |
|
| 83 | 85 | return $instance; |
| 84 | 86 | } |
| 85 | 87 | |
@@ -94,8 +96,9 @@ discard block |
||
| 94 | 96 | */ |
| 95 | 97 | public function run($args) |
| 96 | 98 | { |
| 97 | - if(count($args) > 1) |
|
| 98 | - array_shift($args); |
|
| 99 | + if(count($args) > 1) { |
|
| 100 | + array_shift($args); |
|
| 101 | + } |
|
| 99 | 102 | $valid = false; |
| 100 | 103 | foreach($this->_actions as $class => $action) |
| 101 | 104 | { |
@@ -103,14 +106,14 @@ discard block |
||
| 103 | 106 | { |
| 104 | 107 | $valid |= $action->performAction($args); |
| 105 | 108 | break; |
| 106 | - } |
|
| 107 | - else |
|
| 109 | + } else |
|
| 108 | 110 | { |
| 109 | 111 | $valid = false; |
| 110 | 112 | } |
| 111 | 113 | } |
| 112 | - if(!$valid) |
|
| 113 | - $this->printHelp(); |
|
| 114 | + if(!$valid) { |
|
| 115 | + $this->printHelp(); |
|
| 116 | + } |
|
| 114 | 117 | } |
| 115 | 118 | |
| 116 | 119 | /** |
@@ -123,8 +126,9 @@ discard block |
||
| 123 | 126 | echo "usage: php prado-cli.php action <parameter> [optional]\n"; |
| 124 | 127 | echo "example: php prado-cli.php -c mysite\n\n"; |
| 125 | 128 | echo "actions:\n"; |
| 126 | - foreach($this->_actions as $action) |
|
| 127 | - echo $action->renderHelp(); |
|
| 129 | + foreach($this->_actions as $action) { |
|
| 130 | + echo $action->renderHelp(); |
|
| 131 | + } |
|
| 128 | 132 | } |
| 129 | 133 | } |
| 130 | 134 | |
@@ -150,8 +154,9 @@ discard block |
||
| 150 | 154 | mkdir($dir); |
| 151 | 155 | echo "creating $dir\n"; |
| 152 | 156 | } |
| 153 | - if(is_dir($dir)) |
|
| 154 | - chmod($dir, $mask); |
|
| 157 | + if(is_dir($dir)) { |
|
| 158 | + chmod($dir, $mask); |
|
| 159 | + } |
|
| 155 | 160 | } |
| 156 | 161 | |
| 157 | 162 | protected function createFile($filename, $content) |
@@ -172,16 +177,19 @@ discard block |
||
| 172 | 177 | public function renderHelp() |
| 173 | 178 | { |
| 174 | 179 | $params = []; |
| 175 | - foreach($this->parameters as $v) |
|
| 176 | - $params[] = '<' . $v . '>'; |
|
| 180 | + foreach($this->parameters as $v) { |
|
| 181 | + $params[] = '<' . $v . '>'; |
|
| 182 | + } |
|
| 177 | 183 | $parameters = implode($params, ' '); |
| 178 | 184 | $options = []; |
| 179 | - foreach($this->optional as $v) |
|
| 180 | - $options[] = '[' . $v . ']'; |
|
| 185 | + foreach($this->optional as $v) { |
|
| 186 | + $options[] = '[' . $v . ']'; |
|
| 187 | + } |
|
| 181 | 188 | $optional = (strlen($parameters) ? ' ' : '') . implode($options, ' '); |
| 182 | 189 | $description = ''; |
| 183 | - foreach(explode("\n", wordwrap($this->description, 65)) as $line) |
|
| 184 | - $description .= ' ' . $line . "\n"; |
|
| 190 | + foreach(explode("\n", wordwrap($this->description, 65)) as $line) { |
|
| 191 | + $description .= ' ' . $line . "\n"; |
|
| 192 | + } |
|
| 185 | 193 | return <<<EOD |
| 186 | 194 | {$this->action} {$parameters}{$optional} |
| 187 | 195 | {$description} |
@@ -205,8 +213,7 @@ discard block |
||
| 205 | 213 | } |
| 206 | 214 | |
| 207 | 215 | return Prado::getApplication(); |
| 208 | - } |
|
| 209 | - else |
|
| 216 | + } else |
|
| 210 | 217 | { |
| 211 | 218 | PradoCommandLineInterpreter::printGreeting(); |
| 212 | 219 | echo '+' . str_repeat('-', 77) . "+\n"; |
@@ -243,15 +250,17 @@ discard block |
||
| 243 | 250 | */ |
| 244 | 251 | protected function createNewPradoProject($dir) |
| 245 | 252 | { |
| 246 | - if(strlen(trim($dir)) == 0) |
|
| 247 | - return; |
|
| 253 | + if(strlen(trim($dir)) == 0) { |
|
| 254 | + return; |
|
| 255 | + } |
|
| 248 | 256 | |
| 249 | 257 | $rootPath = realpath(dirname(trim($dir))); |
| 250 | 258 | |
| 251 | - if(basename($dir) !== '.') |
|
| 252 | - $basePath = $rootPath . DIRECTORY_SEPARATOR . basename($dir); |
|
| 253 | - else |
|
| 254 | - $basePath = $rootPath; |
|
| 259 | + if(basename($dir) !== '.') { |
|
| 260 | + $basePath = $rootPath . DIRECTORY_SEPARATOR . basename($dir); |
|
| 261 | + } else { |
|
| 262 | + $basePath = $rootPath; |
|
| 263 | + } |
|
| 255 | 264 | $appName = basename($basePath); |
| 256 | 265 | $assetPath = $basePath . DIRECTORY_SEPARATOR . 'assets'; |
| 257 | 266 | $protectedPath = $basePath . DIRECTORY_SEPARATOR . 'protected'; |
@@ -390,8 +399,9 @@ discard block |
||
| 390 | 399 | |
| 391 | 400 | protected function createTestFixtures($dir) |
| 392 | 401 | { |
| 393 | - if(strlen(trim($dir)) == 0) |
|
| 394 | - return; |
|
| 402 | + if(strlen(trim($dir)) == 0) { |
|
| 403 | + return; |
|
| 404 | + } |
|
| 395 | 405 | |
| 396 | 406 | $rootPath = realpath(dirname(trim($dir))); |
| 397 | 407 | $basePath = $rootPath . '/' . basename($dir); |
@@ -457,8 +467,9 @@ discard block |
||
| 457 | 467 | |
| 458 | 468 | public function performAction($args) |
| 459 | 469 | { |
| 460 | - if(count($args) > 1) |
|
| 461 | - $this->initializePradoApplication($args[1]); |
|
| 470 | + if(count($args) > 1) { |
|
| 471 | + $this->initializePradoApplication($args[1]); |
|
| 472 | + } |
|
| 462 | 473 | |
| 463 | 474 | \Psy\debug([], Prado::getApplication()); |
| 464 | 475 | return true; |
@@ -487,44 +498,51 @@ discard block |
||
| 487 | 498 | { |
| 488 | 499 | $config = $this->getActiveRecordConfig($app_dir); |
| 489 | 500 | $output = $this->getOutputFile($app_dir, $args[2]); |
| 490 | - if(is_file($output)) |
|
| 491 | - echo "** File $output already exists, skiping. \n"; |
|
| 492 | - elseif($config !== false && $output !== false) |
|
| 493 | - $this->generateActiveRecord($config, $args[1], $output); |
|
| 501 | + if(is_file($output)) { |
|
| 502 | + echo "** File $output already exists, skiping. \n"; |
|
| 503 | + } elseif($config !== false && $output !== false) { |
|
| 504 | + $this->generateActiveRecord($config, $args[1], $output); |
|
| 505 | + } |
|
| 494 | 506 | } |
| 495 | 507 | return true; |
| 496 | 508 | } |
| 497 | 509 | |
| 498 | 510 | protected function getAppDir($dir = ".") |
| 499 | 511 | { |
| 500 | - if(is_dir($dir)) |
|
| 501 | - return realpath($dir); |
|
| 502 | - if(false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir)) |
|
| 503 | - return $app_dir; |
|
| 512 | + if(is_dir($dir)) { |
|
| 513 | + return realpath($dir); |
|
| 514 | + } |
|
| 515 | + if(false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir)) { |
|
| 516 | + return $app_dir; |
|
| 517 | + } |
|
| 504 | 518 | echo '** Unable to find directory "' . $dir . "\".\n"; |
| 505 | 519 | return false; |
| 506 | 520 | } |
| 507 | 521 | |
| 508 | 522 | protected function getXmlFile($app_dir) |
| 509 | 523 | { |
| 510 | - if(false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml)) |
|
| 511 | - return $xml; |
|
| 512 | - if(false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml)) |
|
| 513 | - return $xml; |
|
| 524 | + if(false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml)) { |
|
| 525 | + return $xml; |
|
| 526 | + } |
|
| 527 | + if(false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml)) { |
|
| 528 | + return $xml; |
|
| 529 | + } |
|
| 514 | 530 | echo '** Unable to find application.xml in ' . $app_dir . "\n"; |
| 515 | 531 | return false; |
| 516 | 532 | } |
| 517 | 533 | |
| 518 | 534 | protected function getActiveRecordConfig($app_dir) |
| 519 | 535 | { |
| 520 | - if(false === ($xml = $this->getXmlFile($app_dir))) |
|
| 521 | - return false; |
|
| 536 | + if(false === ($xml = $this->getXmlFile($app_dir))) { |
|
| 537 | + return false; |
|
| 538 | + } |
|
| 522 | 539 | if(false !== ($app = $this->initializePradoApplication($app_dir))) |
| 523 | 540 | { |
| 524 | 541 | Prado::using('System.Data.ActiveRecord.TActiveRecordConfig'); |
| 525 | - foreach($app->getModules() as $module) |
|
| 526 | - if($module instanceof TActiveRecordConfig) |
|
| 542 | + foreach($app->getModules() as $module) { |
|
| 543 | + if($module instanceof TActiveRecordConfig) |
|
| 527 | 544 | return $module; |
| 545 | + } |
|
| 528 | 546 | echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n"; |
| 529 | 547 | } |
| 530 | 548 | return false; |
@@ -532,13 +550,15 @@ discard block |
||
| 532 | 550 | |
| 533 | 551 | protected function getOutputFile($app_dir, $namespace) |
| 534 | 552 | { |
| 535 | - if(is_file($namespace) && strpos($namespace, $app_dir) === 0) |
|
| 536 | - return $namespace; |
|
| 553 | + if(is_file($namespace) && strpos($namespace, $app_dir) === 0) { |
|
| 554 | + return $namespace; |
|
| 555 | + } |
|
| 537 | 556 | $file = Prado::getPathOfNamespace($namespace, ".php"); |
| 538 | 557 | if($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) |
| 539 | 558 | { |
| 540 | - if(strpos($path, $app_dir) === 0) |
|
| 541 | - return $file; |
|
| 559 | + if(strpos($path, $app_dir) === 0) { |
|
| 560 | + return $file; |
|
| 561 | + } |
|
| 542 | 562 | } |
| 543 | 563 | echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n"; |
| 544 | 564 | return false; |
@@ -554,12 +574,12 @@ discard block |
||
| 554 | 574 | { |
| 555 | 575 | echo '** Unable to find table or view "' . $tablename . '" in "' . $manager->getDbConnection()->getConnectionString() . "\".\n"; |
| 556 | 576 | return false; |
| 557 | - } |
|
| 558 | - else |
|
| 577 | + } else |
|
| 559 | 578 | { |
| 560 | 579 | $properties = []; |
| 561 | - foreach($tableInfo->getColumns() as $field => $column) |
|
| 562 | - $properties[] = $this->generateProperty($field, $column); |
|
| 580 | + foreach($tableInfo->getColumns() as $field => $column) { |
|
| 581 | + $properties[] = $this->generateProperty($field, $column); |
|
| 582 | + } |
|
| 563 | 583 | } |
| 564 | 584 | |
| 565 | 585 | $classname = basename($output, '.php'); |
@@ -692,58 +712,67 @@ discard block |
||
| 692 | 712 | if(count($input) > 2) |
| 693 | 713 | { |
| 694 | 714 | $app_dir = '.'; |
| 695 | - if(Prado::getApplication() !== null) |
|
| 696 | - $app_dir = dirname(Prado::getApplication()->getBasePath()); |
|
| 715 | + if(Prado::getApplication() !== null) { |
|
| 716 | + $app_dir = dirname(Prado::getApplication()->getBasePath()); |
|
| 717 | + } |
|
| 697 | 718 | $args = [$input[0],$input[1], $input[2],$app_dir]; |
| 698 | - if(count($input) > 3) |
|
| 699 | - $args = [$input[0],$input[1], $input[2],$app_dir,'soap']; |
|
| 719 | + if(count($input) > 3) { |
|
| 720 | + $args = [$input[0],$input[1], $input[2],$app_dir,'soap']; |
|
| 721 | + } |
|
| 700 | 722 | $cmd = new PradoCommandLineActiveRecordGen; |
| 701 | 723 | $cmd->performAction($args); |
| 702 | - } |
|
| 703 | - else |
|
| 724 | + } else |
|
| 704 | 725 | { |
| 705 | 726 | echo "\n Usage: generate table_name Application.pages.RecordClassName\n"; |
| 706 | 727 | } |
| 707 | 728 | } |
| 708 | 729 | |
| 709 | 730 | protected function getAppDir($dir = ".") { |
| 710 | - if (is_dir($dir)) |
|
| 711 | - return realpath($dir); |
|
| 712 | - if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir)) |
|
| 713 | - return $app_dir; |
|
| 731 | + if (is_dir($dir)) { |
|
| 732 | + return realpath($dir); |
|
| 733 | + } |
|
| 734 | + if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir)) { |
|
| 735 | + return $app_dir; |
|
| 736 | + } |
|
| 714 | 737 | echo '** Unable to find directory "' . $dir . "\".\n"; |
| 715 | 738 | return false; |
| 716 | 739 | } |
| 717 | 740 | |
| 718 | 741 | protected function getXmlFile($app_dir) { |
| 719 | - if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml)) |
|
| 720 | - return $xml; |
|
| 721 | - if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml)) |
|
| 722 | - return $xml; |
|
| 742 | + if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml)) { |
|
| 743 | + return $xml; |
|
| 744 | + } |
|
| 745 | + if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml)) { |
|
| 746 | + return $xml; |
|
| 747 | + } |
|
| 723 | 748 | echo '** Unable to find application.xml in ' . $app_dir . "\n"; |
| 724 | 749 | return false; |
| 725 | 750 | } |
| 726 | 751 | |
| 727 | 752 | protected function getActiveRecordConfig($app_dir) { |
| 728 | - if (false === ($xml = $this->getXmlFile($app_dir))) |
|
| 729 | - return false; |
|
| 753 | + if (false === ($xml = $this->getXmlFile($app_dir))) { |
|
| 754 | + return false; |
|
| 755 | + } |
|
| 730 | 756 | if (false !== ($app = $this->initializePradoApplication($app_dir))) { |
| 731 | 757 | Prado::using('System.Data.ActiveRecord.TActiveRecordConfig'); |
| 732 | - foreach ($app->getModules() as $module) |
|
| 733 | - if ($module instanceof TActiveRecordConfig) |
|
| 758 | + foreach ($app->getModules() as $module) { |
|
| 759 | + if ($module instanceof TActiveRecordConfig) |
|
| 734 | 760 | return $module; |
| 761 | + } |
|
| 735 | 762 | echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n"; |
| 736 | 763 | } |
| 737 | 764 | return false; |
| 738 | 765 | } |
| 739 | 766 | |
| 740 | 767 | protected function getOutputFile($app_dir, $namespace) { |
| 741 | - if (is_file($namespace) && strpos($namespace, $app_dir) === 0) |
|
| 742 | - return $namespace; |
|
| 768 | + if (is_file($namespace) && strpos($namespace, $app_dir) === 0) { |
|
| 769 | + return $namespace; |
|
| 770 | + } |
|
| 743 | 771 | $file = Prado::getPathOfNamespace($namespace, ""); |
| 744 | 772 | if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) { |
| 745 | - if (strpos($path, $app_dir) === 0) |
|
| 746 | - return $file; |
|
| 773 | + if (strpos($path, $app_dir) === 0) { |
|
| 774 | + return $file; |
|
| 775 | + } |
|
| 747 | 776 | } |
| 748 | 777 | echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n"; |
| 749 | 778 | return false; |
@@ -300,8 +300,9 @@ discard block |
||
| 300 | 300 | $this->setConfigurationType($configType); |
| 301 | 301 | $this->resolvePaths($basePath); |
| 302 | 302 | |
| 303 | - if($cacheConfig) |
|
| 304 | - $this->_cacheFile = $this->_runtimePath . DIRECTORY_SEPARATOR . self::CONFIGCACHE_FILE; |
|
| 303 | + if($cacheConfig) { |
|
| 304 | + $this->_cacheFile = $this->_runtimePath . DIRECTORY_SEPARATOR . self::CONFIGCACHE_FILE; |
|
| 305 | + } |
|
| 305 | 306 | |
| 306 | 307 | // generates unique ID by hashing the runtime path |
| 307 | 308 | $this->_uniqueID = md5($this->_runtimePath); |
@@ -324,17 +325,18 @@ discard block |
||
| 324 | 325 | protected function resolvePaths($basePath) |
| 325 | 326 | { |
| 326 | 327 | // determine configuration path and file |
| 327 | - if(empty($basePath) || ($basePath = realpath($basePath)) === false) |
|
| 328 | - throw new TConfigurationException('application_basepath_invalid', $basePath); |
|
| 329 | - if(is_dir($basePath) && is_file($basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName())) |
|
| 330 | - $configFile = $basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName(); |
|
| 331 | - elseif(is_file($basePath)) |
|
| 328 | + if(empty($basePath) || ($basePath = realpath($basePath)) === false) { |
|
| 329 | + throw new TConfigurationException('application_basepath_invalid', $basePath); |
|
| 330 | + } |
|
| 331 | + if(is_dir($basePath) && is_file($basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName())) { |
|
| 332 | + $configFile = $basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName(); |
|
| 333 | + } elseif(is_file($basePath)) |
|
| 332 | 334 | { |
| 333 | 335 | $configFile = $basePath; |
| 334 | 336 | $basePath = dirname($configFile); |
| 337 | + } else { |
|
| 338 | + $configFile = null; |
|
| 335 | 339 | } |
| 336 | - else |
|
| 337 | - $configFile = null; |
|
| 338 | 340 | |
| 339 | 341 | // determine runtime path |
| 340 | 342 | $runtimePath = $basePath . DIRECTORY_SEPARATOR . self::RUNTIME_PATH; |
@@ -345,17 +347,18 @@ discard block |
||
| 345 | 347 | $runtimePath .= DIRECTORY_SEPARATOR . basename($configFile) . '-' . Prado::getVersion(); |
| 346 | 348 | if(!is_dir($runtimePath)) |
| 347 | 349 | { |
| 348 | - if(@mkdir($runtimePath) === false) |
|
| 349 | - throw new TConfigurationException('application_runtimepath_failed', $runtimePath); |
|
| 350 | + if(@mkdir($runtimePath) === false) { |
|
| 351 | + throw new TConfigurationException('application_runtimepath_failed', $runtimePath); |
|
| 352 | + } |
|
| 350 | 353 | @chmod($runtimePath, PRADO_CHMOD); //make it deletable |
| 351 | 354 | } |
| 352 | 355 | $this->setConfigurationFile($configFile); |
| 353 | 356 | } |
| 354 | 357 | $this->setBasePath($basePath); |
| 355 | 358 | $this->setRuntimePath($runtimePath); |
| 359 | + } else { |
|
| 360 | + throw new TConfigurationException('application_runtimepath_invalid', $runtimePath); |
|
| 356 | 361 | } |
| 357 | - else |
|
| 358 | - throw new TConfigurationException('application_runtimepath_invalid', $runtimePath); |
|
| 359 | 362 | |
| 360 | 363 | } |
| 361 | 364 | |
@@ -374,17 +377,18 @@ discard block |
||
| 374 | 377 | $this->_requestCompleted = false; |
| 375 | 378 | while($this->_step < $n) |
| 376 | 379 | { |
| 377 | - if($this->_mode === TApplicationMode::Off) |
|
| 378 | - throw new THttpException(503, 'application_unavailable'); |
|
| 379 | - if($this->_requestCompleted) |
|
| 380 | - break; |
|
| 380 | + if($this->_mode === TApplicationMode::Off) { |
|
| 381 | + throw new THttpException(503, 'application_unavailable'); |
|
| 382 | + } |
|
| 383 | + if($this->_requestCompleted) { |
|
| 384 | + break; |
|
| 385 | + } |
|
| 381 | 386 | $method = self::$_steps[$this->_step]; |
| 382 | 387 | Prado::trace("Executing $method()", 'Prado\TApplication'); |
| 383 | 388 | $this->$method(); |
| 384 | 389 | $this->_step++; |
| 385 | 390 | } |
| 386 | - } |
|
| 387 | - catch(\Exception $e) |
|
| 391 | + } catch(\Exception $e) |
|
| 388 | 392 | { |
| 389 | 393 | $this->onError($e); |
| 390 | 394 | } |
@@ -435,12 +439,14 @@ discard block |
||
| 435 | 439 | public function setGlobalState($key, $value, $defaultValue = null, $forceSave = false) |
| 436 | 440 | { |
| 437 | 441 | $this->_stateChanged = true; |
| 438 | - if($value === $defaultValue) |
|
| 439 | - unset($this->_globals[$key]); |
|
| 440 | - else |
|
| 441 | - $this->_globals[$key] = $value; |
|
| 442 | - if($forceSave) |
|
| 443 | - $this->saveGlobals(); |
|
| 442 | + if($value === $defaultValue) { |
|
| 443 | + unset($this->_globals[$key]); |
|
| 444 | + } else { |
|
| 445 | + $this->_globals[$key] = $value; |
|
| 446 | + } |
|
| 447 | + if($forceSave) { |
|
| 448 | + $this->saveGlobals(); |
|
| 449 | + } |
|
| 444 | 450 | } |
| 445 | 451 | |
| 446 | 452 | /** |
@@ -636,8 +642,9 @@ discard block |
||
| 636 | 642 | public function setRuntimePath($value) |
| 637 | 643 | { |
| 638 | 644 | $this->_runtimePath = $value; |
| 639 | - if($this->_cacheFile) |
|
| 640 | - $this->_cacheFile = $this->_runtimePath . DIRECTORY_SEPARATOR . self::CONFIGCACHE_FILE; |
|
| 645 | + if($this->_cacheFile) { |
|
| 646 | + $this->_cacheFile = $this->_runtimePath . DIRECTORY_SEPARATOR . self::CONFIGCACHE_FILE; |
|
| 647 | + } |
|
| 641 | 648 | // generates unique ID by hashing the runtime path |
| 642 | 649 | $this->_uniqueID = md5($this->_runtimePath); |
| 643 | 650 | } |
@@ -666,10 +673,11 @@ discard block |
||
| 666 | 673 | */ |
| 667 | 674 | public function setModule($id, IModule $module = null) |
| 668 | 675 | { |
| 669 | - if(isset($this->_modules[$id])) |
|
| 670 | - throw new TConfigurationException('application_moduleid_duplicated', $id); |
|
| 671 | - else |
|
| 672 | - $this->_modules[$id] = $module; |
|
| 676 | + if(isset($this->_modules[$id])) { |
|
| 677 | + throw new TConfigurationException('application_moduleid_duplicated', $id); |
|
| 678 | + } else { |
|
| 679 | + $this->_modules[$id] = $module; |
|
| 680 | + } |
|
| 673 | 681 | } |
| 674 | 682 | |
| 675 | 683 | /** |
@@ -677,8 +685,9 @@ discard block |
||
| 677 | 685 | */ |
| 678 | 686 | public function getModule($id) |
| 679 | 687 | { |
| 680 | - if(!array_key_exists($id, $this->_modules)) |
|
| 681 | - return null; |
|
| 688 | + if(!array_key_exists($id, $this->_modules)) { |
|
| 689 | + return null; |
|
| 690 | + } |
|
| 682 | 691 | |
| 683 | 692 | // force loading of a lazy module |
| 684 | 693 | if($this->_modules[$id] === null) |
@@ -917,8 +926,9 @@ discard block |
||
| 917 | 926 | */ |
| 918 | 927 | public function getAuthorizationRules() |
| 919 | 928 | { |
| 920 | - if($this->_authRules === null) |
|
| 921 | - $this->_authRules = new \Prado\Security\TAuthorizationRuleCollection; |
|
| 929 | + if($this->_authRules === null) { |
|
| 930 | + $this->_authRules = new \Prado\Security\TAuthorizationRuleCollection; |
|
| 931 | + } |
|
| 922 | 932 | return $this->_authRules; |
| 923 | 933 | } |
| 924 | 934 | |
@@ -941,7 +951,9 @@ discard block |
||
| 941 | 951 | $module = Prado::createComponent($moduleClass); |
| 942 | 952 | foreach($initProperties as $name => $value) |
| 943 | 953 | { |
| 944 | - if($name === 'lazy') continue; |
|
| 954 | + if($name === 'lazy') { |
|
| 955 | + continue; |
|
| 956 | + } |
|
| 945 | 957 | $module->setSubProperty($name, $value); |
| 946 | 958 | } |
| 947 | 959 | $this->setModule($id, $module); |
@@ -957,24 +969,29 @@ discard block |
||
| 957 | 969 | */ |
| 958 | 970 | public function applyConfiguration($config, $withinService = false) |
| 959 | 971 | { |
| 960 | - if($config->getIsEmpty()) |
|
| 961 | - return; |
|
| 972 | + if($config->getIsEmpty()) { |
|
| 973 | + return; |
|
| 974 | + } |
|
| 962 | 975 | |
| 963 | 976 | // set path aliases and using namespaces |
| 964 | - foreach($config->getAliases() as $alias => $path) |
|
| 965 | - Prado::setPathOfAlias($alias, $path); |
|
| 966 | - foreach($config->getUsings() as $using) |
|
| 967 | - Prado::using($using); |
|
| 977 | + foreach($config->getAliases() as $alias => $path) { |
|
| 978 | + Prado::setPathOfAlias($alias, $path); |
|
| 979 | + } |
|
| 980 | + foreach($config->getUsings() as $using) { |
|
| 981 | + Prado::using($using); |
|
| 982 | + } |
|
| 968 | 983 | |
| 969 | 984 | // set application properties |
| 970 | 985 | if(!$withinService) |
| 971 | 986 | { |
| 972 | - foreach($config->getProperties() as $name => $value) |
|
| 973 | - $this->setSubProperty($name, $value); |
|
| 987 | + foreach($config->getProperties() as $name => $value) { |
|
| 988 | + $this->setSubProperty($name, $value); |
|
| 989 | + } |
|
| 974 | 990 | } |
| 975 | 991 | |
| 976 | - if(empty($this->_services)) |
|
| 977 | - $this->_services = [$this->getPageServiceID() => ['Prado\Web\Services\TPageService',[],null]]; |
|
| 992 | + if(empty($this->_services)) { |
|
| 993 | + $this->_services = [$this->getPageServiceID() => ['Prado\Web\Services\TPageService',[],null]]; |
|
| 994 | + } |
|
| 978 | 995 | |
| 979 | 996 | // load parameters |
| 980 | 997 | foreach($config->getParameters() as $id => $parameter) |
@@ -982,40 +999,47 @@ discard block |
||
| 982 | 999 | if(is_array($parameter)) |
| 983 | 1000 | { |
| 984 | 1001 | $component = Prado::createComponent($parameter[0]); |
| 985 | - foreach($parameter[1] as $name => $value) |
|
| 986 | - $component->setSubProperty($name, $value); |
|
| 1002 | + foreach($parameter[1] as $name => $value) { |
|
| 1003 | + $component->setSubProperty($name, $value); |
|
| 1004 | + } |
|
| 987 | 1005 | $this->_parameters->add($id, $component); |
| 1006 | + } else { |
|
| 1007 | + $this->_parameters->add($id, $parameter); |
|
| 988 | 1008 | } |
| 989 | - else |
|
| 990 | - $this->_parameters->add($id, $parameter); |
|
| 991 | 1009 | } |
| 992 | 1010 | |
| 993 | 1011 | // load and init modules specified in app config |
| 994 | 1012 | $modules = []; |
| 995 | 1013 | foreach($config->getModules() as $id => $moduleConfig) |
| 996 | 1014 | { |
| 997 | - if(!is_string($id)) |
|
| 998 | - $id = '_module' . count($this->_lazyModules); |
|
| 1015 | + if(!is_string($id)) { |
|
| 1016 | + $id = '_module' . count($this->_lazyModules); |
|
| 1017 | + } |
|
| 999 | 1018 | $this->_lazyModules[$id] = $moduleConfig; |
| 1000 | - if($module = $this->internalLoadModule($id)) |
|
| 1001 | - $modules[] = $module; |
|
| 1019 | + if($module = $this->internalLoadModule($id)) { |
|
| 1020 | + $modules[] = $module; |
|
| 1021 | + } |
|
| 1022 | + } |
|
| 1023 | + foreach($modules as $module) { |
|
| 1024 | + $module[0]->init($module[1]); |
|
| 1002 | 1025 | } |
| 1003 | - foreach($modules as $module) |
|
| 1004 | - $module[0]->init($module[1]); |
|
| 1005 | 1026 | |
| 1006 | 1027 | // load service |
| 1007 | - foreach($config->getServices() as $serviceID => $serviceConfig) |
|
| 1008 | - $this->_services[$serviceID] = $serviceConfig; |
|
| 1028 | + foreach($config->getServices() as $serviceID => $serviceConfig) { |
|
| 1029 | + $this->_services[$serviceID] = $serviceConfig; |
|
| 1030 | + } |
|
| 1009 | 1031 | |
| 1010 | 1032 | // external configurations |
| 1011 | 1033 | foreach($config->getExternalConfigurations() as $filePath => $condition) |
| 1012 | 1034 | { |
| 1013 | - if($condition !== true) |
|
| 1014 | - $condition = $this->evaluateExpression($condition); |
|
| 1035 | + if($condition !== true) { |
|
| 1036 | + $condition = $this->evaluateExpression($condition); |
|
| 1037 | + } |
|
| 1015 | 1038 | if($condition) |
| 1016 | 1039 | { |
| 1017 | - if(($path = Prado::getPathOfNamespace($filePath, $this->getConfigurationFileExt())) === null || !is_file($path)) |
|
| 1018 | - throw new TConfigurationException('application_includefile_invalid', $filePath); |
|
| 1040 | + if(($path = Prado::getPathOfNamespace($filePath, $this->getConfigurationFileExt())) === null || !is_file($path)) { |
|
| 1041 | + throw new TConfigurationException('application_includefile_invalid', $filePath); |
|
| 1042 | + } |
|
| 1019 | 1043 | $cn = $this->getApplicationConfigurationClass(); |
| 1020 | 1044 | $c = new $cn; |
| 1021 | 1045 | $c->loadFromFile($path); |
@@ -1043,17 +1067,19 @@ discard block |
||
| 1043 | 1067 | { |
| 1044 | 1068 | $config = new TApplicationConfiguration; |
| 1045 | 1069 | $config->loadFromFile($this->_configFile); |
| 1046 | - if($this->_cacheFile !== null) |
|
| 1047 | - file_put_contents($this->_cacheFile, serialize($config), LOCK_EX); |
|
| 1070 | + if($this->_cacheFile !== null) { |
|
| 1071 | + file_put_contents($this->_cacheFile, serialize($config), LOCK_EX); |
|
| 1072 | + } |
|
| 1073 | + } else { |
|
| 1074 | + $config = unserialize(file_get_contents($this->_cacheFile)); |
|
| 1048 | 1075 | } |
| 1049 | - else |
|
| 1050 | - $config = unserialize(file_get_contents($this->_cacheFile)); |
|
| 1051 | 1076 | |
| 1052 | 1077 | $this->applyConfiguration($config, false); |
| 1053 | 1078 | } |
| 1054 | 1079 | |
| 1055 | - if(($serviceID = $this->getRequest()->resolveRequest(array_keys($this->_services))) === null) |
|
| 1056 | - $serviceID = $this->getPageServiceID(); |
|
| 1080 | + if(($serviceID = $this->getRequest()->resolveRequest(array_keys($this->_services))) === null) { |
|
| 1081 | + $serviceID = $this->getPageServiceID(); |
|
| 1082 | + } |
|
| 1057 | 1083 | |
| 1058 | 1084 | $this->startService($serviceID); |
| 1059 | 1085 | } |
@@ -1070,30 +1096,34 @@ discard block |
||
| 1070 | 1096 | { |
| 1071 | 1097 | list($serviceClass, $initProperties, $configElement) = $this->_services[$serviceID]; |
| 1072 | 1098 | $service = Prado::createComponent($serviceClass); |
| 1073 | - if(!($service instanceof IService)) |
|
| 1074 | - throw new THttpException(500, 'application_service_invalid', $serviceClass); |
|
| 1075 | - if(!$service->getEnabled()) |
|
| 1076 | - throw new THttpException(500, 'application_service_unavailable', $serviceClass); |
|
| 1099 | + if(!($service instanceof IService)) { |
|
| 1100 | + throw new THttpException(500, 'application_service_invalid', $serviceClass); |
|
| 1101 | + } |
|
| 1102 | + if(!$service->getEnabled()) { |
|
| 1103 | + throw new THttpException(500, 'application_service_unavailable', $serviceClass); |
|
| 1104 | + } |
|
| 1077 | 1105 | $service->setID($serviceID); |
| 1078 | 1106 | $this->setService($service); |
| 1079 | 1107 | |
| 1080 | - foreach($initProperties as $name => $value) |
|
| 1081 | - $service->setSubProperty($name, $value); |
|
| 1108 | + foreach($initProperties as $name => $value) { |
|
| 1109 | + $service->setSubProperty($name, $value); |
|
| 1110 | + } |
|
| 1082 | 1111 | |
| 1083 | 1112 | if($configElement !== null) |
| 1084 | 1113 | { |
| 1085 | 1114 | $config = new TApplicationConfiguration; |
| 1086 | - if($this->getConfigurationType() == self::CONFIG_TYPE_PHP) |
|
| 1087 | - $config->loadFromPhp($configElement, $this->getBasePath()); |
|
| 1088 | - else |
|
| 1089 | - $config->loadFromXml($configElement, $this->getBasePath()); |
|
| 1115 | + if($this->getConfigurationType() == self::CONFIG_TYPE_PHP) { |
|
| 1116 | + $config->loadFromPhp($configElement, $this->getBasePath()); |
|
| 1117 | + } else { |
|
| 1118 | + $config->loadFromXml($configElement, $this->getBasePath()); |
|
| 1119 | + } |
|
| 1090 | 1120 | $this->applyConfiguration($config, true); |
| 1091 | 1121 | } |
| 1092 | 1122 | |
| 1093 | 1123 | $service->init($configElement); |
| 1124 | + } else { |
|
| 1125 | + throw new THttpException(500, 'application_service_unknown', $serviceID); |
|
| 1094 | 1126 | } |
| 1095 | - else |
|
| 1096 | - throw new THttpException(500, 'application_service_unknown', $serviceID); |
|
| 1097 | 1127 | } |
| 1098 | 1128 | |
| 1099 | 1129 | /** |
@@ -1190,8 +1220,9 @@ discard block |
||
| 1190 | 1220 | */ |
| 1191 | 1221 | public function runService() |
| 1192 | 1222 | { |
| 1193 | - if($this->_service) |
|
| 1194 | - $this->_service->run(); |
|
| 1223 | + if($this->_service) { |
|
| 1224 | + $this->_service->run(); |
|
| 1225 | + } |
|
| 1195 | 1226 | } |
| 1196 | 1227 | |
| 1197 | 1228 | /** |
@@ -117,8 +117,7 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | $userFile = include $this->_userFile; |
| 119 | 119 | $this->loadUserDataFromPhp($userFile); |
| 120 | - } |
|
| 121 | - else |
|
| 120 | + } else |
|
| 122 | 121 | { |
| 123 | 122 | $dom = new TXmlDocument; |
| 124 | 123 | $dom->loadFromFile($this->_userFile); |
@@ -134,10 +133,11 @@ discard block |
||
| 134 | 133 | */ |
| 135 | 134 | private function loadUserData($config) |
| 136 | 135 | { |
| 137 | - if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
| 138 | - $this->loadUserDataFromPhp($config); |
|
| 139 | - else |
|
| 140 | - $this->loadUserDataFromXml($config); |
|
| 136 | + if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) { |
|
| 137 | + $this->loadUserDataFromPhp($config); |
|
| 138 | + } else { |
|
| 139 | + $this->loadUserDataFromXml($config); |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -158,8 +158,9 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | foreach(explode(',', $roles) as $role) |
| 160 | 160 | { |
| 161 | - if(($role = trim($role)) !== '') |
|
| 162 | - $this->_roles[$name][] = $role; |
|
| 161 | + if(($role = trim($role)) !== '') { |
|
| 162 | + $this->_roles[$name][] = $role; |
|
| 163 | + } |
|
| 163 | 164 | } |
| 164 | 165 | } |
| 165 | 166 | } |
@@ -172,8 +173,9 @@ discard block |
||
| 172 | 173 | $users = isset($role['users'])?$role['users']:''; |
| 173 | 174 | foreach(explode(',', $users) as $user) |
| 174 | 175 | { |
| 175 | - if(($user = trim($user)) !== '') |
|
| 176 | - $this->_roles[strtolower($user)][] = $name; |
|
| 176 | + if(($user = trim($user)) !== '') { |
|
| 177 | + $this->_roles[strtolower($user)][] = $name; |
|
| 178 | + } |
|
| 177 | 179 | } |
| 178 | 180 | } |
| 179 | 181 | } |
@@ -193,8 +195,9 @@ discard block |
||
| 193 | 195 | { |
| 194 | 196 | foreach(explode(',', $roles) as $role) |
| 195 | 197 | { |
| 196 | - if(($role = trim($role)) !== '') |
|
| 197 | - $this->_roles[$name][] = $role; |
|
| 198 | + if(($role = trim($role)) !== '') { |
|
| 199 | + $this->_roles[$name][] = $role; |
|
| 200 | + } |
|
| 198 | 201 | } |
| 199 | 202 | } |
| 200 | 203 | } |
@@ -202,8 +205,9 @@ discard block |
||
| 202 | 205 | { |
| 203 | 206 | foreach(explode(',', $node->getAttribute('users')) as $user) |
| 204 | 207 | { |
| 205 | - if(($user = trim($user)) !== '') |
|
| 206 | - $this->_roles[strtolower($user)][] = $node->getAttribute('name'); |
|
| 208 | + if(($user = trim($user)) !== '') { |
|
| 209 | + $this->_roles[strtolower($user)][] = $node->getAttribute('name'); |
|
| 210 | + } |
|
| 207 | 211 | } |
| 208 | 212 | } |
| 209 | 213 | } |
@@ -248,10 +252,11 @@ discard block |
||
| 248 | 252 | */ |
| 249 | 253 | public function setUserFile($value) |
| 250 | 254 | { |
| 251 | - if($this->_initialized) |
|
| 252 | - throw new TInvalidOperationException('usermanager_userfile_unchangeable'); |
|
| 253 | - elseif(($this->_userFile = Prado::getPathOfNamespace($value, self::USER_FILE_EXT)) === null || !is_file($this->_userFile)) |
|
| 254 | - throw new TConfigurationException('usermanager_userfile_invalid', $value); |
|
| 255 | + if($this->_initialized) { |
|
| 256 | + throw new TInvalidOperationException('usermanager_userfile_unchangeable'); |
|
| 257 | + } elseif(($this->_userFile = Prado::getPathOfNamespace($value, self::USER_FILE_EXT)) === null || !is_file($this->_userFile)) { |
|
| 258 | + throw new TConfigurationException('usermanager_userfile_invalid', $value); |
|
| 259 | + } |
|
| 255 | 260 | } |
| 256 | 261 | |
| 257 | 262 | /** |
@@ -294,10 +299,11 @@ discard block |
||
| 294 | 299 | */ |
| 295 | 300 | public function validateUser($username, $password) |
| 296 | 301 | { |
| 297 | - if($this->_passwordMode === TUserManagerPasswordMode::MD5) |
|
| 298 | - $password = md5($password); |
|
| 299 | - elseif($this->_passwordMode === TUserManagerPasswordMode::SHA1) |
|
| 300 | - $password = sha1($password); |
|
| 302 | + if($this->_passwordMode === TUserManagerPasswordMode::MD5) { |
|
| 303 | + $password = md5($password); |
|
| 304 | + } elseif($this->_passwordMode === TUserManagerPasswordMode::SHA1) { |
|
| 305 | + $password = sha1($password); |
|
| 306 | + } |
|
| 301 | 307 | $username = strtolower($username); |
| 302 | 308 | return (isset($this->_users[$username]) && $this->_users[$username] === $password); |
| 303 | 309 | } |
@@ -314,8 +320,7 @@ discard block |
||
| 314 | 320 | $user = new TUser($this); |
| 315 | 321 | $user->setIsGuest(true); |
| 316 | 322 | return $user; |
| 317 | - } |
|
| 318 | - else |
|
| 323 | + } else |
|
| 319 | 324 | { |
| 320 | 325 | $username = strtolower($username); |
| 321 | 326 | if(isset($this->_users[$username])) |
@@ -323,12 +328,13 @@ discard block |
||
| 323 | 328 | $user = new TUser($this); |
| 324 | 329 | $user->setName($username); |
| 325 | 330 | $user->setIsGuest(false); |
| 326 | - if(isset($this->_roles[$username])) |
|
| 327 | - $user->setRoles($this->_roles[$username]); |
|
| 331 | + if(isset($this->_roles[$username])) { |
|
| 332 | + $user->setRoles($this->_roles[$username]); |
|
| 333 | + } |
|
| 328 | 334 | return $user; |
| 335 | + } else { |
|
| 336 | + return null; |
|
| 329 | 337 | } |
| 330 | - else |
|
| 331 | - return null; |
|
| 332 | 338 | } |
| 333 | 339 | } |
| 334 | 340 | |
@@ -346,8 +352,9 @@ discard block |
||
| 346 | 352 | if(is_array($data) && count($data) === 2) |
| 347 | 353 | { |
| 348 | 354 | list($username, $token) = $data; |
| 349 | - if(isset($this->_users[$username]) && $token === md5($username . $this->_users[$username])) |
|
| 350 | - return $this->getUser($username); |
|
| 355 | + if(isset($this->_users[$username]) && $token === md5($username . $this->_users[$username])) { |
|
| 356 | + return $this->getUser($username); |
|
| 357 | + } |
|
| 351 | 358 | } |
| 352 | 359 | } |
| 353 | 360 | return null; |
@@ -89,17 +89,21 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function init($config) |
| 91 | 91 | { |
| 92 | - if($this->_userManager === null) |
|
| 93 | - throw new TConfigurationException('authmanager_usermanager_required'); |
|
| 94 | - if($this->_returnUrlVarName === null) |
|
| 95 | - $this->_returnUrlVarName = $this->getApplication()->getID() . ':' . self::RETURN_URL_VAR; |
|
| 92 | + if($this->_userManager === null) { |
|
| 93 | + throw new TConfigurationException('authmanager_usermanager_required'); |
|
| 94 | + } |
|
| 95 | + if($this->_returnUrlVarName === null) { |
|
| 96 | + $this->_returnUrlVarName = $this->getApplication()->getID() . ':' . self::RETURN_URL_VAR; |
|
| 97 | + } |
|
| 96 | 98 | $application = $this->getApplication(); |
| 97 | 99 | if(is_string($this->_userManager)) |
| 98 | 100 | { |
| 99 | - if(($users = $application->getModule($this->_userManager)) === null) |
|
| 100 | - throw new TConfigurationException('authmanager_usermanager_inexistent', $this->_userManager); |
|
| 101 | - if(!($users instanceof IUserManager)) |
|
| 102 | - throw new TConfigurationException('authmanager_usermanager_invalid', $this->_userManager); |
|
| 101 | + if(($users = $application->getModule($this->_userManager)) === null) { |
|
| 102 | + throw new TConfigurationException('authmanager_usermanager_inexistent', $this->_userManager); |
|
| 103 | + } |
|
| 104 | + if(!($users instanceof IUserManager)) { |
|
| 105 | + throw new TConfigurationException('authmanager_usermanager_invalid', $this->_userManager); |
|
| 106 | + } |
|
| 103 | 107 | $this->_userManager = $users; |
| 104 | 108 | } |
| 105 | 109 | $application->attachEventHandler('OnAuthentication', [$this,'doAuthentication']); |
@@ -122,10 +126,12 @@ discard block |
||
| 122 | 126 | */ |
| 123 | 127 | public function setUserManager($provider) |
| 124 | 128 | { |
| 125 | - if($this->_initialized) |
|
| 126 | - throw new TInvalidOperationException('authmanager_usermanager_unchangeable'); |
|
| 127 | - if(!is_string($provider) && !($provider instanceof IUserManager)) |
|
| 128 | - throw new TConfigurationException('authmanager_usermanager_invalid', $this->_userManager); |
|
| 129 | + if($this->_initialized) { |
|
| 130 | + throw new TInvalidOperationException('authmanager_usermanager_unchangeable'); |
|
| 131 | + } |
|
| 132 | + if(!is_string($provider) && !($provider instanceof IUserManager)) { |
|
| 133 | + throw new TConfigurationException('authmanager_usermanager_invalid', $this->_userManager); |
|
| 134 | + } |
|
| 129 | 135 | $this->_userManager = $provider; |
| 130 | 136 | } |
| 131 | 137 | |
@@ -160,8 +166,9 @@ discard block |
||
| 160 | 166 | $this->onAuthenticate($param); |
| 161 | 167 | |
| 162 | 168 | $service = $this->getService(); |
| 163 | - if(($service instanceof TPageService) && $service->getRequestedPagePath() === $this->getLoginPage()) |
|
| 164 | - $this->_skipAuthorization = true; |
|
| 169 | + if(($service instanceof TPageService) && $service->getRequestedPagePath() === $this->getLoginPage()) { |
|
| 170 | + $this->_skipAuthorization = true; |
|
| 171 | + } |
|
| 165 | 172 | } |
| 166 | 173 | |
| 167 | 174 | /** |
@@ -284,8 +291,9 @@ discard block |
||
| 284 | 291 | $application = $this->getApplication(); |
| 285 | 292 | |
| 286 | 293 | // restoring user info from session |
| 287 | - if(($session = $application->getSession()) === null) |
|
| 288 | - throw new TConfigurationException('authmanager_session_required'); |
|
| 294 | + if(($session = $application->getSession()) === null) { |
|
| 295 | + throw new TConfigurationException('authmanager_session_required'); |
|
| 296 | + } |
|
| 289 | 297 | $session->open(); |
| 290 | 298 | $sessionInfo = $session->itemAt($this->getUserKey()); |
| 291 | 299 | $user = $this->_userManager->getUser(null)->loadFromString($sessionInfo); |
@@ -313,14 +321,16 @@ discard block |
||
| 313 | 321 | $application->setUser($user); |
| 314 | 322 | |
| 315 | 323 | // handle authentication expiration or update expiration time |
| 316 | - if($isAuthExpired) |
|
| 317 | - $this->onAuthExpire($param); |
|
| 318 | - else |
|
| 319 | - $session->add('AuthExpireTime', time() + $this->_authExpire); |
|
| 324 | + if($isAuthExpired) { |
|
| 325 | + $this->onAuthExpire($param); |
|
| 326 | + } else { |
|
| 327 | + $session->add('AuthExpireTime', time() + $this->_authExpire); |
|
| 328 | + } |
|
| 320 | 329 | |
| 321 | 330 | // event handler gets a chance to do further auth work |
| 322 | - if($this->hasEventHandler('OnAuthenticate')) |
|
| 323 | - $this->raiseEvent('OnAuthenticate', $this, $application); |
|
| 331 | + if($this->hasEventHandler('OnAuthenticate')) { |
|
| 332 | + $this->raiseEvent('OnAuthenticate', $this, $application); |
|
| 333 | + } |
|
| 324 | 334 | } |
| 325 | 335 | |
| 326 | 336 | /** |
@@ -331,8 +341,9 @@ discard block |
||
| 331 | 341 | public function onAuthExpire($param) |
| 332 | 342 | { |
| 333 | 343 | $this->logout(); |
| 334 | - if($this->hasEventHandler('OnAuthExpire')) |
|
| 335 | - $this->raiseEvent('OnAuthExpire', $this, $param); |
|
| 344 | + if($this->hasEventHandler('OnAuthExpire')) { |
|
| 345 | + $this->raiseEvent('OnAuthExpire', $this, $param); |
|
| 346 | + } |
|
| 336 | 347 | } |
| 337 | 348 | |
| 338 | 349 | /** |
@@ -345,8 +356,9 @@ discard block |
||
| 345 | 356 | public function onAuthorize($param) |
| 346 | 357 | { |
| 347 | 358 | $application = $this->getApplication(); |
| 348 | - if($this->hasEventHandler('OnAuthorize')) |
|
| 349 | - $this->raiseEvent('OnAuthorize', $this, $application); |
|
| 359 | + if($this->hasEventHandler('OnAuthorize')) { |
|
| 360 | + $this->raiseEvent('OnAuthorize', $this, $application); |
|
| 361 | + } |
|
| 350 | 362 | if(!$application->getAuthorizationRules()->isUserAllowed($application->getUser(), $application->getRequest()->getRequestType(), $application->getRequest()->getUserHostAddress())) |
| 351 | 363 | { |
| 352 | 364 | $application->getResponse()->setStatusCode(401); |
@@ -360,8 +372,9 @@ discard block |
||
| 360 | 372 | */ |
| 361 | 373 | public function getUserKey() |
| 362 | 374 | { |
| 363 | - if($this->_userKey === null) |
|
| 364 | - $this->_userKey = $this->generateUserKey(); |
|
| 375 | + if($this->_userKey === null) { |
|
| 376 | + $this->_userKey = $this->generateUserKey(); |
|
| 377 | + } |
|
| 365 | 378 | return $this->_userKey; |
| 366 | 379 | } |
| 367 | 380 | |
@@ -383,10 +396,11 @@ discard block |
||
| 383 | 396 | { |
| 384 | 397 | if(!$user->getIsGuest()) |
| 385 | 398 | { |
| 386 | - if(($session = $this->getSession()) === null) |
|
| 387 | - throw new TConfigurationException('authmanager_session_required'); |
|
| 388 | - else |
|
| 389 | - $session->add($this->getUserKey(), $user->saveToString()); |
|
| 399 | + if(($session = $this->getSession()) === null) { |
|
| 400 | + throw new TConfigurationException('authmanager_session_required'); |
|
| 401 | + } else { |
|
| 402 | + $session->add($this->getUserKey(), $user->saveToString()); |
|
| 403 | + } |
|
| 390 | 404 | } |
| 391 | 405 | } |
| 392 | 406 | |
@@ -398,8 +412,9 @@ discard block |
||
| 398 | 412 | */ |
| 399 | 413 | public function switchUser($username) |
| 400 | 414 | { |
| 401 | - if(($user = $this->_userManager->getUser($username)) === null) |
|
| 402 | - return false; |
|
| 415 | + if(($user = $this->_userManager->getUser($username)) === null) { |
|
| 416 | + return false; |
|
| 417 | + } |
|
| 403 | 418 | $this->updateSessionUser($user); |
| 404 | 419 | $this->getApplication()->setUser($user); |
| 405 | 420 | return true; |
@@ -418,8 +433,9 @@ discard block |
||
| 418 | 433 | { |
| 419 | 434 | if($this->_userManager->validateUser($username, $password)) |
| 420 | 435 | { |
| 421 | - if(($user = $this->_userManager->getUser($username)) === null) |
|
| 422 | - return false; |
|
| 436 | + if(($user = $this->_userManager->getUser($username)) === null) { |
|
| 437 | + return false; |
|
| 438 | + } |
|
| 423 | 439 | $this->updateSessionUser($user); |
| 424 | 440 | $this->getApplication()->setUser($user); |
| 425 | 441 | |
@@ -431,9 +447,9 @@ discard block |
||
| 431 | 447 | $this->getResponse()->getCookies()->add($cookie); |
| 432 | 448 | } |
| 433 | 449 | return true; |
| 450 | + } else { |
|
| 451 | + return false; |
|
| 434 | 452 | } |
| 435 | - else |
|
| 436 | - return false; |
|
| 437 | 453 | } |
| 438 | 454 | |
| 439 | 455 | /** |
@@ -443,8 +459,9 @@ discard block |
||
| 443 | 459 | */ |
| 444 | 460 | public function logout() |
| 445 | 461 | { |
| 446 | - if(($session = $this->getSession()) === null) |
|
| 447 | - throw new TConfigurationException('authmanager_session_required'); |
|
| 462 | + if(($session = $this->getSession()) === null) { |
|
| 463 | + throw new TConfigurationException('authmanager_session_required'); |
|
| 464 | + } |
|
| 448 | 465 | $this->getApplication()->getUser()->setIsGuest(true); |
| 449 | 466 | $session->destroy(); |
| 450 | 467 | if($this->getAllowAutoLogin()) |
@@ -49,8 +49,9 @@ |
||
| 49 | 49 | $this->_connection = $connection; |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | - if($this->_connection === null) |
|
| 53 | - throw new TConfigurationException('dbuser_dbconnection_invalid'); |
|
| 52 | + if($this->_connection === null) { |
|
| 53 | + throw new TConfigurationException('dbuser_dbconnection_invalid'); |
|
| 54 | + } |
|
| 54 | 55 | } |
| 55 | 56 | return $this->_connection; |
| 56 | 57 | } |