Passed
Branch php-cs-fixer (b9836a)
by Fabio
15:58
created
bin/prado-cli.php 2 patches
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@  discard block
 block discarded – undo
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
 // Locate composer's autoloader
16
-if(file_exists($autoloader = realpath(__DIR__ . '/../vendor/autoload.php')))
16
+if (file_exists($autoloader = realpath(__DIR__.'/../vendor/autoload.php')))
17 17
 {
18 18
 	// if we are running inside a prado repo checkout, get out of bin/
19 19
 	include($autoloader);
20
-} elseif(file_exists($autoloader = realpath(__DIR__ . '/../../../autoload.php'))) {
20
+} elseif (file_exists($autoloader = realpath(__DIR__.'/../../../autoload.php'))) {
21 21
 	// if we are running from inside an application's vendor/ directory, get out of pradosoft/prado/bin/
22 22
 	include($autoloader);
23 23
 }
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
 	public static function getInstance()
79 79
 	{
80 80
 		static $instance;
81
-		if($instance === null)
81
+		if ($instance === null)
82 82
 			$instance = new self;
83 83
 		return $instance;
84 84
 	}
85 85
 
86 86
 	public static function printGreeting()
87 87
 	{
88
-		echo "Command line tools for Prado " . Prado::getVersion() . ".\n";
88
+		echo "Command line tools for Prado ".Prado::getVersion().".\n";
89 89
 	}
90 90
 
91 91
 	/**
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
 	 */
95 95
 	public function run($args)
96 96
 	{
97
-		if(count($args) > 1)
97
+		if (count($args) > 1)
98 98
 			array_shift($args);
99 99
 		$valid = false;
100
-		foreach($this->_actions as $class => $action)
100
+		foreach ($this->_actions as $class => $action)
101 101
 		{
102
-			if($action->isValidAction($args))
102
+			if ($action->isValidAction($args))
103 103
 			{
104 104
 				$valid |= $action->performAction($args);
105 105
 				break;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 				$valid = false;
110 110
 			}
111 111
 		}
112
-		if(!$valid)
112
+		if (!$valid)
113 113
 			$this->printHelp();
114 114
 	}
115 115
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 		echo "usage: php prado-cli.php action <parameter> [optional]\n";
124 124
 		echo "example: php prado-cli.php -c mysite\n\n";
125 125
 		echo "actions:\n";
126
-		foreach($this->_actions as $action)
126
+		foreach ($this->_actions as $action)
127 127
 			echo $action->renderHelp();
128 128
 	}
129 129
 }
@@ -145,18 +145,18 @@  discard block
 block discarded – undo
145 145
 
146 146
 	protected function createDirectory($dir, $mask)
147 147
 	{
148
-		if(!is_dir($dir))
148
+		if (!is_dir($dir))
149 149
 		{
150 150
 			mkdir($dir);
151 151
 			echo "creating $dir\n";
152 152
 		}
153
-		if(is_dir($dir))
153
+		if (is_dir($dir))
154 154
 			chmod($dir, $mask);
155 155
 	}
156 156
 
157 157
 	protected function createFile($filename, $content)
158 158
 	{
159
-		if(!is_file($filename))
159
+		if (!is_file($filename))
160 160
 		{
161 161
 			file_put_contents($filename, $content);
162 162
 			echo "creating $filename\n";
@@ -172,16 +172,16 @@  discard block
 block discarded – undo
172 172
 	public function renderHelp()
173 173
 	{
174 174
 		$params = [];
175
-		foreach($this->parameters as $v)
176
-			$params[] = '<' . $v . '>';
175
+		foreach ($this->parameters as $v)
176
+			$params[] = '<'.$v.'>';
177 177
 		$parameters = implode($params, ' ');
178 178
 		$options = [];
179
-		foreach($this->optional as $v)
180
-			$options[] = '[' . $v . ']';
181
-		$optional = (strlen($parameters) ? ' ' : '') . implode($options, ' ');
179
+		foreach ($this->optional as $v)
180
+			$options[] = '['.$v.']';
181
+		$optional = (strlen($parameters) ? ' ' : '').implode($options, ' ');
182 182
 		$description = '';
183
-		foreach(explode("\n", wordwrap($this->description, 65)) as $line)
184
-			$description .= '    ' . $line . "\n";
183
+		foreach (explode("\n", wordwrap($this->description, 65)) as $line)
184
+			$description .= '    '.$line."\n";
185 185
 		return <<<EOD
186 186
   {$this->action} {$parameters}{$optional}
187 187
 {$description}
@@ -191,17 +191,17 @@  discard block
 block discarded – undo
191 191
 
192 192
 	protected function initializePradoApplication($directory)
193 193
 	{
194
-		$_SERVER['SCRIPT_FILENAME'] = $directory . '/index.php';
195
-		$app_dir = realpath($directory . '/protected/');
196
-		if($app_dir !== false && is_dir($app_dir))
194
+		$_SERVER['SCRIPT_FILENAME'] = $directory.'/index.php';
195
+		$app_dir = realpath($directory.'/protected/');
196
+		if ($app_dir !== false && is_dir($app_dir))
197 197
 		{
198
-			if(Prado::getApplication() === null)
198
+			if (Prado::getApplication() === null)
199 199
 			{
200 200
 				$app = new PradoShellApplication($app_dir);
201 201
 				$app->run();
202 202
 				$dir = substr(str_replace(realpath('./'), '', $app_dir), 1);
203 203
 				PradoCommandLineInterpreter::printGreeting();
204
-				echo '** Loaded PRADO appplication in directory "' . $dir . "\".\n";
204
+				echo '** Loaded PRADO appplication in directory "'.$dir."\".\n";
205 205
 			}
206 206
 
207 207
 			return Prado::getApplication();
@@ -209,9 +209,9 @@  discard block
 block discarded – undo
209 209
 		else
210 210
 		{
211 211
 			PradoCommandLineInterpreter::printGreeting();
212
-			echo '+' . str_repeat('-', 77) . "+\n";
213
-			echo '** Unable to load PRADO application in directory "' . $directory . "\".\n";
214
-			echo '+' . str_repeat('-', 77) . "+\n";
212
+			echo '+'.str_repeat('-', 77)."+\n";
213
+			echo '** Unable to load PRADO application in directory "'.$directory."\".\n";
214
+			echo '+'.str_repeat('-', 77)."+\n";
215 215
 		}
216 216
 		return false;
217 217
 	}
@@ -243,25 +243,25 @@  discard block
 block discarded – undo
243 243
 	 */
244 244
 	protected function createNewPradoProject($dir)
245 245
 	{
246
-		if(strlen(trim($dir)) == 0)
246
+		if (strlen(trim($dir)) == 0)
247 247
 			return;
248 248
 
249 249
 		$rootPath = realpath(dirname(trim($dir)));
250 250
 
251
-		if(basename($dir) !== '.')
252
-			$basePath = $rootPath . DIRECTORY_SEPARATOR . basename($dir);
251
+		if (basename($dir) !== '.')
252
+			$basePath = $rootPath.DIRECTORY_SEPARATOR.basename($dir);
253 253
 		else
254 254
 			$basePath = $rootPath;
255 255
 		$appName = basename($basePath);
256
-		$assetPath = $basePath . DIRECTORY_SEPARATOR . 'assets';
257
-		$protectedPath = $basePath . DIRECTORY_SEPARATOR . 'protected';
258
-		$runtimePath = $basePath . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'runtime';
259
-		$pagesPath = $protectedPath . DIRECTORY_SEPARATOR . 'pages';
256
+		$assetPath = $basePath.DIRECTORY_SEPARATOR.'assets';
257
+		$protectedPath = $basePath.DIRECTORY_SEPARATOR.'protected';
258
+		$runtimePath = $basePath.DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.'runtime';
259
+		$pagesPath = $protectedPath.DIRECTORY_SEPARATOR.'pages';
260 260
 
261
-		$indexFile = $basePath . DIRECTORY_SEPARATOR . 'index.php';
262
-		$htaccessFile = $protectedPath . DIRECTORY_SEPARATOR . '.htaccess';
263
-		$configFile = $protectedPath . DIRECTORY_SEPARATOR . 'application.xml';
264
-		$defaultPageFile = $pagesPath . DIRECTORY_SEPARATOR . 'Home.page';
261
+		$indexFile = $basePath.DIRECTORY_SEPARATOR.'index.php';
262
+		$htaccessFile = $protectedPath.DIRECTORY_SEPARATOR.'.htaccess';
263
+		$configFile = $protectedPath.DIRECTORY_SEPARATOR.'application.xml';
264
+		$defaultPageFile = $pagesPath.DIRECTORY_SEPARATOR.'Home.page';
265 265
 
266 266
 		$this->createDirectory($basePath, 0755);
267 267
 		$this->createDirectory($assetPath, 0777);
@@ -277,10 +277,10 @@  discard block
 block discarded – undo
277 277
 
278 278
 	protected function renderIndexFile()
279 279
 	{
280
-		$framework = realpath(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'prado.php';
280
+		$framework = realpath(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR.'prado.php';
281 281
 return '<?php
282 282
 
283
-$frameworkPath=\'' . $framework . '\';
283
+$frameworkPath=\'' . $framework.'\';
284 284
 
285 285
 // The following directory checks may be removed if performance is required
286 286
 $basePath=dirname(__FILE__);
@@ -390,22 +390,22 @@  discard block
 block discarded – undo
390 390
 
391 391
 	protected function createTestFixtures($dir)
392 392
 	{
393
-		if(strlen(trim($dir)) == 0)
393
+		if (strlen(trim($dir)) == 0)
394 394
 			return;
395 395
 
396 396
 		$rootPath = realpath(dirname(trim($dir)));
397
-		$basePath = $rootPath . '/' . basename($dir);
397
+		$basePath = $rootPath.'/'.basename($dir);
398 398
 
399
-		$tests = $basePath . '/tests';
400
-		$unit_tests = $tests . '/unit';
401
-		$functional_tests = $tests . '/functional';
399
+		$tests = $basePath.'/tests';
400
+		$unit_tests = $tests.'/unit';
401
+		$functional_tests = $tests.'/functional';
402 402
 
403 403
 		$this->createDirectory($tests, 0755);
404 404
 		$this->createDirectory($unit_tests, 0755);
405 405
 		$this->createDirectory($functional_tests, 0755);
406 406
 
407
-		$unit_test_index = $tests . '/unit.php';
408
-		$functional_test_index = $tests . '/functional.php';
407
+		$unit_test_index = $tests.'/unit.php';
408
+		$functional_test_index = $tests.'/functional.php';
409 409
 
410 410
 		$this->createFile($unit_test_index, $this->renderUnitTestFixture());
411 411
 		$this->createFile($functional_test_index, $this->renderFunctionalTestFixture());
@@ -413,10 +413,10 @@  discard block
 block discarded – undo
413 413
 
414 414
 	protected function renderUnitTestFixture()
415 415
 	{
416
-		$tester = realpath(dirname(dirname(__FILE__))) . '/tests/test_tools/unit_tests.php';
416
+		$tester = realpath(dirname(dirname(__FILE__))).'/tests/test_tools/unit_tests.php';
417 417
 return '<?php
418 418
 
419
-include_once \'' . $tester . '\';
419
+include_once \'' . $tester.'\';
420 420
 
421 421
 $app_directory = "../protected";
422 422
 $test_cases = dirname(__FILE__)."/unit";
@@ -428,10 +428,10 @@  discard block
 block discarded – undo
428 428
 
429 429
 	protected function renderFunctionalTestFixture()
430 430
 	{
431
-		$tester = realpath(dirname(dirname(__FILE__))) . '/tests/test_tools/functional_tests.php';
431
+		$tester = realpath(dirname(dirname(__FILE__))).'/tests/test_tools/functional_tests.php';
432 432
 return '<?php
433 433
 
434
-include_once \'' . $tester . '\';
434
+include_once \'' . $tester.'\';
435 435
 
436 436
 $test_cases = dirname(__FILE__)."/functional";
437 437
 
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 
458 458
 	public function performAction($args)
459 459
 	{
460
-		if(count($args) > 1)
460
+		if (count($args) > 1)
461 461
 			$this->initializePradoApplication($args[1]);
462 462
 
463 463
 		\Psy\debug([], Prado::getApplication());
@@ -483,13 +483,13 @@  discard block
 block discarded – undo
483 483
 	{
484 484
 		$app_dir = count($args) > 3 ? $this->getAppDir($args[3]) : $this->getAppDir();
485 485
 		$this->_soap = count($args) > 4;
486
-		if($app_dir !== false)
486
+		if ($app_dir !== false)
487 487
 		{
488 488
 			$config = $this->getActiveRecordConfig($app_dir);
489 489
 			$output = $this->getOutputFile($app_dir, $args[2]);
490
-			if(is_file($output))
490
+			if (is_file($output))
491 491
 				echo "** File $output already exists, skiping. \n";
492
-			elseif($config !== false && $output !== false)
492
+			elseif ($config !== false && $output !== false)
493 493
 				$this->generateActiveRecord($config, $args[1], $output);
494 494
 		}
495 495
 		return true;
@@ -497,68 +497,68 @@  discard block
 block discarded – undo
497 497
 
498 498
 	protected function getAppDir($dir = ".")
499 499
 	{
500
-		if(is_dir($dir))
500
+		if (is_dir($dir))
501 501
 			return realpath($dir);
502
-		if(false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir))
502
+		if (false !== ($app_dir = realpath($dir.'/protected/')) && is_dir($app_dir))
503 503
 			return $app_dir;
504
-		echo '** Unable to find directory "' . $dir . "\".\n";
504
+		echo '** Unable to find directory "'.$dir."\".\n";
505 505
 		return false;
506 506
 	}
507 507
 
508 508
 	protected function getXmlFile($app_dir)
509 509
 	{
510
-		if(false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml))
510
+		if (false !== ($xml = realpath($app_dir.'/application.xml')) && is_file($xml))
511 511
 			return $xml;
512
-		if(false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml))
512
+		if (false !== ($xml = realpath($app_dir.'/protected/application.xml')) && is_file($xml))
513 513
 			return $xml;
514
-		echo '** Unable to find application.xml in ' . $app_dir . "\n";
514
+		echo '** Unable to find application.xml in '.$app_dir."\n";
515 515
 		return false;
516 516
 	}
517 517
 
518 518
 	protected function getActiveRecordConfig($app_dir)
519 519
 	{
520
-		if(false === ($xml = $this->getXmlFile($app_dir)))
520
+		if (false === ($xml = $this->getXmlFile($app_dir)))
521 521
 			return false;
522
-		if(false !== ($app = $this->initializePradoApplication($app_dir)))
522
+		if (false !== ($app = $this->initializePradoApplication($app_dir)))
523 523
 		{
524 524
 			Prado::using('System.Data.ActiveRecord.TActiveRecordConfig');
525
-			foreach($app->getModules() as $module)
526
-				if($module instanceof TActiveRecordConfig)
525
+			foreach ($app->getModules() as $module)
526
+				if ($module instanceof TActiveRecordConfig)
527 527
 					return $module;
528
-			echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n";
528
+			echo '** Unable to find TActiveRecordConfig module in '.$xml."\n";
529 529
 		}
530 530
 		return false;
531 531
 	}
532 532
 
533 533
 	protected function getOutputFile($app_dir, $namespace)
534 534
 	{
535
-		if(is_file($namespace) && strpos($namespace, $app_dir) === 0)
535
+		if (is_file($namespace) && strpos($namespace, $app_dir) === 0)
536 536
 				return $namespace;
537 537
 		$file = Prado::getPathOfNamespace($namespace, ".php");
538
-		if($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path))
538
+		if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path))
539 539
 		{
540
-			if(strpos($path, $app_dir) === 0)
540
+			if (strpos($path, $app_dir) === 0)
541 541
 				return $file;
542 542
 		}
543
-		echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n";
543
+		echo '** Output file '.$file.' must be within directory '.$app_dir."\n";
544 544
 		return false;
545 545
 	}
546 546
 
547 547
 	protected function generateActiveRecord($config, $tablename, $output)
548 548
 	{
549 549
 		$manager = TActiveRecordManager::getInstance();
550
-		if($manager->getDbConnection()) {
550
+		if ($manager->getDbConnection()) {
551 551
 			$gateway = $manager->getRecordGateway();
552 552
 			$tableInfo = $gateway->getTableInfo($manager->getDbConnection(), $tablename);
553
-			if(count($tableInfo->getColumns()) === 0)
553
+			if (count($tableInfo->getColumns()) === 0)
554 554
 			{
555
-				echo '** Unable to find table or view "' . $tablename . '" in "' . $manager->getDbConnection()->getConnectionString() . "\".\n";
555
+				echo '** Unable to find table or view "'.$tablename.'" in "'.$manager->getDbConnection()->getConnectionString()."\".\n";
556 556
 				return false;
557 557
 			}
558 558
 			else
559 559
 			{
560 560
 				$properties = [];
561
-				foreach($tableInfo->getColumns() as $field => $column)
561
+				foreach ($tableInfo->getColumns() as $field => $column)
562 562
 					$properties[] = $this->generateProperty($field, $column);
563 563
 			}
564 564
 
@@ -567,16 +567,16 @@  discard block
 block discarded – undo
567 567
 			echo "  Writing class $classname to file $output\n";
568 568
 			file_put_contents($output, $class);
569 569
 		} else {
570
-			echo '** Unable to connect to database with ConnectionID=\'' . $config->getConnectionID() . "'. Please check your settings in application.xml and ensure your database connection is set up first.\n";
570
+			echo '** Unable to connect to database with ConnectionID=\''.$config->getConnectionID()."'. Please check your settings in application.xml and ensure your database connection is set up first.\n";
571 571
 		}
572 572
 	}
573 573
 
574 574
 	protected function generateProperty($field, $column)
575 575
 	{
576 576
 		$prop = '';
577
-		$name = '$' . $field;
577
+		$name = '$'.$field;
578 578
 		$type = $column->getPHPType();
579
-		if($this->_soap)
579
+		if ($this->_soap)
580 580
 		{
581 581
 			$prop .= <<<EOD
582 582
 
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 			$con = $manager->getDbConnection();
649 649
 			$con->Active = true;
650 650
 
651
-			switch($con->getDriverName())
651
+			switch ($con->getDriverName())
652 652
 			   {
653 653
 				case 'mysqli':
654 654
 				case 'mysql':
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
 				case 'oci':
666 666
 //				case 'ibm':
667 667
 				default:
668
-					echo "\n    Sorry, generateAll is not implemented for " . $con->getDriverName() . "\n";
668
+					echo "\n    Sorry, generateAll is not implemented for ".$con->getDriverName()."\n";
669 669
 					
670 670
 			   }
671 671
 
@@ -677,9 +677,9 @@  discard block
 block discarded – undo
677 677
 			}
678 678
 			$con->Active = false;
679 679
 			foreach ($tables as $key => $table) {
680
-				$output = $args[1] . "." . $this->_prefix . ucfirst($table) . $this->_postfix;
680
+				$output = $args[1].".".$this->_prefix.ucfirst($table).$this->_postfix;
681 681
 				if ($config !== false && $output !== false) {
682
-					$this->generate("generate " . $table . " " . $output . " " . $this->_soap . " " . $this->_overwrite);
682
+					$this->generate("generate ".$table." ".$output." ".$this->_soap." ".$this->_overwrite);
683 683
 				}
684 684
 			}
685 685
 		}
@@ -689,14 +689,14 @@  discard block
 block discarded – undo
689 689
 	public function generate($l)
690 690
 	{
691 691
 		$input = explode(" ", trim($l));
692
-		if(count($input) > 2)
692
+		if (count($input) > 2)
693 693
 		{
694 694
 			$app_dir = '.';
695
-			if(Prado::getApplication() !== null)
695
+			if (Prado::getApplication() !== null)
696 696
 				$app_dir = dirname(Prado::getApplication()->getBasePath());
697
-			$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'];
697
+			$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'];
700 700
 			$cmd = new PradoCommandLineActiveRecordGen;
701 701
 			$cmd->performAction($args);
702 702
 		}
@@ -709,18 +709,18 @@  discard block
 block discarded – undo
709 709
 	protected function getAppDir($dir = ".") {
710 710
 		if (is_dir($dir))
711 711
 			return realpath($dir);
712
-		if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir))
712
+		if (false !== ($app_dir = realpath($dir.'/protected/')) && is_dir($app_dir))
713 713
 			return $app_dir;
714
-		echo '** Unable to find directory "' . $dir . "\".\n";
714
+		echo '** Unable to find directory "'.$dir."\".\n";
715 715
 		return false;
716 716
 	}
717 717
 
718 718
 	protected function getXmlFile($app_dir) {
719
-		if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml))
719
+		if (false !== ($xml = realpath($app_dir.'/application.xml')) && is_file($xml))
720 720
 			return $xml;
721
-		if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml))
721
+		if (false !== ($xml = realpath($app_dir.'/protected/application.xml')) && is_file($xml))
722 722
 			return $xml;
723
-		echo '** Unable to find application.xml in ' . $app_dir . "\n";
723
+		echo '** Unable to find application.xml in '.$app_dir."\n";
724 724
 		return false;
725 725
 	}
726 726
 
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
 			foreach ($app->getModules() as $module)
733 733
 				if ($module instanceof TActiveRecordConfig)
734 734
 					return $module;
735
-			echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n";
735
+			echo '** Unable to find TActiveRecordConfig module in '.$xml."\n";
736 736
 		}
737 737
 		return false;
738 738
 	}
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
 			if (strpos($path, $app_dir) === 0)
746 746
 				return $file;
747 747
 		}
748
-		echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n";
748
+		echo '** Output file '.$file.' must be within directory '.$app_dir."\n";
749 749
 		return false;
750 750
 	}
751 751
 
Please login to merge, or discard this patch.
Braces   +106 added lines, -77 removed lines patch added patch discarded remove patch
@@ -9,8 +9,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
framework/TApplication.php 2 patches
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -300,13 +300,13 @@  discard block
 block discarded – undo
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
 		// generates unique ID by hashing the runtime path
307 307
 		$this->_uniqueID = md5($this->_runtimePath);
308 308
 		$this->_parameters = new \Prado\Collections\TMap;
309
-		$this->_services = [$this->getPageServiceID() => ['TPageService',[],null]];
309
+		$this->_services = [$this->getPageServiceID() => ['TPageService', [], null]];
310 310
 
311 311
 		Prado::setPathOfAlias('Application', $this->_basePath);
312 312
 	}
@@ -324,11 +324,11 @@  discard block
 block discarded – undo
324 324
 	protected function resolvePaths($basePath)
325 325
 	{
326 326
 		// determine configuration path and file
327
-		if(empty($basePath) || ($basePath = realpath($basePath)) === false)
327
+		if (empty($basePath) || ($basePath = realpath($basePath)) === false)
328 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))
329
+		if (is_dir($basePath) && is_file($basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName()))
330
+			$configFile = $basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName();
331
+		elseif (is_file($basePath))
332 332
 		{
333 333
 			$configFile = $basePath;
334 334
 			$basePath = dirname($configFile);
@@ -337,15 +337,15 @@  discard block
 block discarded – undo
337 337
 			$configFile = null;
338 338
 
339 339
 		// determine runtime path
340
-		$runtimePath = $basePath . DIRECTORY_SEPARATOR . self::RUNTIME_PATH;
341
-		if(is_writable($runtimePath))
340
+		$runtimePath = $basePath.DIRECTORY_SEPARATOR.self::RUNTIME_PATH;
341
+		if (is_writable($runtimePath))
342 342
 		{
343
-			if($configFile !== null)
343
+			if ($configFile !== null)
344 344
 			{
345
-				$runtimePath .= DIRECTORY_SEPARATOR . basename($configFile) . '-' . Prado::getVersion();
346
-				if(!is_dir($runtimePath))
345
+				$runtimePath .= DIRECTORY_SEPARATOR.basename($configFile).'-'.Prado::getVersion();
346
+				if (!is_dir($runtimePath))
347 347
 				{
348
-					if(@mkdir($runtimePath) === false)
348
+					if (@mkdir($runtimePath) === false)
349 349
 						throw new TConfigurationException('application_runtimepath_failed', $runtimePath);
350 350
 					@chmod($runtimePath, PRADO_CHMOD); //make it deletable
351 351
 				}
@@ -372,11 +372,11 @@  discard block
 block discarded – undo
372 372
 			$n = count(self::$_steps);
373 373
 			$this->_step = 0;
374 374
 			$this->_requestCompleted = false;
375
-			while($this->_step < $n)
375
+			while ($this->_step < $n)
376 376
 			{
377
-				if($this->_mode === TApplicationMode::Off)
377
+				if ($this->_mode === TApplicationMode::Off)
378 378
 					throw new THttpException(503, 'application_unavailable');
379
-				if($this->_requestCompleted)
379
+				if ($this->_requestCompleted)
380 380
 					break;
381 381
 				$method = self::$_steps[$this->_step];
382 382
 				Prado::trace("Executing $method()", 'Prado\TApplication');
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 				$this->_step++;
385 385
 			}
386 386
 		}
387
-		catch(\Exception $e)
387
+		catch (\Exception $e)
388 388
 		{
389 389
 			$this->onError($e);
390 390
 		}
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 */
420 420
 	public function getGlobalState($key, $defaultValue = null)
421 421
 	{
422
-		return isset($this->_globals[$key])?$this->_globals[$key]:$defaultValue;
422
+		return isset($this->_globals[$key]) ? $this->_globals[$key] : $defaultValue;
423 423
 	}
424 424
 
425 425
 	/**
@@ -435,11 +435,11 @@  discard block
 block discarded – undo
435 435
 	public function setGlobalState($key, $value, $defaultValue = null, $forceSave = false)
436 436
 	{
437 437
 		$this->_stateChanged = true;
438
-		if($value === $defaultValue)
438
+		if ($value === $defaultValue)
439 439
 			unset($this->_globals[$key]);
440 440
 		else
441 441
 			$this->_globals[$key] = $value;
442
-		if($forceSave)
442
+		if ($forceSave)
443 443
 			$this->saveGlobals();
444 444
 	}
445 445
 
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 	 */
473 473
 	protected function saveGlobals()
474 474
 	{
475
-		if($this->_stateChanged)
475
+		if ($this->_stateChanged)
476 476
 		{
477 477
 			$this->_stateChanged = false;
478 478
 			$this->getApplicationStatePersister()->save($this->_globals);
@@ -588,9 +588,9 @@  discard block
 block discarded – undo
588 588
 	 */
589 589
 	public function getConfigurationFileExt()
590 590
 	{
591
-		if($this->_configFileExt === null)
591
+		if ($this->_configFileExt === null)
592 592
 		{
593
-			switch($this->_configType)
593
+			switch ($this->_configType)
594 594
 			{
595 595
 				case TApplication::CONFIG_TYPE_PHP:
596 596
 					$this->_configFileExt = TApplication::CONFIG_FILE_EXT_PHP;
@@ -608,9 +608,9 @@  discard block
 block discarded – undo
608 608
 	public function getConfigurationFileName()
609 609
 	{
610 610
 		static $fileName;
611
-		if($fileName == null)
611
+		if ($fileName == null)
612 612
 		{
613
-			switch($this->_configType)
613
+			switch ($this->_configType)
614 614
 			{
615 615
 				case TApplication::CONFIG_TYPE_PHP:
616 616
 					$fileName = TApplication::CONFIG_FILE_PHP;
@@ -636,8 +636,8 @@  discard block
 block discarded – undo
636 636
 	public function setRuntimePath($value)
637 637
 	{
638 638
 		$this->_runtimePath = $value;
639
-		if($this->_cacheFile)
640
-			$this->_cacheFile = $this->_runtimePath . DIRECTORY_SEPARATOR . self::CONFIGCACHE_FILE;
639
+		if ($this->_cacheFile)
640
+			$this->_cacheFile = $this->_runtimePath.DIRECTORY_SEPARATOR.self::CONFIGCACHE_FILE;
641 641
 		// generates unique ID by hashing the runtime path
642 642
 		$this->_uniqueID = md5($this->_runtimePath);
643 643
 	}
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 	 */
667 667
 	public function setModule($id, IModule $module = null)
668 668
 	{
669
-		if(isset($this->_modules[$id]))
669
+		if (isset($this->_modules[$id]))
670 670
 			throw new TConfigurationException('application_moduleid_duplicated', $id);
671 671
 		else
672 672
 			$this->_modules[$id] = $module;
@@ -677,11 +677,11 @@  discard block
 block discarded – undo
677 677
 	 */
678 678
 	public function getModule($id)
679 679
 	{
680
-		if(!array_key_exists($id, $this->_modules))
680
+		if (!array_key_exists($id, $this->_modules))
681 681
 			return null;
682 682
 
683 683
 		// force loading of a lazy module
684
-		if($this->_modules[$id] === null)
684
+		if ($this->_modules[$id] === null)
685 685
 		{
686 686
 			$module = $this->internalLoadModule($id, true);
687 687
 			$module[0]->init($module[1]);
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 	 */
717 717
 	public function getRequest()
718 718
 	{
719
-		if(!$this->_request)
719
+		if (!$this->_request)
720 720
 		{
721 721
 			$this->_request = new \Prado\Web\THttpRequest;
722 722
 			$this->_request->init(null);
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
 	 */
738 738
 	public function getResponse()
739 739
 	{
740
-		if(!$this->_response)
740
+		if (!$this->_response)
741 741
 		{
742 742
 			$this->_response = new THttpResponse;
743 743
 			$this->_response->init(null);
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 	 */
759 759
 	public function getSession()
760 760
 	{
761
-		if(!$this->_session)
761
+		if (!$this->_session)
762 762
 		{
763 763
 			$this->_session = new THttpSession;
764 764
 			$this->_session->init(null);
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 	 */
780 780
 	public function getErrorHandler()
781 781
 	{
782
-		if(!$this->_errorHandler)
782
+		if (!$this->_errorHandler)
783 783
 		{
784 784
 			$this->_errorHandler = new TErrorHandler;
785 785
 			$this->_errorHandler->init(null);
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 	 */
801 801
 	public function getSecurityManager()
802 802
 	{
803
-		if(!$this->_security)
803
+		if (!$this->_security)
804 804
 		{
805 805
 			$this->_security = new TSecurityManager;
806 806
 			$this->_security->init(null);
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 	 */
822 822
 	public function getAssetManager()
823 823
 	{
824
-		if(!$this->_assetManager)
824
+		if (!$this->_assetManager)
825 825
 		{
826 826
 			$this->_assetManager = new TAssetManager;
827 827
 			$this->_assetManager->init(null);
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 	 */
843 843
 	public function getApplicationStatePersister()
844 844
 	{
845
-		if(!$this->_statePersister)
845
+		if (!$this->_statePersister)
846 846
 		{
847 847
 			$this->_statePersister = new TApplicationStatePersister;
848 848
 			$this->_statePersister->init(null);
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
 	 */
897 897
 	public function getGlobalization($createIfNotExists = true)
898 898
 	{
899
-		if($this->_globalization === null && $createIfNotExists)
899
+		if ($this->_globalization === null && $createIfNotExists)
900 900
 		{
901 901
 			$this->_globalization = new TGlobalization;
902 902
 			$this->_globalization->init(null);
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
 	 */
918 918
 	public function getAuthorizationRules()
919 919
 	{
920
-		if($this->_authRules === null)
920
+		if ($this->_authRules === null)
921 921
 			$this->_authRules = new \Prado\Security\TAuthorizationRuleCollection;
922 922
 		return $this->_authRules;
923 923
 	}
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
 	protected function internalLoadModule($id, $force = false)
931 931
 	{
932 932
 		list($moduleClass, $initProperties, $configElement) = $this->_lazyModules[$id];
933
-		if(isset($initProperties['lazy']) && $initProperties['lazy'] && !$force)
933
+		if (isset($initProperties['lazy']) && $initProperties['lazy'] && !$force)
934 934
 		{
935 935
 			Prado::trace("Postponed loading of lazy module $id ({$moduleClass})", '\Prado\TApplication');
936 936
 			$this->setModule($id, null);
@@ -939,16 +939,16 @@  discard block
 block discarded – undo
939 939
 
940 940
 		Prado::trace("Loading module $id ({$moduleClass})", '\Prado\TApplication');
941 941
 		$module = Prado::createComponent($moduleClass);
942
-		foreach($initProperties as $name => $value)
942
+		foreach ($initProperties as $name => $value)
943 943
 		{
944
-			if($name === 'lazy') continue;
944
+			if ($name === 'lazy') continue;
945 945
 			$module->setSubProperty($name, $value);
946 946
 		}
947 947
 		$this->setModule($id, $module);
948 948
 		// keep the key to avoid reuse of the old module id
949 949
 		$this->_lazyModules[$id] = null;
950 950
 
951
-		return [$module,$configElement];
951
+		return [$module, $configElement];
952 952
 	}
953 953
 	/**
954 954
 	 * Applies an application configuration.
@@ -957,32 +957,32 @@  discard block
 block discarded – undo
957 957
 	 */
958 958
 	public function applyConfiguration($config, $withinService = false)
959 959
 	{
960
-		if($config->getIsEmpty())
960
+		if ($config->getIsEmpty())
961 961
 			return;
962 962
 
963 963
 		// set path aliases and using namespaces
964
-		foreach($config->getAliases() as $alias => $path)
964
+		foreach ($config->getAliases() as $alias => $path)
965 965
 			Prado::setPathOfAlias($alias, $path);
966
-		foreach($config->getUsings() as $using)
966
+		foreach ($config->getUsings() as $using)
967 967
 			Prado::using($using);
968 968
 
969 969
 		// set application properties
970
-		if(!$withinService)
970
+		if (!$withinService)
971 971
 		{
972
-			foreach($config->getProperties() as $name => $value)
972
+			foreach ($config->getProperties() as $name => $value)
973 973
 				$this->setSubProperty($name, $value);
974 974
 		}
975 975
 
976
-		if(empty($this->_services))
977
-			$this->_services = [$this->getPageServiceID() => ['Prado\Web\Services\TPageService',[],null]];
976
+		if (empty($this->_services))
977
+			$this->_services = [$this->getPageServiceID() => ['Prado\Web\Services\TPageService', [], null]];
978 978
 
979 979
 		// load parameters
980
-		foreach($config->getParameters() as $id => $parameter)
980
+		foreach ($config->getParameters() as $id => $parameter)
981 981
 		{
982
-			if(is_array($parameter))
982
+			if (is_array($parameter))
983 983
 			{
984 984
 				$component = Prado::createComponent($parameter[0]);
985
-				foreach($parameter[1] as $name => $value)
985
+				foreach ($parameter[1] as $name => $value)
986 986
 					$component->setSubProperty($name, $value);
987 987
 				$this->_parameters->add($id, $component);
988 988
 			}
@@ -992,29 +992,29 @@  discard block
 block discarded – undo
992 992
 
993 993
 		// load and init modules specified in app config
994 994
 		$modules = [];
995
-		foreach($config->getModules() as $id => $moduleConfig)
995
+		foreach ($config->getModules() as $id => $moduleConfig)
996 996
 		{
997
-			if(!is_string($id))
998
-				$id = '_module' . count($this->_lazyModules);
997
+			if (!is_string($id))
998
+				$id = '_module'.count($this->_lazyModules);
999 999
 			$this->_lazyModules[$id] = $moduleConfig;
1000
-			if($module = $this->internalLoadModule($id))
1000
+			if ($module = $this->internalLoadModule($id))
1001 1001
 				$modules[] = $module;
1002 1002
 		}
1003
-		foreach($modules as $module)
1003
+		foreach ($modules as $module)
1004 1004
 			$module[0]->init($module[1]);
1005 1005
 
1006 1006
 		// load service
1007
-		foreach($config->getServices() as $serviceID => $serviceConfig)
1007
+		foreach ($config->getServices() as $serviceID => $serviceConfig)
1008 1008
 			$this->_services[$serviceID] = $serviceConfig;
1009 1009
 
1010 1010
 		// external configurations
1011
-		foreach($config->getExternalConfigurations() as $filePath => $condition)
1011
+		foreach ($config->getExternalConfigurations() as $filePath => $condition)
1012 1012
 		{
1013
-			if($condition !== true)
1013
+			if ($condition !== true)
1014 1014
 				$condition = $this->evaluateExpression($condition);
1015
-			if($condition)
1015
+			if ($condition)
1016 1016
 			{
1017
-				if(($path = Prado::getPathOfNamespace($filePath, $this->getConfigurationFileExt())) === null || !is_file($path))
1017
+				if (($path = Prado::getPathOfNamespace($filePath, $this->getConfigurationFileExt())) === null || !is_file($path))
1018 1018
 					throw new TConfigurationException('application_includefile_invalid', $filePath);
1019 1019
 				$cn = $this->getApplicationConfigurationClass();
1020 1020
 				$c = new $cn;
@@ -1037,13 +1037,13 @@  discard block
 block discarded – undo
1037 1037
 	{
1038 1038
 		Prado::trace('Initializing application', 'Prado\TApplication');
1039 1039
 
1040
-		if($this->_configFile !== null)
1040
+		if ($this->_configFile !== null)
1041 1041
 		{
1042
-			if($this->_cacheFile === null || @filemtime($this->_cacheFile) < filemtime($this->_configFile))
1042
+			if ($this->_cacheFile === null || @filemtime($this->_cacheFile) < filemtime($this->_configFile))
1043 1043
 			{
1044 1044
 				$config = new TApplicationConfiguration;
1045 1045
 				$config->loadFromFile($this->_configFile);
1046
-				if($this->_cacheFile !== null)
1046
+				if ($this->_cacheFile !== null)
1047 1047
 					file_put_contents($this->_cacheFile, serialize($config), LOCK_EX);
1048 1048
 			}
1049 1049
 			else
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
 			$this->applyConfiguration($config, false);
1053 1053
 		}
1054 1054
 
1055
-		if(($serviceID = $this->getRequest()->resolveRequest(array_keys($this->_services))) === null)
1055
+		if (($serviceID = $this->getRequest()->resolveRequest(array_keys($this->_services))) === null)
1056 1056
 			$serviceID = $this->getPageServiceID();
1057 1057
 
1058 1058
 		$this->startService($serviceID);
@@ -1066,24 +1066,24 @@  discard block
 block discarded – undo
1066 1066
 	 */
1067 1067
 	public function startService($serviceID)
1068 1068
 	{
1069
-		if(isset($this->_services[$serviceID]))
1069
+		if (isset($this->_services[$serviceID]))
1070 1070
 		{
1071 1071
 			list($serviceClass, $initProperties, $configElement) = $this->_services[$serviceID];
1072 1072
 			$service = Prado::createComponent($serviceClass);
1073
-			if(!($service instanceof IService))
1073
+			if (!($service instanceof IService))
1074 1074
 				throw new THttpException(500, 'application_service_invalid', $serviceClass);
1075
-			if(!$service->getEnabled())
1075
+			if (!$service->getEnabled())
1076 1076
 				throw new THttpException(500, 'application_service_unavailable', $serviceClass);
1077 1077
 			$service->setID($serviceID);
1078 1078
 			$this->setService($service);
1079 1079
 
1080
-			foreach($initProperties as $name => $value)
1080
+			foreach ($initProperties as $name => $value)
1081 1081
 				$service->setSubProperty($name, $value);
1082 1082
 
1083
-			if($configElement !== null)
1083
+			if ($configElement !== null)
1084 1084
 			{
1085 1085
 				$config = new TApplicationConfiguration;
1086
-				if($this->getConfigurationType() == self::CONFIG_TYPE_PHP)
1086
+				if ($this->getConfigurationType() == self::CONFIG_TYPE_PHP)
1087 1087
 					$config->loadFromPhp($configElement, $this->getBasePath());
1088 1088
 				else
1089 1089
 					$config->loadFromXml($configElement, $this->getBasePath());
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 	 */
1191 1191
 	public function runService()
1192 1192
 	{
1193
-		if($this->_service)
1193
+		if ($this->_service)
1194 1194
 			$this->_service->run();
1195 1195
 	}
1196 1196
 
@@ -1238,7 +1238,7 @@  discard block
 block discarded – undo
1238 1238
 	public function onEndRequest()
1239 1239
 	{
1240 1240
 		$this->flushOutput(false); // flush all remaining content in the buffer
1241
-		$this->saveGlobals();  // save global state
1241
+		$this->saveGlobals(); // save global state
1242 1242
 		$this->raiseEvent('OnEndRequest', $this, null);
1243 1243
 	}
1244 1244
 }
Please login to merge, or discard this patch.
Braces   +113 added lines, -82 removed lines patch added patch discarded remove patch
@@ -300,8 +300,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	/**
Please login to merge, or discard this patch.
framework/Security/TUserManager.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 	public function init($config)
112 112
 	{
113 113
 		$this->loadUserData($config);
114
-		if($this->_userFile !== null)
114
+		if ($this->_userFile !== null)
115 115
 		{
116
-			if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP)
116
+			if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP)
117 117
 			{
118 118
 				$userFile = include $this->_userFile;
119 119
 				$this->loadUserDataFromPhp($userFile);
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 */
135 135
 	private function loadUserData($config)
136 136
 	{
137
-		if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP)
137
+		if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP)
138 138
 			$this->loadUserDataFromPhp($config);
139 139
 		else
140 140
 			$this->loadUserDataFromXml($config);
@@ -146,33 +146,33 @@  discard block
 block discarded – undo
146 146
 	 */
147 147
 	private function loadUserDataFromPhp($config)
148 148
 	{
149
-		if(isset($config['users']) && is_array($config['users']))
149
+		if (isset($config['users']) && is_array($config['users']))
150 150
 		{
151
-			foreach($config['users'] as $user)
151
+			foreach ($config['users'] as $user)
152 152
 			{
153
-				$name = trim(strtolower(isset($user['name'])?$user['name']:''));
154
-				$password = isset($user['password'])?$user['password']:'';
153
+				$name = trim(strtolower(isset($user['name']) ? $user['name'] : ''));
154
+				$password = isset($user['password']) ? $user['password'] : '';
155 155
 				$this->_users[$name] = $password;
156
-				$roles = isset($user['roles'])?$user['roles']:'';
157
-				if($roles !== '')
156
+				$roles = isset($user['roles']) ? $user['roles'] : '';
157
+				if ($roles !== '')
158 158
 				{
159
-					foreach(explode(',', $roles) as $role)
159
+					foreach (explode(',', $roles) as $role)
160 160
 					{
161
-						if(($role = trim($role)) !== '')
161
+						if (($role = trim($role)) !== '')
162 162
 							$this->_roles[$name][] = $role;
163 163
 					}
164 164
 				}
165 165
 			}
166 166
 		}
167
-		if(isset($config['roles']) && is_array($config['roles']))
167
+		if (isset($config['roles']) && is_array($config['roles']))
168 168
 		{
169
-			foreach($config['roles'] as $role)
169
+			foreach ($config['roles'] as $role)
170 170
 			{
171
-				$name = isset($role['name'])?$role['name']:'';
172
-				$users = isset($role['users'])?$role['users']:'';
173
-				foreach(explode(',', $users) as $user)
171
+				$name = isset($role['name']) ? $role['name'] : '';
172
+				$users = isset($role['users']) ? $role['users'] : '';
173
+				foreach (explode(',', $users) as $user)
174 174
 				{
175
-					if(($user = trim($user)) !== '')
175
+					if (($user = trim($user)) !== '')
176 176
 						$this->_roles[strtolower($user)][] = $name;
177 177
 				}
178 178
 			}
@@ -185,24 +185,24 @@  discard block
 block discarded – undo
185 185
 	 */
186 186
 	private function loadUserDataFromXml($xmlNode)
187 187
 	{
188
-		foreach($xmlNode->getElementsByTagName('user') as $node)
188
+		foreach ($xmlNode->getElementsByTagName('user') as $node)
189 189
 		{
190 190
 			$name = trim(strtolower($node->getAttribute('name')));
191 191
 			$this->_users[$name] = $node->getAttribute('password');
192
-			if(($roles = trim($node->getAttribute('roles'))) !== '')
192
+			if (($roles = trim($node->getAttribute('roles'))) !== '')
193 193
 			{
194
-				foreach(explode(',', $roles) as $role)
194
+				foreach (explode(',', $roles) as $role)
195 195
 				{
196
-					if(($role = trim($role)) !== '')
196
+					if (($role = trim($role)) !== '')
197 197
 						$this->_roles[$name][] = $role;
198 198
 				}
199 199
 			}
200 200
 		}
201
-		foreach($xmlNode->getElementsByTagName('role') as $node)
201
+		foreach ($xmlNode->getElementsByTagName('role') as $node)
202 202
 		{
203
-			foreach(explode(',', $node->getAttribute('users')) as $user)
203
+			foreach (explode(',', $node->getAttribute('users')) as $user)
204 204
 			{
205
-				if(($user = trim($user)) !== '')
205
+				if (($user = trim($user)) !== '')
206 206
 					$this->_roles[strtolower($user)][] = $node->getAttribute('name');
207 207
 			}
208 208
 		}
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
 	 */
249 249
 	public function setUserFile($value)
250 250
 	{
251
-		if($this->_initialized)
251
+		if ($this->_initialized)
252 252
 			throw new TInvalidOperationException('usermanager_userfile_unchangeable');
253
-		elseif(($this->_userFile = Prado::getPathOfNamespace($value, self::USER_FILE_EXT)) === null || !is_file($this->_userFile))
253
+		elseif (($this->_userFile = Prado::getPathOfNamespace($value, self::USER_FILE_EXT)) === null || !is_file($this->_userFile))
254 254
 			throw new TConfigurationException('usermanager_userfile_invalid', $value);
255 255
 	}
256 256
 
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 	 */
295 295
 	public function validateUser($username, $password)
296 296
 	{
297
-		if($this->_passwordMode === TUserManagerPasswordMode::MD5)
297
+		if ($this->_passwordMode === TUserManagerPasswordMode::MD5)
298 298
 			$password = md5($password);
299
-		elseif($this->_passwordMode === TUserManagerPasswordMode::SHA1)
299
+		elseif ($this->_passwordMode === TUserManagerPasswordMode::SHA1)
300 300
 			$password = sha1($password);
301 301
 		$username = strtolower($username);
302 302
 		return (isset($this->_users[$username]) && $this->_users[$username] === $password);
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 */
310 310
 	public function getUser($username = null)
311 311
 	{
312
-		if($username === null)
312
+		if ($username === null)
313 313
 		{
314 314
 			$user = new TUser($this);
315 315
 			$user->setIsGuest(true);
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
 		else
319 319
 		{
320 320
 			$username = strtolower($username);
321
-			if(isset($this->_users[$username]))
321
+			if (isset($this->_users[$username]))
322 322
 			{
323 323
 				$user = new TUser($this);
324 324
 				$user->setName($username);
325 325
 				$user->setIsGuest(false);
326
-				if(isset($this->_roles[$username]))
326
+				if (isset($this->_roles[$username]))
327 327
 					$user->setRoles($this->_roles[$username]);
328 328
 				return $user;
329 329
 			}
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
 	 */
341 341
 	public function getUserFromCookie($cookie)
342 342
 	{
343
-		if(($data = $cookie->getValue()) !== '')
343
+		if (($data = $cookie->getValue()) !== '')
344 344
 		{
345 345
 			$data = unserialize($data);
346
-			if(is_array($data) && count($data) === 2)
346
+			if (is_array($data) && count($data) === 2)
347 347
 			{
348 348
 				list($username, $token) = $data;
349
-				if(isset($this->_users[$username]) && $token === md5($username . $this->_users[$username]))
349
+				if (isset($this->_users[$username]) && $token === md5($username.$this->_users[$username]))
350 350
 					return $this->getUser($username);
351 351
 			}
352 352
 		}
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 	{
363 363
 		$user = $this->getApplication()->getUser();
364 364
 		$username = strtolower($user->getName());
365
-		if(isset($this->_users[$username]))
365
+		if (isset($this->_users[$username]))
366 366
 		{
367
-			$data = [$username,md5($username . $this->_users[$username])];
367
+			$data = [$username, md5($username.$this->_users[$username])];
368 368
 			$cookie->setValue(serialize($data));
369 369
 		}
370 370
 	}
Please login to merge, or discard this patch.
Braces   +37 added lines, -30 removed lines patch added patch discarded remove patch
@@ -117,8 +117,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
framework/Security/TAuthManager.php 2 patches
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -89,22 +89,22 @@  discard block
 block discarded – undo
89 89
 	 */
90 90
 	public function init($config)
91 91
 	{
92
-		if($this->_userManager === null)
92
+		if ($this->_userManager === null)
93 93
 			throw new TConfigurationException('authmanager_usermanager_required');
94
-		if($this->_returnUrlVarName === null)
95
-			$this->_returnUrlVarName = $this->getApplication()->getID() . ':' . self::RETURN_URL_VAR;
94
+		if ($this->_returnUrlVarName === null)
95
+			$this->_returnUrlVarName = $this->getApplication()->getID().':'.self::RETURN_URL_VAR;
96 96
 		$application = $this->getApplication();
97
-		if(is_string($this->_userManager))
97
+		if (is_string($this->_userManager))
98 98
 		{
99
-			if(($users = $application->getModule($this->_userManager)) === null)
99
+			if (($users = $application->getModule($this->_userManager)) === null)
100 100
 				throw new TConfigurationException('authmanager_usermanager_inexistent', $this->_userManager);
101
-			if(!($users instanceof IUserManager))
101
+			if (!($users instanceof IUserManager))
102 102
 				throw new TConfigurationException('authmanager_usermanager_invalid', $this->_userManager);
103 103
 			$this->_userManager = $users;
104 104
 		}
105
-		$application->attachEventHandler('OnAuthentication', [$this,'doAuthentication']);
106
-		$application->attachEventHandler('OnEndRequest', [$this,'leave']);
107
-		$application->attachEventHandler('OnAuthorization', [$this,'doAuthorization']);
105
+		$application->attachEventHandler('OnAuthentication', [$this, 'doAuthentication']);
106
+		$application->attachEventHandler('OnEndRequest', [$this, 'leave']);
107
+		$application->attachEventHandler('OnAuthorization', [$this, 'doAuthorization']);
108 108
 		$this->_initialized = true;
109 109
 	}
110 110
 
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function setUserManager($provider)
124 124
 	{
125
-		if($this->_initialized)
125
+		if ($this->_initialized)
126 126
 			throw new TInvalidOperationException('authmanager_usermanager_unchangeable');
127
-		if(!is_string($provider) && !($provider instanceof IUserManager))
127
+		if (!is_string($provider) && !($provider instanceof IUserManager))
128 128
 			throw new TConfigurationException('authmanager_usermanager_invalid', $this->_userManager);
129 129
 		$this->_userManager = $provider;
130 130
 	}
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		$this->onAuthenticate($param);
161 161
 
162 162
 		$service = $this->getService();
163
-		if(($service instanceof TPageService) && $service->getRequestedPagePath() === $this->getLoginPage())
163
+		if (($service instanceof TPageService) && $service->getRequestedPagePath() === $this->getLoginPage())
164 164
 			$this->_skipAuthorization = true;
165 165
 	}
166 166
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	 */
174 174
 	public function doAuthorization($sender, $param)
175 175
 	{
176
-		if(!$this->_skipAuthorization)
176
+		if (!$this->_skipAuthorization)
177 177
 		{
178 178
 			$this->onAuthorize($param);
179 179
 		}
@@ -189,10 +189,10 @@  discard block
 block discarded – undo
189 189
 	public function leave($sender, $param)
190 190
 	{
191 191
 		$application = $this->getApplication();
192
-		if($application->getResponse()->getStatusCode() === 401)
192
+		if ($application->getResponse()->getStatusCode() === 401)
193 193
 		{
194 194
 			$service = $application->getService();
195
-			if($service instanceof TPageService)
195
+			if ($service instanceof TPageService)
196 196
 			{
197 197
 				$returnUrl = $application->getRequest()->getRequestUri();
198 198
 				$this->setReturnUrl($returnUrl);
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 		$application = $this->getApplication();
285 285
 
286 286
 		// restoring user info from session
287
-		if(($session = $application->getSession()) === null)
287
+		if (($session = $application->getSession()) === null)
288 288
 			throw new TConfigurationException('authmanager_session_required');
289 289
 		$session->open();
290 290
 		$sessionInfo = $session->itemAt($this->getUserKey());
@@ -295,12 +295,12 @@  discard block
 block discarded – undo
295 295
 		($expiretime = $session->itemAt('AuthExpireTime')) && $expiretime < time();
296 296
 
297 297
 		// try authenticating through cookie if possible
298
-		if($this->getAllowAutoLogin() && ($user->getIsGuest() || $isAuthExpired))
298
+		if ($this->getAllowAutoLogin() && ($user->getIsGuest() || $isAuthExpired))
299 299
 		{
300 300
 			$cookie = $this->getRequest()->getCookies()->itemAt($this->getUserKey());
301
-			if($cookie instanceof THttpCookie)
301
+			if ($cookie instanceof THttpCookie)
302 302
 			{
303
-				if(($user2 = $this->_userManager->getUserFromCookie($cookie)) !== null)
303
+				if (($user2 = $this->_userManager->getUserFromCookie($cookie)) !== null)
304 304
 				{
305 305
 					$user = $user2;
306 306
 					$this->updateSessionUser($user);
@@ -313,13 +313,13 @@  discard block
 block discarded – undo
313 313
 		$application->setUser($user);
314 314
 
315 315
 		// handle authentication expiration or update expiration time
316
-		if($isAuthExpired)
316
+		if ($isAuthExpired)
317 317
 			$this->onAuthExpire($param);
318 318
 		else
319 319
 			$session->add('AuthExpireTime', time() + $this->_authExpire);
320 320
 
321 321
 		// event handler gets a chance to do further auth work
322
-		if($this->hasEventHandler('OnAuthenticate'))
322
+		if ($this->hasEventHandler('OnAuthenticate'))
323 323
 			$this->raiseEvent('OnAuthenticate', $this, $application);
324 324
 	}
325 325
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	public function onAuthExpire($param)
332 332
 	{
333 333
 		$this->logout();
334
-		if($this->hasEventHandler('OnAuthExpire'))
334
+		if ($this->hasEventHandler('OnAuthExpire'))
335 335
 			$this->raiseEvent('OnAuthExpire', $this, $param);
336 336
 	}
337 337
 
@@ -345,9 +345,9 @@  discard block
 block discarded – undo
345 345
 	public function onAuthorize($param)
346 346
 	{
347 347
 		$application = $this->getApplication();
348
-		if($this->hasEventHandler('OnAuthorize'))
348
+		if ($this->hasEventHandler('OnAuthorize'))
349 349
 			$this->raiseEvent('OnAuthorize', $this, $application);
350
-		if(!$application->getAuthorizationRules()->isUserAllowed($application->getUser(), $application->getRequest()->getRequestType(), $application->getRequest()->getUserHostAddress()))
350
+		if (!$application->getAuthorizationRules()->isUserAllowed($application->getUser(), $application->getRequest()->getRequestType(), $application->getRequest()->getUserHostAddress()))
351 351
 		{
352 352
 			$application->getResponse()->setStatusCode(401);
353 353
 			$application->completeRequest();
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 */
361 361
 	public function getUserKey()
362 362
 	{
363
-		if($this->_userKey === null)
363
+		if ($this->_userKey === null)
364 364
 			$this->_userKey = $this->generateUserKey();
365 365
 		return $this->_userKey;
366 366
 	}
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 	 */
372 372
 	protected function generateUserKey()
373 373
 	{
374
-		return md5($this->getApplication()->getUniqueID() . 'prado:user');
374
+		return md5($this->getApplication()->getUniqueID().'prado:user');
375 375
 	}
376 376
 
377 377
 	/**
@@ -381,9 +381,9 @@  discard block
 block discarded – undo
381 381
 	 */
382 382
 	public function updateSessionUser($user)
383 383
 	{
384
-		if(!$user->getIsGuest())
384
+		if (!$user->getIsGuest())
385 385
 		{
386
-			if(($session = $this->getSession()) === null)
386
+			if (($session = $this->getSession()) === null)
387 387
 				throw new TConfigurationException('authmanager_session_required');
388 388
 			else
389 389
 				$session->add($this->getUserKey(), $user->saveToString());
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	 */
399 399
 	public function switchUser($username)
400 400
 	{
401
-		if(($user = $this->_userManager->getUser($username)) === null)
401
+		if (($user = $this->_userManager->getUser($username)) === null)
402 402
 			return false;
403 403
 		$this->updateSessionUser($user);
404 404
 		$this->getApplication()->setUser($user);
@@ -416,14 +416,14 @@  discard block
 block discarded – undo
416 416
 	 */
417 417
 	public function login($username, $password, $expire = 0)
418 418
 	{
419
-		if($this->_userManager->validateUser($username, $password))
419
+		if ($this->_userManager->validateUser($username, $password))
420 420
 		{
421
-			if(($user = $this->_userManager->getUser($username)) === null)
421
+			if (($user = $this->_userManager->getUser($username)) === null)
422 422
 				return false;
423 423
 			$this->updateSessionUser($user);
424 424
 			$this->getApplication()->setUser($user);
425 425
 
426
-			if($expire > 0)
426
+			if ($expire > 0)
427 427
 			{
428 428
 				$cookie = new THttpCookie($this->getUserKey(), '');
429 429
 				$cookie->setExpire(time() + $expire);
@@ -443,11 +443,11 @@  discard block
 block discarded – undo
443 443
 	 */
444 444
 	public function logout()
445 445
 	{
446
-		if(($session = $this->getSession()) === null)
446
+		if (($session = $this->getSession()) === null)
447 447
 			throw new TConfigurationException('authmanager_session_required');
448 448
 		$this->getApplication()->getUser()->setIsGuest(true);
449 449
 		$session->destroy();
450
-		if($this->getAllowAutoLogin())
450
+		if ($this->getAllowAutoLogin())
451 451
 		{
452 452
 			$cookie = new THttpCookie($this->getUserKey(), '');
453 453
 			$this->getResponse()->getCookies()->add($cookie);
Please login to merge, or discard this patch.
Braces   +57 added lines, -40 removed lines patch added patch discarded remove patch
@@ -89,17 +89,21 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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())
Please login to merge, or discard this patch.
framework/Security/TDbUser.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -37,19 +37,19 @@
 block discarded – undo
37 37
 	 */
38 38
 	public function getDbConnection()
39 39
 	{
40
-		if($this->_connection === null)
40
+		if ($this->_connection === null)
41 41
 		{
42 42
 			$userManager = $this->getManager();
43
-			if($userManager instanceof TDbUserManager)
43
+			if ($userManager instanceof TDbUserManager)
44 44
 			{
45 45
 				$connection = $userManager->getDbConnection();
46
-				if($connection instanceof TDbConnection)
46
+				if ($connection instanceof TDbConnection)
47 47
 				{
48 48
 					$connection->setActive(true);
49 49
 					$this->_connection = $connection;
50 50
 				}
51 51
 			}
52
-			if($this->_connection === null)
52
+			if ($this->_connection === null)
53 53
 				throw new TConfigurationException('dbuser_dbconnection_invalid');
54 54
 		}
55 55
 		return $this->_connection;
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,8 +49,9 @@
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
framework/Security/TAuthorizationRule.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	public function __construct($action, $users, $roles, $verb = '', $ipRules = '')
79 79
 	{
80 80
 		$action = strtolower(trim($action));
81
-		if($action === 'allow' || $action === 'deny')
81
+		if ($action === 'allow' || $action === 'deny')
82 82
 			$this->_action = $action;
83 83
 		else
84 84
 			throw new TInvalidDataValueException('authorizationrule_action_invalid', $action);
@@ -89,46 +89,46 @@  discard block
 block discarded – undo
89 89
 		$this->_guest = false;
90 90
 		$this->_authenticated = false;
91 91
 
92
-		if(trim($users) === '')
92
+		if (trim($users) === '')
93 93
 			$users = '*';
94
-		foreach(explode(',', $users) as $user)
94
+		foreach (explode(',', $users) as $user)
95 95
 		{
96
-			if(($user = trim(strtolower($user))) !== '')
96
+			if (($user = trim(strtolower($user))) !== '')
97 97
 			{
98
-				if($user === '*')
98
+				if ($user === '*')
99 99
 				{
100 100
 					$this->_everyone = true;
101 101
 					break;
102 102
 				}
103
-				elseif($user === '?')
103
+				elseif ($user === '?')
104 104
 					$this->_guest = true;
105
-				elseif($user === '@')
105
+				elseif ($user === '@')
106 106
 					$this->_authenticated = true;
107 107
 				else
108 108
 					$this->_users[] = $user;
109 109
 			}
110 110
 		}
111 111
 
112
-		if(trim($roles) === '')
112
+		if (trim($roles) === '')
113 113
 			$roles = '*';
114
-		foreach(explode(',', $roles) as $role)
114
+		foreach (explode(',', $roles) as $role)
115 115
 		{
116
-			if(($role = trim(strtolower($role))) !== '')
116
+			if (($role = trim(strtolower($role))) !== '')
117 117
 				$this->_roles[] = $role;
118 118
 		}
119 119
 
120
-		if(($verb = trim(strtolower($verb))) === '')
120
+		if (($verb = trim(strtolower($verb))) === '')
121 121
 			$verb = '*';
122
-		if($verb === '*' || $verb === 'get' || $verb === 'post')
122
+		if ($verb === '*' || $verb === 'get' || $verb === 'post')
123 123
 			$this->_verb = $verb;
124 124
 		else
125 125
 			throw new TInvalidDataValueException('authorizationrule_verb_invalid', $verb);
126 126
 
127
-		if(trim($ipRules) === '')
127
+		if (trim($ipRules) === '')
128 128
 			$ipRules = '*';
129
-		foreach(explode(',', $ipRules) as $ipRule)
129
+		foreach (explode(',', $ipRules) as $ipRule)
130 130
 		{
131
-			if(($ipRule = trim($ipRule)) !== '')
131
+			if (($ipRule = trim($ipRule)) !== '')
132 132
 				$this->_ipRules[] = $ipRule;
133 133
 		}
134 134
 	}
@@ -206,19 +206,19 @@  discard block
 block discarded – undo
206 206
 	 */
207 207
 	public function isUserAllowed(IUser $user, $verb, $ip)
208 208
 	{
209
-		if($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user))
210
-			return ($this->_action === 'allow')?1:-1;
209
+		if ($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user))
210
+			return ($this->_action === 'allow') ? 1 : -1;
211 211
 		else
212 212
 			return 0;
213 213
 	}
214 214
 
215 215
 	private function isIpMatched($ip)
216 216
 	{
217
-		if(empty($this->_ipRules))
217
+		if (empty($this->_ipRules))
218 218
 			return 1;
219
-		foreach($this->_ipRules as $rule)
219
+		foreach ($this->_ipRules as $rule)
220 220
 		{
221
-			if($rule === '*' || $rule === $ip || (($pos = strpos($rule, '*')) !== false && strncmp($ip, $rule, $pos) === 0))
221
+			if ($rule === '*' || $rule === $ip || (($pos = strpos($rule, '*')) !== false && strncmp($ip, $rule, $pos) === 0))
222 222
 				return 1;
223 223
 		}
224 224
 		return 0;
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 
232 232
 	private function isRoleMatched($user)
233 233
 	{
234
-		foreach($this->_roles as $role)
234
+		foreach ($this->_roles as $role)
235 235
 		{
236
-			if($role === '*' || $user->isInRole($role))
236
+			if ($role === '*' || $user->isInRole($role))
237 237
 				return true;
238 238
 		}
239 239
 		return false;
Please login to merge, or discard this patch.
Braces   +48 added lines, -36 removed lines patch added patch discarded remove patch
@@ -78,10 +78,11 @@  discard block
 block discarded – undo
78 78
 	public function __construct($action, $users, $roles, $verb = '', $ipRules = '')
79 79
 	{
80 80
 		$action = strtolower(trim($action));
81
-		if($action === 'allow' || $action === 'deny')
82
-			$this->_action = $action;
83
-		else
84
-			throw new TInvalidDataValueException('authorizationrule_action_invalid', $action);
81
+		if($action === 'allow' || $action === 'deny') {
82
+					$this->_action = $action;
83
+		} else {
84
+					throw new TInvalidDataValueException('authorizationrule_action_invalid', $action);
85
+		}
85 86
 		$this->_users = [];
86 87
 		$this->_roles = [];
87 88
 		$this->_ipRules = [];
@@ -89,8 +90,9 @@  discard block
 block discarded – undo
89 90
 		$this->_guest = false;
90 91
 		$this->_authenticated = false;
91 92
 
92
-		if(trim($users) === '')
93
-			$users = '*';
93
+		if(trim($users) === '') {
94
+					$users = '*';
95
+		}
94 96
 		foreach(explode(',', $users) as $user)
95 97
 		{
96 98
 			if(($user = trim(strtolower($user))) !== '')
@@ -99,37 +101,43 @@  discard block
 block discarded – undo
99 101
 				{
100 102
 					$this->_everyone = true;
101 103
 					break;
104
+				} elseif($user === '?') {
105
+									$this->_guest = true;
106
+				} elseif($user === '@') {
107
+									$this->_authenticated = true;
108
+				} else {
109
+									$this->_users[] = $user;
102 110
 				}
103
-				elseif($user === '?')
104
-					$this->_guest = true;
105
-				elseif($user === '@')
106
-					$this->_authenticated = true;
107
-				else
108
-					$this->_users[] = $user;
109 111
 			}
110 112
 		}
111 113
 
112
-		if(trim($roles) === '')
113
-			$roles = '*';
114
+		if(trim($roles) === '') {
115
+					$roles = '*';
116
+		}
114 117
 		foreach(explode(',', $roles) as $role)
115 118
 		{
116
-			if(($role = trim(strtolower($role))) !== '')
117
-				$this->_roles[] = $role;
119
+			if(($role = trim(strtolower($role))) !== '') {
120
+							$this->_roles[] = $role;
121
+			}
118 122
 		}
119 123
 
120
-		if(($verb = trim(strtolower($verb))) === '')
121
-			$verb = '*';
122
-		if($verb === '*' || $verb === 'get' || $verb === 'post')
123
-			$this->_verb = $verb;
124
-		else
125
-			throw new TInvalidDataValueException('authorizationrule_verb_invalid', $verb);
124
+		if(($verb = trim(strtolower($verb))) === '') {
125
+					$verb = '*';
126
+		}
127
+		if($verb === '*' || $verb === 'get' || $verb === 'post') {
128
+					$this->_verb = $verb;
129
+		} else {
130
+					throw new TInvalidDataValueException('authorizationrule_verb_invalid', $verb);
131
+		}
126 132
 
127
-		if(trim($ipRules) === '')
128
-			$ipRules = '*';
133
+		if(trim($ipRules) === '') {
134
+					$ipRules = '*';
135
+		}
129 136
 		foreach(explode(',', $ipRules) as $ipRule)
130 137
 		{
131
-			if(($ipRule = trim($ipRule)) !== '')
132
-				$this->_ipRules[] = $ipRule;
138
+			if(($ipRule = trim($ipRule)) !== '') {
139
+							$this->_ipRules[] = $ipRule;
140
+			}
133 141
 		}
134 142
 	}
135 143
 
@@ -206,20 +214,23 @@  discard block
 block discarded – undo
206 214
 	 */
207 215
 	public function isUserAllowed(IUser $user, $verb, $ip)
208 216
 	{
209
-		if($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user))
210
-			return ($this->_action === 'allow')?1:-1;
211
-		else
212
-			return 0;
217
+		if($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user)) {
218
+					return ($this->_action === 'allow')?1:-1;
219
+		} else {
220
+					return 0;
221
+		}
213 222
 	}
214 223
 
215 224
 	private function isIpMatched($ip)
216 225
 	{
217
-		if(empty($this->_ipRules))
218
-			return 1;
226
+		if(empty($this->_ipRules)) {
227
+					return 1;
228
+		}
219 229
 		foreach($this->_ipRules as $rule)
220 230
 		{
221
-			if($rule === '*' || $rule === $ip || (($pos = strpos($rule, '*')) !== false && strncmp($ip, $rule, $pos) === 0))
222
-				return 1;
231
+			if($rule === '*' || $rule === $ip || (($pos = strpos($rule, '*')) !== false && strncmp($ip, $rule, $pos) === 0)) {
232
+							return 1;
233
+			}
223 234
 		}
224 235
 		return 0;
225 236
 	}
@@ -233,8 +244,9 @@  discard block
 block discarded – undo
233 244
 	{
234 245
 		foreach($this->_roles as $role)
235 246
 		{
236
-			if($role === '*' || $user->isInRole($role))
237
-				return true;
247
+			if($role === '*' || $user->isInRole($role)) {
248
+							return true;
249
+			}
238 250
 		}
239 251
 		return false;
240 252
 	}
Please login to merge, or discard this patch.
framework/Security/TAuthorizationRuleCollection.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,12 +32,12 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public function isUserAllowed($user, $verb, $ip)
34 34
 	{
35
-		if($user instanceof IUser)
35
+		if ($user instanceof IUser)
36 36
 		{
37 37
 			$verb = strtolower(trim($verb));
38
-			foreach($this as $rule)
38
+			foreach ($this as $rule)
39 39
 			{
40
-				if(($decision = $rule->isUserAllowed($user, $verb, $ip)) !== 0)
40
+				if (($decision = $rule->isUserAllowed($user, $verb, $ip)) !== 0)
41 41
 					return ($decision > 0);
42 42
 			}
43 43
 			return true;
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public function insertAt($index, $item)
58 58
 	{
59
-		if($item instanceof TAuthorizationRule)
59
+		if ($item instanceof TAuthorizationRule)
60 60
 			parent::insertAt($index, $item);
61 61
 		else
62 62
 			throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required');
Please login to merge, or discard this patch.
Braces   +10 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,13 +37,14 @@  discard block
 block discarded – undo
37 37
 			$verb = strtolower(trim($verb));
38 38
 			foreach($this as $rule)
39 39
 			{
40
-				if(($decision = $rule->isUserAllowed($user, $verb, $ip)) !== 0)
41
-					return ($decision > 0);
40
+				if(($decision = $rule->isUserAllowed($user, $verb, $ip)) !== 0) {
41
+									return ($decision > 0);
42
+				}
42 43
 			}
43 44
 			return true;
45
+		} else {
46
+					return false;
44 47
 		}
45
-		else
46
-			return false;
47 48
 	}
48 49
 
49 50
 	/**
@@ -56,9 +57,10 @@  discard block
 block discarded – undo
56 57
 	 */
57 58
 	public function insertAt($index, $item)
58 59
 	{
59
-		if($item instanceof TAuthorizationRule)
60
-			parent::insertAt($index, $item);
61
-		else
62
-			throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required');
60
+		if($item instanceof TAuthorizationRule) {
61
+					parent::insertAt($index, $item);
62
+		} else {
63
+					throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required');
64
+		}
63 65
 	}
64 66
 }
65 67
\ No newline at end of file
Please login to merge, or discard this patch.
framework/Security/TUser.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public function setIsGuest($value)
93 93
 	{
94
-		if($isGuest = TPropertyValue::ensureBoolean($value))
94
+		if ($isGuest = TPropertyValue::ensureBoolean($value))
95 95
 		{
96 96
 			$this->setName($this->_manager->getGuestName());
97 97
 			$this->setRoles([]);
@@ -112,14 +112,14 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	public function setRoles($value)
114 114
 	{
115
-		if(is_array($value))
115
+		if (is_array($value))
116 116
 			$this->setState('Roles', $value, []);
117 117
 		else
118 118
 		{
119 119
 			$roles = [];
120
-			foreach(explode(',', $value) as $role)
120
+			foreach (explode(',', $value) as $role)
121 121
 			{
122
-				if(($role = trim($role)) !== '')
122
+				if (($role = trim($role)) !== '')
123 123
 					$roles[] = $role;
124 124
 			}
125 125
 			$this->setState('Roles', $roles, []);
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	public function isInRole($role)
134 134
 	{
135
-		foreach($this->getRoles() as $r)
136
-			if(strcasecmp($role, $r) === 0)
135
+		foreach ($this->getRoles() as $r)
136
+			if (strcasecmp($role, $r) === 0)
137 137
 				return true;
138 138
 		return false;
139 139
 	}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function loadFromString($data)
154 154
 	{
155
-		if(!empty($data))
155
+		if (!empty($data))
156 156
 			$this->_state = unserialize($data);
157
-		if(!is_array($this->_state))
157
+		if (!is_array($this->_state))
158 158
 			$this->_state = [];
159 159
 		return $this;
160 160
 	}
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 */
175 175
 	protected function getState($key, $defaultValue = null)
176 176
 	{
177
-		return isset($this->_state[$key])?$this->_state[$key]:$defaultValue;
177
+		return isset($this->_state[$key]) ? $this->_state[$key] : $defaultValue;
178 178
 	}
179 179
 
180 180
 	/**
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	 */
194 194
 	protected function setState($key, $value, $defaultValue = null)
195 195
 	{
196
-		if($value === $defaultValue)
196
+		if ($value === $defaultValue)
197 197
 			unset($this->_state[$key]);
198 198
 		else
199 199
 			$this->_state[$key] = $value;
Please login to merge, or discard this patch.
Braces   +20 added lines, -15 removed lines patch added patch discarded remove patch
@@ -112,15 +112,16 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	public function setRoles($value)
114 114
 	{
115
-		if(is_array($value))
116
-			$this->setState('Roles', $value, []);
117
-		else
115
+		if(is_array($value)) {
116
+					$this->setState('Roles', $value, []);
117
+		} else
118 118
 		{
119 119
 			$roles = [];
120 120
 			foreach(explode(',', $value) as $role)
121 121
 			{
122
-				if(($role = trim($role)) !== '')
123
-					$roles[] = $role;
122
+				if(($role = trim($role)) !== '') {
123
+									$roles[] = $role;
124
+				}
124 125
 			}
125 126
 			$this->setState('Roles', $roles, []);
126 127
 		}
@@ -132,9 +133,10 @@  discard block
 block discarded – undo
132 133
 	 */
133 134
 	public function isInRole($role)
134 135
 	{
135
-		foreach($this->getRoles() as $r)
136
-			if(strcasecmp($role, $r) === 0)
136
+		foreach($this->getRoles() as $r) {
137
+					if(strcasecmp($role, $r) === 0)
137 138
 				return true;
139
+		}
138 140
 		return false;
139 141
 	}
140 142
 
@@ -152,10 +154,12 @@  discard block
 block discarded – undo
152 154
 	 */
153 155
 	public function loadFromString($data)
154 156
 	{
155
-		if(!empty($data))
156
-			$this->_state = unserialize($data);
157
-		if(!is_array($this->_state))
158
-			$this->_state = [];
157
+		if(!empty($data)) {
158
+					$this->_state = unserialize($data);
159
+		}
160
+		if(!is_array($this->_state)) {
161
+					$this->_state = [];
162
+		}
159 163
 		return $this;
160 164
 	}
161 165
 
@@ -193,10 +197,11 @@  discard block
 block discarded – undo
193 197
 	 */
194 198
 	protected function setState($key, $value, $defaultValue = null)
195 199
 	{
196
-		if($value === $defaultValue)
197
-			unset($this->_state[$key]);
198
-		else
199
-			$this->_state[$key] = $value;
200
+		if($value === $defaultValue) {
201
+					unset($this->_state[$key]);
202
+		} else {
203
+					$this->_state[$key] = $value;
204
+		}
200 205
 		$this->_stateChanged = true;
201 206
 	}
202 207
 
Please login to merge, or discard this patch.
framework/Security/TDbUserManager.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function init($config)
63 63
 	{
64
-		if($this->_userClass === '')
64
+		if ($this->_userClass === '')
65 65
 			throw new TConfigurationException('dbusermanager_userclass_required');
66 66
 		$this->_userFactory = Prado::createComponent($this->_userClass, $this);
67
-		if(!($this->_userFactory instanceof TDbUser))
67
+		if (!($this->_userFactory instanceof TDbUser))
68 68
 			throw new TInvalidDataTypeException('dbusermanager_userclass_invalid', $this->_userClass);
69 69
 	}
70 70
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function getUser($username = null)
120 120
 	{
121
-		if($username === null)
121
+		if ($username === null)
122 122
 		{
123 123
 			$user = Prado::createComponent($this->_userClass, $this);
124 124
 			$user->setIsGuest(true);
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function getDbConnection()
154 154
 	{
155
-		if($this->_conn === null)
155
+		if ($this->_conn === null)
156 156
 		{
157 157
 			$this->_conn = $this->createDbConnection($this->_connID);
158 158
 			$this->_conn->setActive(true);
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
 	 */
169 169
 	protected function createDbConnection($connectionID)
170 170
 	{
171
-		if($connectionID !== '')
171
+		if ($connectionID !== '')
172 172
 		{
173 173
 			$conn = $this->getApplication()->getModule($connectionID);
174
-			if($conn instanceof TDataSourceConfig)
174
+			if ($conn instanceof TDataSourceConfig)
175 175
 				return $conn->getDbConnection();
176 176
 			else
177 177
 				throw new TConfigurationException('dbusermanager_connectionid_invalid', $connectionID);
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	public function saveUserToCookie($cookie)
200 200
 	{
201 201
 		$user = $this->getApplication()->getUser();
202
-		if($user instanceof TDbUser)
202
+		if ($user instanceof TDbUser)
203 203
 			$user->saveUserToCookie($cookie);
204 204
 	}
205 205
 }
206 206
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +18 added lines, -14 removed lines patch added patch discarded remove patch
@@ -61,11 +61,13 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function init($config)
63 63
 	{
64
-		if($this->_userClass === '')
65
-			throw new TConfigurationException('dbusermanager_userclass_required');
64
+		if($this->_userClass === '') {
65
+					throw new TConfigurationException('dbusermanager_userclass_required');
66
+		}
66 67
 		$this->_userFactory = Prado::createComponent($this->_userClass, $this);
67
-		if(!($this->_userFactory instanceof TDbUser))
68
-			throw new TInvalidDataTypeException('dbusermanager_userclass_invalid', $this->_userClass);
68
+		if(!($this->_userFactory instanceof TDbUser)) {
69
+					throw new TInvalidDataTypeException('dbusermanager_userclass_invalid', $this->_userClass);
70
+		}
69 71
 	}
70 72
 
71 73
 	/**
@@ -123,9 +125,9 @@  discard block
 block discarded – undo
123 125
 			$user = Prado::createComponent($this->_userClass, $this);
124 126
 			$user->setIsGuest(true);
125 127
 			return $user;
128
+		} else {
129
+					return $this->_userFactory->createUser($username);
126 130
 		}
127
-		else
128
-			return $this->_userFactory->createUser($username);
129 131
 	}
130 132
 
131 133
 	/**
@@ -171,13 +173,14 @@  discard block
 block discarded – undo
171 173
 		if($connectionID !== '')
172 174
 		{
173 175
 			$conn = $this->getApplication()->getModule($connectionID);
174
-			if($conn instanceof TDataSourceConfig)
175
-				return $conn->getDbConnection();
176
-			else
177
-				throw new TConfigurationException('dbusermanager_connectionid_invalid', $connectionID);
176
+			if($conn instanceof TDataSourceConfig) {
177
+							return $conn->getDbConnection();
178
+			} else {
179
+							throw new TConfigurationException('dbusermanager_connectionid_invalid', $connectionID);
180
+			}
181
+		} else {
182
+					throw new TConfigurationException('dbusermanager_connectionid_required');
178 183
 		}
179
-		else
180
-			throw new TConfigurationException('dbusermanager_connectionid_required');
181 184
 	}
182 185
 
183 186
 	/**
@@ -199,7 +202,8 @@  discard block
 block discarded – undo
199 202
 	public function saveUserToCookie($cookie)
200 203
 	{
201 204
 		$user = $this->getApplication()->getUser();
202
-		if($user instanceof TDbUser)
203
-			$user->saveUserToCookie($cookie);
205
+		if($user instanceof TDbUser) {
206
+					$user->saveUserToCookie($cookie);
207
+		}
204 208
 	}
205 209
 }
206 210
\ No newline at end of file
Please login to merge, or discard this patch.