From c00c2dcb1ad212d3d8bcb696dc3c91202bd81fa9 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 21 Feb 2013 13:41:53 +0400 Subject: [PATCH] renamed yiic webapp -> yiic app --- framework/console/Application.php | 2 +- framework/console/controllers/AppController.php | 209 +++++++++++++++++++++ framework/console/controllers/WebappController.php | 209 --------------------- framework/console/webapp/config.php | 2 +- 4 files changed, 211 insertions(+), 211 deletions(-) create mode 100644 framework/console/controllers/AppController.php delete mode 100644 framework/console/controllers/WebappController.php diff --git a/framework/console/Application.php b/framework/console/Application.php index 537821c..11b7d11 100644 --- a/framework/console/Application.php +++ b/framework/console/Application.php @@ -126,7 +126,7 @@ class Application extends \yii\base\Application 'message' => 'yii\console\controllers\MessageController', 'help' => 'yii\console\controllers\HelpController', 'migrate' => 'yii\console\controllers\MigrateController', - 'webapp' => 'yii\console\controllers\WebappController', + 'app' => 'yii\console\controllers\AppController', 'cache' => 'yii\console\controllers\CacheController', ); } diff --git a/framework/console/controllers/AppController.php b/framework/console/controllers/AppController.php new file mode 100644 index 0000000..32dbe2e --- /dev/null +++ b/framework/console/controllers/AppController.php @@ -0,0 +1,209 @@ + + * @author Alexander Makarov + * @since 2.0 + */ +class AppController extends Controller +{ + private $_rootPath; + private $_config; + + /** + * @var string custom template path. If specified, templates will be + * searched there additionally to `framework/console/webapp`. + */ + public $templatesPath; + + /** + * @var string application type. If not specified default application + * skeleton will be used. + */ + public $type = 'default'; + + public function init() + { + parent::init(); + + if($this->templatesPath && !is_dir($this->templatesPath)) { + throw new Exception('--templatesPath "'.$this->templatesPath.'" does not exist or can not be read.'); + } + } + + public function globalOptions() + { + return array('templatesPath', 'type'); + } + + public function actionIndex() + { + $this->forward('help/index', array('-args' => array('app/create'))); + } + + /** + * Generates Yii application at the path specified via appPath parameter. + * + * @param string $path the directory where the new application will be created. + * If the directory does not exist, it will be created. After the application + * is created, please make sure the directory has enough permissions. + * + * @throws \yii\base\Exception if path specified is not valid + * @return integer the exit status + */ + public function actionCreate($path) + { + $path = strtr($path, '/\\', DIRECTORY_SEPARATOR); + if(strpos($path, DIRECTORY_SEPARATOR) === false) { + $path = '.'.DIRECTORY_SEPARATOR.$path; + } + $dir = rtrim(realpath(dirname($path)), '\\/'); + if($dir === false || !is_dir($dir)) { + throw new Exception("The directory '$path' is not valid. Please make sure the parent directory exists."); + } + + if(basename($path) === '.') { + $this->_rootPath = $path = $dir; + } + else { + $this->_rootPath = $path = $dir.DIRECTORY_SEPARATOR.basename($path); + } + + if($this->confirm("Create \"$this->type\" application under '$path'?")) { + $sourceDir = $this->getSourceDir(); + $config = $this->getConfig(); + + $list = FileHelper::buildFileList($sourceDir, $path); + + if(is_array($config)) { + foreach($config as $file => $settings) { + if(isset($settings['handler'])) { + $list[$file]['callback'] = $settings['handler']; + } + } + } + + FileHelper::copyFiles($list); + + if(is_array($config)) { + foreach($config as $file => $settings) { + if(isset($settings['permissions'])) { + @chmod($path.'/'.$file, $settings['permissions']); + } + } + } + + echo "\nYour application has been created successfully under {$path}.\n"; + } + } + + /** + * @throws \yii\base\Exception if source directory wasn't located + * @return string + */ + protected function getSourceDir() + { + $customSource = realpath($this->templatesPath.'/'.$this->type); + $defaultSource = realpath($this->getDefaultTemplatesPath().'/'.$this->type); + + if($customSource) { + return $customSource; + } + elseif($defaultSource) { + return $defaultSource; + } + else { + throw new Exception('Unable to locate the source directory for "'.$this->type.'".'); + } + } + + /** + * @return string default templates path + */ + protected function getDefaultTemplatesPath() + { + return realpath(__DIR__.'/../webapp'); + } + + /** + * @return array|null template configuration + */ + protected function getConfig() + { + if($this->_config===null) { + $this->_config = require $this->getDefaultTemplatesPath().'/config.php'; + if($this->templatesPath && file_exists($this->templatesPath)) { + $this->_config = array_merge($this->_config, require $this->templatesPath.'/config.php'); + } + } + if(isset($this->_config[$this->type])) { + return $this->_config[$this->type]; + } + } + + /** + * @param string $source path to source file + * @param string $pathTo path to file we want to get relative path for + * @param string $varName variable name w/o $ to replace value with relative path for + * + * @return string target file contetns + */ + public function replaceRelativePath($source, $pathTo, $varName) + { + $content = file_get_contents($source); + $relativeFile = str_replace($this->getSourceDir(), '', $source); + + $relativePath = $this->getRelativePath($pathTo, $this->_rootPath.$relativeFile); + $relativePath = str_replace('\\', '\\\\', $relativePath); + + return preg_replace('/\$'.$varName.'\s*=(.*?);/', "\$".$varName."=$relativePath;", $content); + } + + /** + * @param string $path1 absolute path + * @param string $path2 absolute path + * + * @return string relative path + */ + protected function getRelativePath($path1, $path2) + { + $segs1 = explode(DIRECTORY_SEPARATOR, $path1); + $segs2 = explode(DIRECTORY_SEPARATOR, $path2); + $n1 = count($segs1); + $n2 = count($segs2); + + for($i=0; $i<$n1 && $i<$n2; ++$i) { + if($segs1[$i] !== $segs2[$i]) { + break; + } + } + + if($i===0) { + return "'".$path1."'"; + } + $up=''; + for($j=$i;$j<$n2-1;++$j) { + $up.='/..'; + } + for(; $i<$n1-1; ++$i) { + $up.='/'.$segs1[$i]; + } + + return '__DIR__.\''.$up.'/'.basename($path1).'\''; + } +} \ No newline at end of file diff --git a/framework/console/controllers/WebappController.php b/framework/console/controllers/WebappController.php deleted file mode 100644 index c19eff3..0000000 --- a/framework/console/controllers/WebappController.php +++ /dev/null @@ -1,209 +0,0 @@ - - * @author Alexander Makarov - * @since 2.0 - */ -class WebappController extends Controller -{ - private $_rootPath; - private $_config; - - /** - * @var string custom template path. If specified, templates will be - * searched there additionally to `framework/console/webapp`. - */ - public $templatesPath; - - /** - * @var string application type. If not specified default application - * skeleton will be used. - */ - public $type = 'default'; - - public function init() - { - parent::init(); - - if($this->templatesPath && !is_dir($this->templatesPath)) { - throw new Exception('--templatesPath "'.$this->templatesPath.'" does not exist or can not be read.'); - } - } - - public function globalOptions() - { - return array('templatesPath', 'type'); - } - - public function actionIndex() - { - $this->forward('help/index', array('-args' => array('webapp/create'))); - } - - /** - * Generates Yii application at the path specified via appPath parameter. - * - * @param string $path the directory where the new application will be created. - * If the directory does not exist, it will be created. After the application - * is created, please make sure the directory has enough permissions. - * - * @throws \yii\base\Exception if path specified is not valid - * @return integer the exit status - */ - public function actionCreate($path) - { - $path = strtr($path, '/\\', DIRECTORY_SEPARATOR); - if(strpos($path, DIRECTORY_SEPARATOR) === false) { - $path = '.'.DIRECTORY_SEPARATOR.$path; - } - $dir = rtrim(realpath(dirname($path)), '\\/'); - if($dir === false || !is_dir($dir)) { - throw new Exception("The directory '$path' is not valid. Please make sure the parent directory exists."); - } - - if(basename($path) === '.') { - $this->_rootPath = $path = $dir; - } - else { - $this->_rootPath = $path = $dir.DIRECTORY_SEPARATOR.basename($path); - } - - if($this->confirm("Create \"$this->type\" application under '$path'?")) { - $sourceDir = $this->getSourceDir(); - $config = $this->getConfig(); - - $list = FileHelper::buildFileList($sourceDir, $path); - - if(is_array($config)) { - foreach($config as $file => $settings) { - if(isset($settings['handler'])) { - $list[$file]['callback'] = $settings['handler']; - } - } - } - - FileHelper::copyFiles($list); - - if(is_array($config)) { - foreach($config as $file => $settings) { - if(isset($settings['permissions'])) { - @chmod($path.'/'.$file, $settings['permissions']); - } - } - } - - echo "\nYour application has been created successfully under {$path}.\n"; - } - } - - /** - * @throws \yii\base\Exception if source directory wasn't located - * @return string - */ - protected function getSourceDir() - { - $customSource = realpath($this->templatesPath.'/'.$this->type); - $defaultSource = realpath($this->getDefaultTemplatesPath().'/'.$this->type); - - if($customSource) { - return $customSource; - } - elseif($defaultSource) { - return $defaultSource; - } - else { - throw new Exception('Unable to locate the source directory for "'.$this->type.'".'); - } - } - - /** - * @return string default templates path - */ - protected function getDefaultTemplatesPath() - { - return realpath(__DIR__.'/../webapp'); - } - - /** - * @return array|null template configuration - */ - protected function getConfig() - { - if($this->_config===null) { - $this->_config = require $this->getDefaultTemplatesPath().'/config.php'; - if($this->templatesPath && file_exists($this->templatesPath)) { - $this->_config = array_merge($this->_config, require $this->templatesPath.'/config.php'); - } - } - if(isset($this->_config[$this->type])) { - return $this->_config[$this->type]; - } - } - - /** - * @param string $source path to source file - * @param string $pathTo path to file we want to get relative path for - * @param string $varName variable name w/o $ to replace value with relative path for - * - * @return string target file contetns - */ - public function replaceRelativePath($source, $pathTo, $varName) - { - $content = file_get_contents($source); - $relativeFile = str_replace($this->getSourceDir(), '', $source); - - $relativePath = $this->getRelativePath($pathTo, $this->_rootPath.$relativeFile); - $relativePath = str_replace('\\', '\\\\', $relativePath); - - return preg_replace('/\$'.$varName.'\s*=(.*?);/', "\$".$varName."=$relativePath;", $content); - } - - /** - * @param string $path1 absolute path - * @param string $path2 absolute path - * - * @return string relative path - */ - protected function getRelativePath($path1, $path2) - { - $segs1 = explode(DIRECTORY_SEPARATOR, $path1); - $segs2 = explode(DIRECTORY_SEPARATOR, $path2); - $n1 = count($segs1); - $n2 = count($segs2); - - for($i=0; $i<$n1 && $i<$n2; ++$i) { - if($segs1[$i] !== $segs2[$i]) { - break; - } - } - - if($i===0) { - return "'".$path1."'"; - } - $up=''; - for($j=$i;$j<$n2-1;++$j) { - $up.='/..'; - } - for(; $i<$n1-1; ++$i) { - $up.='/'.$segs1[$i]; - } - - return '__DIR__.\''.$up.'/'.basename($path1).'\''; - } -} \ No newline at end of file diff --git a/framework/console/webapp/config.php b/framework/console/webapp/config.php index 6a8d28a..112fb18 100644 --- a/framework/console/webapp/config.php +++ b/framework/console/webapp/config.php @@ -1,5 +1,5 @@