Completed
Push — master ( 9d31a7...55703c )
by Fabio
09:26
created
bin/prado-cli.php 4 patches
Doc Comments   +25 added lines patch added patch discarded remove patch
@@ -140,6 +140,10 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	public abstract function performAction($args);
142 142
 
143
+	/**
144
+	 * @param string $dir
145
+	 * @param integer $mask
146
+	 */
143 147
 	protected function createDirectory($dir, $mask)
144 148
 	{
145 149
 		if(!is_dir($dir))
@@ -151,6 +155,9 @@  discard block
 block discarded – undo
151 155
 			chmod($dir, $mask);
152 156
 	}
153 157
 
158
+	/**
159
+	 * @param string $filename
160
+	 */
154 161
 	protected function createFile($filename, $content)
155 162
 	{
156 163
 		if(!is_file($filename))
@@ -300,6 +307,9 @@  discard block
 block discarded – undo
300 307
 ';
301 308
 	}
302 309
 
310
+	/**
311
+	 * @param string $appName
312
+	 */
303 313
 	protected function renderConfigFile($appName)
304 314
 	{
305 315
 		return <<<EOD
@@ -513,6 +523,9 @@  discard block
 block discarded – undo
513 523
 		return false;
514 524
 	}
515 525
 
526
+	/**
527
+	 * @param string $app_dir
528
+	 */
516 529
 	protected function getActiveRecordConfig($app_dir)
517 530
 	{
518 531
 		if(false === ($xml=$this->getXmlFile($app_dir)))
@@ -528,6 +541,9 @@  discard block
 block discarded – undo
528 541
 		return false;
529 542
 	}
530 543
 
544
+	/**
545
+	 * @param string $app_dir
546
+	 */
531 547
 	protected function getOutputFile($app_dir, $namespace)
532 548
 	{
533 549
 		if(is_file($namespace) && strpos($namespace, $app_dir)===0)
@@ -589,6 +605,9 @@  discard block
 block discarded – undo
589 605
 		return $prop;
590 606
 	}
591 607
 
608
+	/**
609
+	 * @param string $class
610
+	 */
592 611
 	protected function generateClass($properties, $tablename, $class)
593 612
 	{
594 613
 		$props = implode("\n", $properties);
@@ -684,6 +703,9 @@  discard block
 block discarded – undo
684 703
         return true;
685 704
     }
686 705
 
706
+    /**
707
+     * @param string $l
708
+     */
687 709
     public function generate($l)
688 710
     {
689 711
 		$input = explode(" ", trim($l));
@@ -722,6 +744,9 @@  discard block
 block discarded – undo
722 744
         return false;
723 745
     }
724 746
 
747
+    /**
748
+     * @param string $app_dir
749
+     */
725 750
     protected function getActiveRecordConfig($app_dir) {
726 751
         if (false === ($xml = $this->getXmlFile($app_dir)))
727 752
             return false;
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -623,31 +623,31 @@  discard block
 block discarded – undo
623 623
  */
624 624
 class PradoCommandLineActiveRecordGenAll extends PradoCommandLineAction
625 625
 {
626
-    protected $action = 'generateAll';
627
-    protected $parameters = array('output');
628
-    protected $optional = array('directory', 'soap', 'overwrite', 'prefix', 'postfix');
629
-    protected $description = "Generate Active Record skeleton for all Tables to <output> file using application.xml in [directory]. May also generate [soap] properties.\nGenerated Classes are named like the Table with optional [Prefix] and/or [Postfix]. [Overwrite] is used to overwrite existing Files.";
630
-    private $_soap = false;
631
-    private $_prefix = '';
632
-    private $_postfix = '';
633
-    private $_overwrite = false;
634
-
635
-    public function performAction($args) {
636
-        $app_dir = count($args) > 2 ? $this->getAppDir($args[2]) : $this->getAppDir();
637
-        $this->_soap = count($args) > 3 ? ($args[3] == "soap" || $args[3] == "true" ? true : false) : false;
638
-        $this->_overwrite = count($args) > 4 ? ($args[4] == "overwrite" || $args[4] == "true" ? true : false) : false;
639
-        $this->_prefix = count($args) > 5 ? $args[5] : '';
640
-        $this->_postfix = count($args) > 6 ? $args[6] : '';
641
-
642
-        if ($app_dir !== false) {
643
-            $config = $this->getActiveRecordConfig($app_dir);
644
-
645
-            $manager = TActiveRecordManager::getInstance();
646
-            $con = $manager->getDbConnection();
647
-            $con->Active = true;
648
-
649
-            switch($con->getDriverName())
650
-           	{
626
+	protected $action = 'generateAll';
627
+	protected $parameters = array('output');
628
+	protected $optional = array('directory', 'soap', 'overwrite', 'prefix', 'postfix');
629
+	protected $description = "Generate Active Record skeleton for all Tables to <output> file using application.xml in [directory]. May also generate [soap] properties.\nGenerated Classes are named like the Table with optional [Prefix] and/or [Postfix]. [Overwrite] is used to overwrite existing Files.";
630
+	private $_soap = false;
631
+	private $_prefix = '';
632
+	private $_postfix = '';
633
+	private $_overwrite = false;
634
+
635
+	public function performAction($args) {
636
+		$app_dir = count($args) > 2 ? $this->getAppDir($args[2]) : $this->getAppDir();
637
+		$this->_soap = count($args) > 3 ? ($args[3] == "soap" || $args[3] == "true" ? true : false) : false;
638
+		$this->_overwrite = count($args) > 4 ? ($args[4] == "overwrite" || $args[4] == "true" ? true : false) : false;
639
+		$this->_prefix = count($args) > 5 ? $args[5] : '';
640
+		$this->_postfix = count($args) > 6 ? $args[6] : '';
641
+
642
+		if ($app_dir !== false) {
643
+			$config = $this->getActiveRecordConfig($app_dir);
644
+
645
+			$manager = TActiveRecordManager::getInstance();
646
+			$con = $manager->getDbConnection();
647
+			$con->Active = true;
648
+
649
+			switch($con->getDriverName())
650
+		   	{
651 651
 				case 'mysqli':
652 652
 				case 'mysql':
653 653
 					$command = $con->createCommand("SHOW TABLES");
@@ -665,27 +665,27 @@  discard block
 block discarded – undo
665 665
 				default:
666 666
 					echo "\n    Sorry, generateAll is not implemented for ".$con->getDriverName()."\n";
667 667
 					
668
-           	}
669
-
670
-            $dataReader = $command->query();
671
-            $dataReader->bindColumn(1, $table);
672
-            $tables = array();
673
-            while ($dataReader->read() !== false) {
674
-                $tables[] = $table;
675
-            }
676
-            $con->Active = False;
677
-            foreach ($tables as $key => $table) {
678
-                $output = $args[1] . "." . $this->_prefix . ucfirst($table) . $this->_postfix;
679
-                if ($config !== false && $output !== false) {
680
-                    $this->generate("generate " . $table . " " . $output . " " . $this->_soap . " " . $this->_overwrite);
681
-                }
682
-            }
683
-        }
684
-        return true;
685
-    }
686
-
687
-    public function generate($l)
688
-    {
668
+		   	}
669
+
670
+			$dataReader = $command->query();
671
+			$dataReader->bindColumn(1, $table);
672
+			$tables = array();
673
+			while ($dataReader->read() !== false) {
674
+				$tables[] = $table;
675
+			}
676
+			$con->Active = False;
677
+			foreach ($tables as $key => $table) {
678
+				$output = $args[1] . "." . $this->_prefix . ucfirst($table) . $this->_postfix;
679
+				if ($config !== false && $output !== false) {
680
+					$this->generate("generate " . $table . " " . $output . " " . $this->_soap . " " . $this->_overwrite);
681
+				}
682
+			}
683
+		}
684
+		return true;
685
+	}
686
+
687
+	public function generate($l)
688
+	{
689 689
 		$input = explode(" ", trim($l));
690 690
 		if(count($input) > 2)
691 691
 		{
@@ -702,49 +702,49 @@  discard block
 block discarded – undo
702 702
 		{
703 703
 			echo "\n    Usage: generate table_name Application.pages.RecordClassName\n";
704 704
 		}
705
-    }
706
-
707
-    protected function getAppDir($dir=".") {
708
-        if (is_dir($dir))
709
-            return realpath($dir);
710
-        if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir))
711
-            return $app_dir;
712
-        echo '** Unable to find directory "' . $dir . "\".\n";
713
-        return false;
714
-    }
715
-
716
-    protected function getXmlFile($app_dir) {
717
-        if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml))
718
-            return $xml;
719
-        if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml))
720
-            return $xml;
721
-        echo '** Unable to find application.xml in ' . $app_dir . "\n";
722
-        return false;
723
-    }
724
-
725
-    protected function getActiveRecordConfig($app_dir) {
726
-        if (false === ($xml = $this->getXmlFile($app_dir)))
727
-            return false;
728
-        if (false !== ($app = $this->initializePradoApplication($app_dir))) {
729
-            Prado::using('System.Data.ActiveRecord.TActiveRecordConfig');
730
-            foreach ($app->getModules() as $module)
731
-                if ($module instanceof TActiveRecordConfig)
732
-                    return $module;
733
-            echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n";
734
-        }
735
-        return false;
736
-    }
737
-
738
-    protected function getOutputFile($app_dir, $namespace) {
739
-        if (is_file($namespace) && strpos($namespace, $app_dir) === 0)
740
-            return $namespace;
741
-        $file = Prado::getPathOfNamespace($namespace, "");
742
-        if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) {
743
-            if (strpos($path, $app_dir) === 0)
744
-                return $file;
745
-        }
746
-        echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n";
747
-        return false;
748
-    }
705
+	}
706
+
707
+	protected function getAppDir($dir=".") {
708
+		if (is_dir($dir))
709
+			return realpath($dir);
710
+		if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir))
711
+			return $app_dir;
712
+		echo '** Unable to find directory "' . $dir . "\".\n";
713
+		return false;
714
+	}
715
+
716
+	protected function getXmlFile($app_dir) {
717
+		if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml))
718
+			return $xml;
719
+		if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml))
720
+			return $xml;
721
+		echo '** Unable to find application.xml in ' . $app_dir . "\n";
722
+		return false;
723
+	}
724
+
725
+	protected function getActiveRecordConfig($app_dir) {
726
+		if (false === ($xml = $this->getXmlFile($app_dir)))
727
+			return false;
728
+		if (false !== ($app = $this->initializePradoApplication($app_dir))) {
729
+			Prado::using('System.Data.ActiveRecord.TActiveRecordConfig');
730
+			foreach ($app->getModules() as $module)
731
+				if ($module instanceof TActiveRecordConfig)
732
+					return $module;
733
+			echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n";
734
+		}
735
+		return false;
736
+	}
737
+
738
+	protected function getOutputFile($app_dir, $namespace) {
739
+		if (is_file($namespace) && strpos($namespace, $app_dir) === 0)
740
+			return $namespace;
741
+		$file = Prado::getPathOfNamespace($namespace, "");
742
+		if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) {
743
+			if (strpos($path, $app_dir) === 0)
744
+				return $file;
745
+		}
746
+		echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n";
747
+		return false;
748
+	}
749 749
 
750 750
 }
Please login to merge, or discard this patch.
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 if(!isset($_SERVER['argv']) || php_sapi_name()!=='cli')
13 13
 	die('Must be run from the command line');
14 14
 
15
-if(file_exists($autoloader = realpath(__DIR__ . '/../vendor/autoload.php')))
15
+if(file_exists($autoloader=realpath(__DIR__.'/../vendor/autoload.php')))
16 16
 {
17 17
 	include($autoloader);
18
-} elseif(file_exists($autoloader = realpath(__DIR__ . '/../autoload.php'))) {
18
+} elseif(file_exists($autoloader=realpath(__DIR__.'/../autoload.php'))) {
19 19
 	include($autoloader);
20 20
 }
21 21
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function addActionClass($class)
68 68
 	{
69
-		$this->_actions[$class] = new $class;
69
+		$this->_actions[$class]=new $class;
70 70
 	}
71 71
 
72 72
 	/**
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 	public static function getInstance()
76 76
 	{
77 77
 		static $instance;
78
-		if($instance === null)
79
-			$instance = new self;
78
+		if($instance===null)
79
+			$instance=new self;
80 80
 		return $instance;
81 81
 	}
82 82
 
@@ -93,17 +93,17 @@  discard block
 block discarded – undo
93 93
 	{
94 94
 		if(count($args) > 1)
95 95
 			array_shift($args);
96
-		$valid = false;
96
+		$valid=false;
97 97
 		foreach($this->_actions as $class => $action)
98 98
 		{
99 99
 			if($action->isValidAction($args))
100 100
 			{
101
-				$valid |= $action->performAction($args);
101
+				$valid|=$action->performAction($args);
102 102
 				break;
103 103
 			}
104 104
 			else
105 105
 			{
106
-				$valid = false;
106
+				$valid=false;
107 107
 			}
108 108
 		}
109 109
 		if(!$valid)
@@ -162,23 +162,23 @@  discard block
 block discarded – undo
162 162
 
163 163
 	public function isValidAction($args)
164 164
 	{
165
-		return 0 == strcasecmp($args[0], $this->action) &&
166
-			count($args)-1 >= count($this->parameters);
165
+		return 0==strcasecmp($args[0], $this->action) &&
166
+			count($args) - 1 >= count($this->parameters);
167 167
 	}
168 168
 
169 169
 	public function renderHelp()
170 170
 	{
171
-		$params = array();
171
+		$params=array();
172 172
 		foreach($this->parameters as $v)
173
-			$params[] = '<'.$v.'>';
174
-		$parameters = join($params, ' ');
175
-		$options = array();
173
+			$params[]='<'.$v.'>';
174
+		$parameters=join($params, ' ');
175
+		$options=array();
176 176
 		foreach($this->optional as $v)
177
-			$options[] = '['.$v.']';
178
-		$optional = (strlen($parameters) ? ' ' : ''). join($options, ' ');
177
+			$options[]='['.$v.']';
178
+		$optional=(strlen($parameters) ? ' ' : '').join($options, ' ');
179 179
 		$description='';
180
-		foreach(explode("\n", wordwrap($this->description,65)) as $line)
181
-			$description .= '    '.$line."\n";
180
+		foreach(explode("\n", wordwrap($this->description, 65)) as $line)
181
+			$description.='    '.$line."\n";
182 182
 		return <<<EOD
183 183
   {$this->action} {$parameters}{$optional}
184 184
 {$description}
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
 
189 189
 	protected function initializePradoApplication($directory)
190 190
 	{
191
-		$_SERVER['SCRIPT_FILENAME'] = $directory.'/index.php';
192
-		$app_dir = realpath($directory.'/protected/');
193
-		if($app_dir !== false && is_dir($app_dir))
191
+		$_SERVER['SCRIPT_FILENAME']=$directory.'/index.php';
192
+		$app_dir=realpath($directory.'/protected/');
193
+		if($app_dir!==false && is_dir($app_dir))
194 194
 		{
195 195
 			if(Prado::getApplication()===null)
196 196
 			{
197
-				$app = new PradoShellApplication($app_dir);
197
+				$app=new PradoShellApplication($app_dir);
198 198
 				$app->run();
199
-				$dir = substr(str_replace(realpath('./'),'',$app_dir),1);
199
+				$dir=substr(str_replace(realpath('./'), '', $app_dir), 1);
200 200
 				$initialized=true;
201 201
 				PradoCommandLineInterpreter::printGreeting();
202 202
 				echo '** Loaded PRADO appplication in directory "'.$dir."\".\n";
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
 		else
208 208
 		{
209 209
 			PradoCommandLineInterpreter::printGreeting();
210
-			echo '+'.str_repeat('-',77)."+\n";
210
+			echo '+'.str_repeat('-', 77)."+\n";
211 211
 			echo '** Unable to load PRADO application in directory "'.$directory."\".\n";
212
-			echo '+'.str_repeat('-',77)."+\n";
212
+			echo '+'.str_repeat('-', 77)."+\n";
213 213
 		}
214 214
 		return false;
215 215
 	}
@@ -224,10 +224,10 @@  discard block
 block discarded – undo
224 224
  */
225 225
 class PradoCommandLineCreateProject extends PradoCommandLineAction
226 226
 {
227
-	protected $action = '-c';
228
-	protected $parameters = array('directory');
229
-	protected $optional = array();
230
-	protected $description = 'Creates a Prado project skeleton for the given <directory>.';
227
+	protected $action='-c';
228
+	protected $parameters=array('directory');
229
+	protected $optional=array();
230
+	protected $description='Creates a Prado project skeleton for the given <directory>.';
231 231
 
232 232
 	public function performAction($args)
233 233
 	{
@@ -241,31 +241,31 @@  discard block
 block discarded – undo
241 241
 	 */
242 242
 	protected function createNewPradoProject($dir)
243 243
 	{
244
-		if(strlen(trim($dir)) == 0)
244
+		if(strlen(trim($dir))==0)
245 245
 			return;
246 246
 
247
-		$rootPath = realpath(dirname(trim($dir)));
247
+		$rootPath=realpath(dirname(trim($dir)));
248 248
 
249 249
 		if(basename($dir)!=='.')
250
-			$basePath = $rootPath.DIRECTORY_SEPARATOR.basename($dir);
250
+			$basePath=$rootPath.DIRECTORY_SEPARATOR.basename($dir);
251 251
 		else
252
-			$basePath = $rootPath;
253
-		$appName = basename($basePath);
254
-		$assetPath = $basePath.DIRECTORY_SEPARATOR.'assets';
255
-		$protectedPath  = $basePath.DIRECTORY_SEPARATOR.'protected';
256
-		$runtimePath = $basePath.DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.'runtime';
257
-		$pagesPath = $protectedPath.DIRECTORY_SEPARATOR.'pages';
258
-
259
-		$indexFile = $basePath.DIRECTORY_SEPARATOR.'index.php';
260
-		$htaccessFile = $protectedPath.DIRECTORY_SEPARATOR.'.htaccess';
261
-		$configFile = $protectedPath.DIRECTORY_SEPARATOR.'application.xml';
262
-		$defaultPageFile = $pagesPath.DIRECTORY_SEPARATOR.'Home.page';
252
+			$basePath=$rootPath;
253
+		$appName=basename($basePath);
254
+		$assetPath=$basePath.DIRECTORY_SEPARATOR.'assets';
255
+		$protectedPath=$basePath.DIRECTORY_SEPARATOR.'protected';
256
+		$runtimePath=$basePath.DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.'runtime';
257
+		$pagesPath=$protectedPath.DIRECTORY_SEPARATOR.'pages';
258
+
259
+		$indexFile=$basePath.DIRECTORY_SEPARATOR.'index.php';
260
+		$htaccessFile=$protectedPath.DIRECTORY_SEPARATOR.'.htaccess';
261
+		$configFile=$protectedPath.DIRECTORY_SEPARATOR.'application.xml';
262
+		$defaultPageFile=$pagesPath.DIRECTORY_SEPARATOR.'Home.page';
263 263
 
264 264
 		$this->createDirectory($basePath, 0755);
265
-		$this->createDirectory($assetPath,0777);
266
-		$this->createDirectory($protectedPath,0755);
267
-		$this->createDirectory($runtimePath,0777);
268
-		$this->createDirectory($pagesPath,0755);
265
+		$this->createDirectory($assetPath, 0777);
266
+		$this->createDirectory($protectedPath, 0755);
267
+		$this->createDirectory($runtimePath, 0777);
268
+		$this->createDirectory($pagesPath, 0755);
269 269
 
270 270
 		$this->createFile($indexFile, $this->renderIndexFile());
271 271
 		$this->createFile($configFile, $this->renderConfigFile($appName));
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 	protected function renderIndexFile()
277 277
 	{
278
-		$framework = realpath(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR.'prado.php';
278
+		$framework=realpath(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR.'prado.php';
279 279
 return '<?php
280 280
 
281 281
 $frameworkPath=\''.$framework.'\';
@@ -374,10 +374,10 @@  discard block
 block discarded – undo
374 374
  */
375 375
 class PradoCommandLineCreateTests extends PradoCommandLineAction
376 376
 {
377
-	protected $action = '-t';
378
-	protected $parameters = array('directory');
379
-	protected $optional = array();
380
-	protected $description = 'Create test fixtures in the given <directory>.';
377
+	protected $action='-t';
378
+	protected $parameters=array('directory');
379
+	protected $optional=array();
380
+	protected $description='Create test fixtures in the given <directory>.';
381 381
 
382 382
 	public function performAction($args)
383 383
 	{
@@ -388,22 +388,22 @@  discard block
 block discarded – undo
388 388
 
389 389
 	protected function createTestFixtures($dir)
390 390
 	{
391
-		if(strlen(trim($dir)) == 0)
391
+		if(strlen(trim($dir))==0)
392 392
 			return;
393 393
 
394
-		$rootPath = realpath(dirname(trim($dir)));
395
-		$basePath = $rootPath.'/'.basename($dir);
394
+		$rootPath=realpath(dirname(trim($dir)));
395
+		$basePath=$rootPath.'/'.basename($dir);
396 396
 
397
-		$tests = $basePath.'/tests';
398
-		$unit_tests = $tests.'/unit';
399
-		$functional_tests = $tests.'/functional';
397
+		$tests=$basePath.'/tests';
398
+		$unit_tests=$tests.'/unit';
399
+		$functional_tests=$tests.'/functional';
400 400
 
401
-		$this->createDirectory($tests,0755);
402
-		$this->createDirectory($unit_tests,0755);
403
-		$this->createDirectory($functional_tests,0755);
401
+		$this->createDirectory($tests, 0755);
402
+		$this->createDirectory($unit_tests, 0755);
403
+		$this->createDirectory($functional_tests, 0755);
404 404
 
405
-		$unit_test_index = $tests.'/unit.php';
406
-		$functional_test_index = $tests.'/functional.php';
405
+		$unit_test_index=$tests.'/unit.php';
406
+		$functional_test_index=$tests.'/functional.php';
407 407
 
408 408
 		$this->createFile($unit_test_index, $this->renderUnitTestFixture());
409 409
 		$this->createFile($functional_test_index, $this->renderFunctionalTestFixture());
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 
412 412
 	protected function renderUnitTestFixture()
413 413
 	{
414
-		$tester = realpath(dirname(dirname(__FILE__))).'/tests/test_tools/unit_tests.php';
414
+		$tester=realpath(dirname(dirname(__FILE__))).'/tests/test_tools/unit_tests.php';
415 415
 return '<?php
416 416
 
417 417
 include_once \''.$tester.'\';
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 
427 427
 	protected function renderFunctionalTestFixture()
428 428
 	{
429
-		$tester = realpath(dirname(dirname(__FILE__))).'/tests/test_tools/functional_tests.php';
429
+		$tester=realpath(dirname(dirname(__FILE__))).'/tests/test_tools/functional_tests.php';
430 430
 return '<?php
431 431
 
432 432
 include_once \''.$tester.'\';
@@ -448,15 +448,15 @@  discard block
 block discarded – undo
448 448
  */
449 449
 class PradoCommandLinePhpShell extends PradoCommandLineAction
450 450
 {
451
-	protected $action = 'shell';
452
-	protected $parameters = array();
453
-	protected $optional = array('directory');
454
-	protected $description = 'Runs a PHP interactive interpreter. Initializes the Prado application in the given [directory].';
451
+	protected $action='shell';
452
+	protected $parameters=array();
453
+	protected $optional=array('directory');
454
+	protected $description='Runs a PHP interactive interpreter. Initializes the Prado application in the given [directory].';
455 455
 
456 456
 	public function performAction($args)
457 457
 	{
458 458
 		if(count($args) > 1)
459
-			$app = $this->initializePradoApplication($args[1]);
459
+			$app=$this->initializePradoApplication($args[1]);
460 460
 
461 461
 		\Psy\Shell::debug([], Prado::getApplication());
462 462
 		return true;
@@ -471,23 +471,23 @@  discard block
 block discarded – undo
471 471
  */
472 472
 class PradoCommandLineActiveRecordGen extends PradoCommandLineAction
473 473
 {
474
-	protected $action = 'generate';
475
-	protected $parameters = array('table', 'output');
476
-	protected $optional = array('directory', 'soap');
477
-	protected $description = 'Generate Active Record skeleton for <table> to <output> file using application.xml in [directory]. May also generate [soap] properties.';
474
+	protected $action='generate';
475
+	protected $parameters=array('table', 'output');
476
+	protected $optional=array('directory', 'soap');
477
+	protected $description='Generate Active Record skeleton for <table> to <output> file using application.xml in [directory]. May also generate [soap] properties.';
478 478
 	private $_soap=false;
479 479
 
480 480
 	public function performAction($args)
481 481
 	{
482
-		$app_dir = count($args) > 3 ? $this->getAppDir($args[3]) : $this->getAppDir();
483
-		$this->_soap = count($args) > 4;
484
-		if($app_dir !== false)
482
+		$app_dir=count($args) > 3 ? $this->getAppDir($args[3]) : $this->getAppDir();
483
+		$this->_soap=count($args) > 4;
484
+		if($app_dir!==false)
485 485
 		{
486
-			$config = $this->getActiveRecordConfig($app_dir);
487
-			$output = $this->getOutputFile($app_dir, $args[2]);
486
+			$config=$this->getActiveRecordConfig($app_dir);
487
+			$output=$this->getOutputFile($app_dir, $args[2]);
488 488
 			if(is_file($output))
489 489
 				echo "** File $output already exists, skiping. \n";
490
-			else if($config !== false && $output !== false)
490
+			else if($config!==false && $output!==false)
491 491
 				$this->generateActiveRecord($config, $args[1], $output);
492 492
 		}
493 493
 		return true;
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 	{
498 498
 		if(is_dir($dir))
499 499
 			return realpath($dir);
500
-		if(false !== ($app_dir = realpath($dir.'/protected/')) && is_dir($app_dir))
500
+		if(false!==($app_dir=realpath($dir.'/protected/')) && is_dir($app_dir))
501 501
 			return $app_dir;
502 502
 		echo '** Unable to find directory "'.$dir."\".\n";
503 503
 		return false;
@@ -505,9 +505,9 @@  discard block
 block discarded – undo
505 505
 
506 506
 	protected function getXmlFile($app_dir)
507 507
 	{
508
-		if(false !== ($xml = realpath($app_dir.'/application.xml')) && is_file($xml))
508
+		if(false!==($xml=realpath($app_dir.'/application.xml')) && is_file($xml))
509 509
 			return $xml;
510
-		if(false !== ($xml = realpath($app_dir.'/protected/application.xml')) && is_file($xml))
510
+		if(false!==($xml=realpath($app_dir.'/protected/application.xml')) && is_file($xml))
511 511
 			return $xml;
512 512
 		echo '** Unable to find application.xml in '.$app_dir."\n";
513 513
 		return false;
@@ -515,9 +515,9 @@  discard block
 block discarded – undo
515 515
 
516 516
 	protected function getActiveRecordConfig($app_dir)
517 517
 	{
518
-		if(false === ($xml=$this->getXmlFile($app_dir)))
518
+		if(false===($xml=$this->getXmlFile($app_dir)))
519 519
 			return false;
520
-		if(false !== ($app=$this->initializePradoApplication($app_dir)))
520
+		if(false!==($app=$this->initializePradoApplication($app_dir)))
521 521
 		{
522 522
 			Prado::using('System.Data.ActiveRecord.TActiveRecordConfig');
523 523
 			foreach($app->getModules() as $module)
@@ -532,8 +532,8 @@  discard block
 block discarded – undo
532 532
 	{
533 533
 		if(is_file($namespace) && strpos($namespace, $app_dir)===0)
534 534
 				return $namespace;
535
-		$file = Prado::getPathOfNamespace($namespace, ".php");
536
-		if($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path))
535
+		$file=Prado::getPathOfNamespace($namespace, ".php");
536
+		if($file!==null && false!==($path=realpath(dirname($file))) && is_dir($path))
537 537
 		{
538 538
 			if(strpos($path, $app_dir)===0)
539 539
 				return $file;
@@ -544,24 +544,24 @@  discard block
 block discarded – undo
544 544
 
545 545
 	protected function generateActiveRecord($config, $tablename, $output)
546 546
 	{
547
-		$manager = TActiveRecordManager::getInstance();
548
-		if($connection = $manager->getDbConnection()) {
549
-			$gateway = $manager->getRecordGateway();
550
-			$tableInfo = $gateway->getTableInfo($manager->getDbConnection(), $tablename);
551
-			if(count($tableInfo->getColumns()) === 0)
547
+		$manager=TActiveRecordManager::getInstance();
548
+		if($connection=$manager->getDbConnection()) {
549
+			$gateway=$manager->getRecordGateway();
550
+			$tableInfo=$gateway->getTableInfo($manager->getDbConnection(), $tablename);
551
+			if(count($tableInfo->getColumns())===0)
552 552
 			{
553 553
 				echo '** Unable to find table or view "'.$tablename.'" in "'.$manager->getDbConnection()->getConnectionString()."\".\n";
554 554
 				return false;
555 555
 			}
556 556
 			else
557 557
 			{
558
-				$properties = array();
558
+				$properties=array();
559 559
 				foreach($tableInfo->getColumns() as $field=>$column)
560
-					$properties[] = $this->generateProperty($field,$column);
560
+					$properties[]=$this->generateProperty($field, $column);
561 561
 			}
562 562
 
563
-			$classname = basename($output, '.php');
564
-			$class = $this->generateClass($properties, $tablename, $classname);
563
+			$classname=basename($output, '.php');
564
+			$class=$this->generateClass($properties, $tablename, $classname);
565 565
 			echo "  Writing class $classname to file $output\n";
566 566
 			file_put_contents($output, $class);
567 567
 		} else {
@@ -569,14 +569,14 @@  discard block
 block discarded – undo
569 569
 		}
570 570
 	}
571 571
 
572
-	protected function generateProperty($field,$column)
572
+	protected function generateProperty($field, $column)
573 573
 	{
574
-		$prop = '';
575
-		$name = '$'.$field;
576
-		$type = $column->getPHPType();
574
+		$prop='';
575
+		$name='$'.$field;
576
+		$type=$column->getPHPType();
577 577
 		if($this->_soap)
578 578
 		{
579
-			$prop .= <<<EOD
579
+			$prop.=<<<EOD
580 580
 
581 581
 	/**
582 582
 	 * @var $type $name
@@ -585,14 +585,14 @@  discard block
 block discarded – undo
585 585
 
586 586
 EOD;
587 587
 		}
588
-		$prop .= "\tpublic $name;";
588
+		$prop.="\tpublic $name;";
589 589
 		return $prop;
590 590
 	}
591 591
 
592 592
 	protected function generateClass($properties, $tablename, $class)
593 593
 	{
594
-		$props = implode("\n", $properties);
595
-		$date = date('Y-m-d h:i:s');
594
+		$props=implode("\n", $properties);
595
+		$date=date('Y-m-d h:i:s');
596 596
 return <<<EOD
597 597
 <?php
598 598
 /**
@@ -623,38 +623,38 @@  discard block
 block discarded – undo
623 623
  */
624 624
 class PradoCommandLineActiveRecordGenAll extends PradoCommandLineAction
625 625
 {
626
-    protected $action = 'generateAll';
627
-    protected $parameters = array('output');
628
-    protected $optional = array('directory', 'soap', 'overwrite', 'prefix', 'postfix');
629
-    protected $description = "Generate Active Record skeleton for all Tables to <output> file using application.xml in [directory]. May also generate [soap] properties.\nGenerated Classes are named like the Table with optional [Prefix] and/or [Postfix]. [Overwrite] is used to overwrite existing Files.";
630
-    private $_soap = false;
631
-    private $_prefix = '';
632
-    private $_postfix = '';
633
-    private $_overwrite = false;
626
+    protected $action='generateAll';
627
+    protected $parameters=array('output');
628
+    protected $optional=array('directory', 'soap', 'overwrite', 'prefix', 'postfix');
629
+    protected $description="Generate Active Record skeleton for all Tables to <output> file using application.xml in [directory]. May also generate [soap] properties.\nGenerated Classes are named like the Table with optional [Prefix] and/or [Postfix]. [Overwrite] is used to overwrite existing Files.";
630
+    private $_soap=false;
631
+    private $_prefix='';
632
+    private $_postfix='';
633
+    private $_overwrite=false;
634 634
 
635 635
     public function performAction($args) {
636
-        $app_dir = count($args) > 2 ? $this->getAppDir($args[2]) : $this->getAppDir();
637
-        $this->_soap = count($args) > 3 ? ($args[3] == "soap" || $args[3] == "true" ? true : false) : false;
638
-        $this->_overwrite = count($args) > 4 ? ($args[4] == "overwrite" || $args[4] == "true" ? true : false) : false;
639
-        $this->_prefix = count($args) > 5 ? $args[5] : '';
640
-        $this->_postfix = count($args) > 6 ? $args[6] : '';
636
+        $app_dir=count($args) > 2 ? $this->getAppDir($args[2]) : $this->getAppDir();
637
+        $this->_soap=count($args) > 3 ? ($args[3]=="soap" || $args[3]=="true" ? true : false) : false;
638
+        $this->_overwrite=count($args) > 4 ? ($args[4]=="overwrite" || $args[4]=="true" ? true : false) : false;
639
+        $this->_prefix=count($args) > 5 ? $args[5] : '';
640
+        $this->_postfix=count($args) > 6 ? $args[6] : '';
641 641
 
642
-        if ($app_dir !== false) {
643
-            $config = $this->getActiveRecordConfig($app_dir);
642
+        if($app_dir!==false) {
643
+            $config=$this->getActiveRecordConfig($app_dir);
644 644
 
645
-            $manager = TActiveRecordManager::getInstance();
646
-            $con = $manager->getDbConnection();
647
-            $con->Active = true;
645
+            $manager=TActiveRecordManager::getInstance();
646
+            $con=$manager->getDbConnection();
647
+            $con->Active=true;
648 648
 
649 649
             switch($con->getDriverName())
650 650
            	{
651 651
 				case 'mysqli':
652 652
 				case 'mysql':
653
-					$command = $con->createCommand("SHOW TABLES");
653
+					$command=$con->createCommand("SHOW TABLES");
654 654
 					break;
655 655
 				case 'sqlite': //sqlite 3
656 656
 				case 'sqlite2': //sqlite 2
657
-					$command = $con->createCommand("SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'");
657
+					$command=$con->createCommand("SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'");
658 658
 					break;
659 659
 				case 'pgsql':
660 660
 				case 'mssql': // Mssql driver on windows hosts
@@ -667,17 +667,17 @@  discard block
 block discarded – undo
667 667
 					
668 668
            	}
669 669
 
670
-            $dataReader = $command->query();
670
+            $dataReader=$command->query();
671 671
             $dataReader->bindColumn(1, $table);
672
-            $tables = array();
673
-            while ($dataReader->read() !== false) {
674
-                $tables[] = $table;
672
+            $tables=array();
673
+            while($dataReader->read()!==false) {
674
+                $tables[]=$table;
675 675
             }
676
-            $con->Active = False;
677
-            foreach ($tables as $key => $table) {
678
-                $output = $args[1] . "." . $this->_prefix . ucfirst($table) . $this->_postfix;
679
-                if ($config !== false && $output !== false) {
680
-                    $this->generate("generate " . $table . " " . $output . " " . $this->_soap . " " . $this->_overwrite);
676
+            $con->Active=False;
677
+            foreach($tables as $key => $table) {
678
+                $output=$args[1].".".$this->_prefix.ucfirst($table).$this->_postfix;
679
+                if($config!==false && $output!==false) {
680
+                    $this->generate("generate ".$table." ".$output." ".$this->_soap." ".$this->_overwrite);
681 681
                 }
682 682
             }
683 683
         }
@@ -686,16 +686,16 @@  discard block
 block discarded – undo
686 686
 
687 687
     public function generate($l)
688 688
     {
689
-		$input = explode(" ", trim($l));
689
+		$input=explode(" ", trim($l));
690 690
 		if(count($input) > 2)
691 691
 		{
692
-			$app_dir = '.';
692
+			$app_dir='.';
693 693
 			if(Prado::getApplication()!==null)
694
-				$app_dir = dirname(Prado::getApplication()->getBasePath());
695
-			$args = array($input[0],$input[1], $input[2],$app_dir);
696
-			if(count($input)>3)
697
-				$args = array($input[0],$input[1], $input[2],$app_dir,'soap');
698
-			$cmd = new PradoCommandLineActiveRecordGen;
694
+				$app_dir=dirname(Prado::getApplication()->getBasePath());
695
+			$args=array($input[0], $input[1], $input[2], $app_dir);
696
+			if(count($input) > 3)
697
+				$args=array($input[0], $input[1], $input[2], $app_dir, 'soap');
698
+			$cmd=new PradoCommandLineActiveRecordGen;
699 699
 			$cmd->performAction($args);
700 700
 		}
701 701
 		else
@@ -705,45 +705,45 @@  discard block
 block discarded – undo
705 705
     }
706 706
 
707 707
     protected function getAppDir($dir=".") {
708
-        if (is_dir($dir))
708
+        if(is_dir($dir))
709 709
             return realpath($dir);
710
-        if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir))
710
+        if(false!==($app_dir=realpath($dir.'/protected/')) && is_dir($app_dir))
711 711
             return $app_dir;
712
-        echo '** Unable to find directory "' . $dir . "\".\n";
712
+        echo '** Unable to find directory "'.$dir."\".\n";
713 713
         return false;
714 714
     }
715 715
 
716 716
     protected function getXmlFile($app_dir) {
717
-        if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml))
717
+        if(false!==($xml=realpath($app_dir.'/application.xml')) && is_file($xml))
718 718
             return $xml;
719
-        if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml))
719
+        if(false!==($xml=realpath($app_dir.'/protected/application.xml')) && is_file($xml))
720 720
             return $xml;
721
-        echo '** Unable to find application.xml in ' . $app_dir . "\n";
721
+        echo '** Unable to find application.xml in '.$app_dir."\n";
722 722
         return false;
723 723
     }
724 724
 
725 725
     protected function getActiveRecordConfig($app_dir) {
726
-        if (false === ($xml = $this->getXmlFile($app_dir)))
726
+        if(false===($xml=$this->getXmlFile($app_dir)))
727 727
             return false;
728
-        if (false !== ($app = $this->initializePradoApplication($app_dir))) {
728
+        if(false!==($app=$this->initializePradoApplication($app_dir))) {
729 729
             Prado::using('System.Data.ActiveRecord.TActiveRecordConfig');
730
-            foreach ($app->getModules() as $module)
731
-                if ($module instanceof TActiveRecordConfig)
730
+            foreach($app->getModules() as $module)
731
+                if($module instanceof TActiveRecordConfig)
732 732
                     return $module;
733
-            echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n";
733
+            echo '** Unable to find TActiveRecordConfig module in '.$xml."\n";
734 734
         }
735 735
         return false;
736 736
     }
737 737
 
738 738
     protected function getOutputFile($app_dir, $namespace) {
739
-        if (is_file($namespace) && strpos($namespace, $app_dir) === 0)
739
+        if(is_file($namespace) && strpos($namespace, $app_dir)===0)
740 740
             return $namespace;
741
-        $file = Prado::getPathOfNamespace($namespace, "");
742
-        if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) {
743
-            if (strpos($path, $app_dir) === 0)
741
+        $file=Prado::getPathOfNamespace($namespace, "");
742
+        if($file!==null && false!==($path=realpath(dirname($file))) && is_dir($path)) {
743
+            if(strpos($path, $app_dir)===0)
744 744
                 return $file;
745 745
         }
746
-        echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n";
746
+        echo '** Output file '.$file.' must be within directory '.$app_dir."\n";
747 747
         return false;
748 748
     }
749 749
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -100,8 +100,7 @@  discard block
 block discarded – undo
100 100
 			{
101 101
 				$valid |= $action->performAction($args);
102 102
 				break;
103
-			}
104
-			else
103
+			} else
105 104
 			{
106 105
 				$valid = false;
107 106
 			}
@@ -203,8 +202,7 @@  discard block
 block discarded – undo
203 202
 			}
204 203
 
205 204
 			return Prado::getApplication();
206
-		}
207
-		else
205
+		} else
208 206
 		{
209 207
 			PradoCommandLineInterpreter::printGreeting();
210 208
 			echo '+'.str_repeat('-',77)."+\n";
@@ -552,8 +550,7 @@  discard block
 block discarded – undo
552 550
 			{
553 551
 				echo '** Unable to find table or view "'.$tablename.'" in "'.$manager->getDbConnection()->getConnectionString()."\".\n";
554 552
 				return false;
555
-			}
556
-			else
553
+			} else
557 554
 			{
558 555
 				$properties = array();
559 556
 				foreach($tableInfo->getColumns() as $field=>$column)
@@ -697,8 +694,7 @@  discard block
 block discarded – undo
697 694
 				$args = array($input[0],$input[1], $input[2],$app_dir,'soap');
698 695
 			$cmd = new PradoCommandLineActiveRecordGen;
699 696
 			$cmd->performAction($args);
700
-		}
701
-		else
697
+		} else
702 698
 		{
703 699
 			echo "\n    Usage: generate table_name Application.pages.RecordClassName\n";
704 700
 		}
Please login to merge, or discard this patch.