Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Enh #584: Refactored WebAppCommand to be more customizable, added mor…

…e PHPDoc
  • Loading branch information...
commit bf3c1f7d50ebbd05a79e209c1e270777d31f8fac 1 parent e9c5d98
@samdark samdark authored
Showing with 68 additions and 11 deletions.
  1. +1 −0  CHANGELOG
  2. +67 −11 framework/cli/commands/WebAppCommand.php
View
1  CHANGELOG
@@ -56,6 +56,7 @@ Version 1.1.11 work in progress
- Enh #568: CHtml::getIdByName() will now convert spaces to underscore to get proper ID for HTML elements (mdomba)
- Enh #578: Added extension checks to CMemCache (samdark)
- Enh #581: Added formatSize method in CFormatter to format file sizes into units of different order - KB, MB, etc (brilyuhns, samdark)
+- Enh #584: Refactored WebAppCommand to be more customizable, added more PHPDoc (samdark)
- Enh #599: Added case sensitivity check when autoloading classes (qiangxue)
- Enh #601: added the method loginRequired() to the IWebUser interface (mdomba)
- Enh #616: CVarDumper is now correctly highligting integer array keys (vernes, samdark)
View
78 framework/cli/commands/WebAppCommand.php
@@ -40,7 +40,7 @@ public function getHelp()
/**
* Execute the action.
- * @param array command line parameters specific for this command
+ * @param array $args command line parameters specific for this command
*/
public function run($args)
{
@@ -60,24 +60,59 @@ public function run($args)
$this->_rootPath=$path=$dir.DIRECTORY_SEPARATOR.basename($path);
if($this->confirm("Create a Web application under '$path'?"))
{
- $sourceDir=realpath(dirname(__FILE__).'/../views/webapp');
+ $sourceDir=$this->getSourceDir();
if($sourceDir===false)
die("\nUnable to locate the source directory.\n");
$list=$this->buildFileList($sourceDir,$path);
- $list['index.php']['callback']=array($this,'generateIndex');
- $list['index-test.php']['callback']=array($this,'generateIndex');
- $list['protected/tests/bootstrap.php']['callback']=array($this,'generateTestBoostrap');
- $list['protected/yiic.php']['callback']=array($this,'generateYiic');
+ $this->addFileModificationCallbacks($list);
$this->copyFiles($list);
- @chmod($path.'/assets',0777);
- @chmod($path.'/protected/runtime',0777);
- @chmod($path.'/protected/data',0777);
- @chmod($path.'/protected/data/testdrive.db',0777);
- @chmod($path.'/protected/yiic',0755);
+ $this->setPermissions($path);
echo "\nYour application has been created successfully under {$path}.\n";
}
}
+ /**
+ * Adjusts created application file and directory permissions
+ *
+ * @param string $targetDir path to created application
+ */
+ protected function setPermissions($targetDir)
+ {
+ @chmod($targetDir.'/assets',0777);
+ @chmod($targetDir.'/protected/runtime',0777);
+ @chmod($targetDir.'/protected/data',0777);
+ @chmod($targetDir.'/protected/data/testdrive.db',0777);
+ @chmod($targetDir.'/protected/yiic',0755);
+ }
+
+ /**
+ * @return string path to application bootstrap source files
+ */
+ protected function getSourceDir()
+ {
+ return realpath(dirname(__FILE__).'/../views/webapp');
+ }
+
+ /**
+ * Adds callbacks that will modify source files
+ *
+ * @param array $fileList
+ */
+ protected function addFileModificationCallbacks(&$fileList)
+ {
+ $fileList['index.php']['callback']=array($this,'generateIndex');
+ $fileList['index-test.php']['callback']=array($this,'generateIndex');
+ $fileList['protected/tests/bootstrap.php']['callback']=array($this,'generateTestBoostrap');
+ $fileList['protected/yiic.php']['callback']=array($this,'generateYiic');
+ }
+
+ /**
+ * Inserts path to framework's yii.php into application's index.php
+ *
+ * @param string $source source file path
+ * @param array $params
+ * @return string modified source file content
+ */
public function generateIndex($source,$params)
{
$content=file_get_contents($source);
@@ -87,6 +122,13 @@ public function generateIndex($source,$params)
return preg_replace('/\$yii\s*=(.*?);/',"\$yii=$yii;",$content);
}
+ /**
+ * Inserts path to framework's yiit.php into application's index-test.php
+ *
+ * @param string $source source file path
+ * @param array $params
+ * @return string modified source file content
+ */
public function generateTestBoostrap($source,$params)
{
$content=file_get_contents($source);
@@ -96,6 +138,13 @@ public function generateTestBoostrap($source,$params)
return preg_replace('/\$yiit\s*=(.*?);/',"\$yiit=$yii;",$content);
}
+ /**
+ * Inserts path to framework's yiic.php into application's yiic.php
+ *
+ * @param string $source source file path
+ * @param array $params
+ * @return string modified source file content
+ */
public function generateYiic($source,$params)
{
$content=file_get_contents($source);
@@ -105,6 +154,13 @@ public function generateYiic($source,$params)
return preg_replace('/\$yiic\s*=(.*?);/',"\$yiic=$yiic;",$content);
}
+ /**
+ * Returns variant of $path1 relative to $path2
+ *
+ * @param string $path1
+ * @param string $path2
+ * @return string $path1 relative to $path2
+ */
protected function getRelativePath($path1,$path2)
{
$segs1=explode(DIRECTORY_SEPARATOR,$path1);
Please sign in to comment.
Something went wrong with that request. Please try again.