当前位置: 首页>>代码示例>>PHP>>正文


PHP Console::clearScreenBeforeCursor方法代码示例

本文整理汇总了PHP中yii\helpers\Console::clearScreenBeforeCursor方法的典型用法代码示例。如果您正苦于以下问题:PHP Console::clearScreenBeforeCursor方法的具体用法?PHP Console::clearScreenBeforeCursor怎么用?PHP Console::clearScreenBeforeCursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\Console的用法示例。


在下文中一共展示了Console::clearScreenBeforeCursor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * Create a new frontend/admin module.
  *
  * @return number
  */
 public function actionCreate()
 {
     Console::clearScreenBeforeCursor();
     $moduleName = $this->prompt("Enter the name of the module you like to generate:");
     $newName = preg_replace("/[^a-z]/", "", strtolower($moduleName));
     if ($newName !== $moduleName) {
         if (!$this->confirm("We have changed the name to '{$newName}'. Do you want to proceed with this name?")) {
             return $this->outputError('Abort by user.');
         } else {
             $moduleName = $newName;
         }
     }
     $appModulesFolder = Yii::$app->basePath . DIRECTORY_SEPARATOR . 'modules';
     $moduleFolder = $appModulesFolder . DIRECTORY_SEPARATOR . $moduleName;
     if (file_exists($moduleFolder)) {
         return $this->outputError("The folder " . $moduleFolder . " exists already.");
     }
     $folders = ['basePath' => $moduleFolder, 'adminPath' => $moduleFolder . DIRECTORY_SEPARATOR . 'admin', 'adminPath' => $moduleFolder . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'aws', 'frontendPath' => $moduleFolder . DIRECTORY_SEPARATOR . 'frontend', 'blocksPath' => $moduleFolder . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'blocks', 'blocksPath' => $moduleFolder . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'controllers', 'blocksPath' => $moduleFolder . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'views', 'modelsPath' => $moduleFolder . DIRECTORY_SEPARATOR . 'models'];
     $ns = 'app\\modules\\' . $moduleName;
     foreach ($folders as $folder) {
         FileHelper::createDirectory($folder);
     }
     $contents = [$moduleFolder . DIRECTORY_SEPARATOR . 'README.md' => $this->renderReadme($folders, $moduleName, $ns), $moduleFolder . DIRECTORY_SEPARATOR . 'admin/Module.php' => $this->renderAdmin($folders, $moduleName, $ns), $moduleFolder . DIRECTORY_SEPARATOR . 'frontend/Module.php' => $this->renderFrontend($folders, $moduleName, $ns)];
     foreach ($contents as $fileName => $content) {
         FileHelper::writeFile($fileName, $content);
     }
     return $this->outputSuccess("Module files has been created successfull. Check the README file to understand how to added the module to your config.");
 }
开发者ID:luyadev,项目名称:luya-core,代码行数:33,代码来源:ModuleController.php

示例2: testStripAnsiFormat

 public function testStripAnsiFormat()
 {
     ob_start();
     ob_implicit_flush(false);
     echo 'a';
     Console::moveCursorForward(1);
     echo 'a';
     Console::moveCursorDown(1);
     echo 'a';
     Console::moveCursorUp(1);
     echo 'a';
     Console::moveCursorBackward(1);
     echo 'a';
     Console::moveCursorNextLine(1);
     echo 'a';
     Console::moveCursorPrevLine(1);
     echo 'a';
     Console::moveCursorTo(1);
     echo 'a';
     Console::moveCursorTo(1, 2);
     echo 'a';
     Console::clearLine();
     echo 'a';
     Console::clearLineAfterCursor();
     echo 'a';
     Console::clearLineBeforeCursor();
     echo 'a';
     Console::clearScreen();
     echo 'a';
     Console::clearScreenAfterCursor();
     echo 'a';
     Console::clearScreenBeforeCursor();
     echo 'a';
     Console::scrollDown();
     echo 'a';
     Console::scrollUp();
     echo 'a';
     Console::hideCursor();
     echo 'a';
     Console::showCursor();
     echo 'a';
     Console::saveCursorPosition();
     echo 'a';
     Console::restoreCursorPosition();
     echo 'a';
     Console::beginAnsiFormat([Console::FG_GREEN, Console::BG_BLUE, Console::UNDERLINE]);
     echo 'a';
     Console::endAnsiFormat();
     echo 'a';
     Console::beginAnsiFormat([Console::xtermBgColor(128), Console::xtermFgColor(55)]);
     echo 'a';
     Console::endAnsiFormat();
     echo 'a';
     $ouput = Console::stripAnsiFormat(ob_get_clean());
     ob_implicit_flush(true);
     // $output = str_replace("\033", 'X003', $ouput );// uncomment for debugging
     $this->assertEquals(str_repeat('a', 25), $ouput);
 }
开发者ID:rajanishtimes,项目名称:basicyii,代码行数:58,代码来源:ConsoleTest.php

示例3: actionCreate

 public function actionCreate()
 {
     Console::clearScreenBeforeCursor();
     $moduleType = $this->select('What kind of Module you want to create?', ['frontend' => 'Frontend Modules are mainly used to render views.', 'admin' => 'Admin Modules are mainly used when you Data-Managment should be done inside the Administration area.']);
     switch ($moduleType) {
         case 'admin':
             $isAdmin = true;
             $text = 'Name of your new Admin-Module (e.g. newsadmin)';
             break;
         case 'frontend':
             $isAdmin = false;
             $text = 'Name of your new Frontend-Module (e.g. news)';
             break;
     }
     $moduleName = $this->prompt($text);
     if ($isAdmin && substr($moduleName, -5) !== 'admin') {
         echo $this->ansiFormat("The provided Modulename ({$moduleName}) must have the suffix 'admin' as it is an Admin-Module!", Console::FG_RED) . PHP_EOL;
         exit(1);
     }
     if (!$this->confirm('Are you sure you want to create the ' . ($isAdmin ? 'Admin' : 'Frontend') . " Module '" . $moduleName . "' now?")) {
         exit(1);
     }
     $basePath = Yii::$app->basePath;
     $modulesDir = $basePath . DIRECTORY_SEPARATOR . 'modules';
     if (!file_exists($modulesDir)) {
         mkdir($modulesDir);
     }
     $moduleDir = $modulesDir . DIRECTORY_SEPARATOR . $moduleName;
     if (!file_exists($moduleDir)) {
         mkdir($moduleDir);
     } else {
         echo $this->ansiFormat("The Module '{$moduleName}' folder already exists!", Console::FG_RED) . PHP_EOL;
         exit(1);
     }
     $content = '<?php' . PHP_EOL;
     $content .= 'namespace app\\modules\\' . $moduleName . ';' . PHP_EOL . PHP_EOL;
     $content .= 'class Module extends ' . ($isAdmin ? '\\admin\\base\\Module' : 'luya\\base\\Module') . PHP_EOL;
     $content .= '{' . PHP_EOL;
     $content .= '    // add your custom Module properties here.' . PHP_EOL;
     $content .= '}';
     $modulephp = $moduleDir . DIRECTORY_SEPARATOR . 'Module.php';
     if (file_put_contents($modulephp, $content)) {
         $out = PHP_EOL . "'modules' => [" . PHP_EOL;
         $out .= "    '{$moduleName}' => [" . PHP_EOL;
         $out .= "        'class' => '\\app\\modules\\{$moduleName}\\Module'" . PHP_EOL;
         $out .= '    ],' . PHP_EOL;
         $out .= ']' . PHP_EOL . PHP_EOL;
         echo $this->ansiFormat($out, Console::FG_GREEN);
         exit(0);
     } else {
         echo $this->ansiFormat("Unable to write file: '" . $modulephp . "'", Console::FG_RED) . PHP_EOL;
         exit(1);
     }
 }
开发者ID:efueger,项目名称:luya,代码行数:54,代码来源:ModuleController.php

示例4: actionIndex

 public function actionIndex()
 {
     $error = false;
     Console::clearScreenBeforeCursor();
     @chdir(Yii::getAlias('@app'));
     $this->output('The directory the health commands is applying to: ' . Yii::getAlias('@app'));
     foreach ($this->folders as $folder => $writable) {
         if (!file_exists($folder)) {
             $mode = $writable ? 0777 : 0775;
             if (FileHelper::createDirectory($folder, $mode)) {
                 $this->outputSuccess("{$folder}: successfully created directory");
             } else {
                 $error = true;
                 $this->outputError("{$folder}: unable to create directory");
             }
         } else {
             $this->outputInfo("{$folder}: directory exists already");
         }
         if ($writable && !is_writable($folder)) {
             $this->outputInfo("{$folder}: is not writeable, try to set mode '{$mode}'.");
             @chmod($folder, $mode);
         }
         if ($writable) {
             if (!is_writable($folder)) {
                 $error = true;
                 $this->outputError("{$folder}: is not writable, please change permissions.");
             }
         }
     }
     foreach ($this->files as $file) {
         if (file_exists($file)) {
             $this->outputInfo("{$file}: file exists.");
         } else {
             $error = true;
             $this->outputError("{$file}: file does not exists!");
         }
     }
     return $error ? $this->outputError('Health check found errors!') : $this->outputSuccess('O.K.');
 }
开发者ID:boehsermoe,项目名称:luya,代码行数:39,代码来源:HealthController.php

示例5: actionCreate

 /**
  * Wizzard to create a new CMS block.
  *
  * @return number
  */
 public function actionCreate()
 {
     if (empty($this->type)) {
         Console::clearScreenBeforeCursor();
         $this->type = $this->select('Do you want to create an app or module Block?', [self::TYPE_APP => 'Creates a project block inside your @app Namespace (casual).', self::TYPE_MODULE => 'Creating a block inside a later specified Module.']);
     }
     if ($this->type == self::TYPE_MODULE && count($this->getModuleProposal()) === 0) {
         return $this->outputError('Your project does not have Project-Modules registered!');
     }
     if (empty($this->moduleName) && $this->type == self::TYPE_MODULE) {
         $this->moduleName = $this->select('Choose a module to create the block inside:', $this->getModuleProposal());
     }
     if (empty($this->blockName)) {
         $this->blockName = $this->prompt('Insert a name for your Block (e.g. HeadTeaser):', ['required' => true]);
     }
     if ($this->isContainer === null) {
         $this->isContainer = $this->confirm("Do you want to add placeholders to your block that serve as a container for nested blocks?", false);
     }
     if ($this->cacheEnabled === null) {
         $this->cacheEnabled = $this->confirm("Do you want to enable the caching for this block or not?", true);
     }
     if ($this->config === null) {
         $this->config = ['vars' => [], 'cfgs' => [], 'placeholders' => []];
         $doConfigure = $this->confirm('Would you like to configure this Block? (vars, cfgs, placeholders)', false);
         if ($doConfigure) {
             $doVars = $this->confirm('Add new Variable (vars)?', false);
             $i = 1;
             while ($doVars) {
                 $item = $this->varCreator('Variabel (vars) #' . $i, 'var');
                 $this->phpdoc[] = '{{vars.' . $item['var'] . '}}';
                 $this->viewFileDoc[] = '$this->varValue(\'' . $item['var'] . '\');';
                 $this->config['vars'][] = $item;
                 $doVars = $this->confirm('Add one more?', false);
                 ++$i;
             }
             $doCfgs = $this->confirm('Add new Configuration (cgfs)?', false);
             $i = 1;
             while ($doCfgs) {
                 $item = $this->varCreator('Configration (cfgs) #' . $i, 'cfg');
                 $this->phpdoc[] = '{{cfgs.' . $item['var'] . '}}';
                 $this->viewFileDoc[] = '$this->cfgValue(\'' . $item['var'] . '\');';
                 $this->config['cfgs'][] = $item;
                 $doCfgs = $this->confirm('Add one more?', false);
                 ++$i;
             }
             $doPlaceholders = $this->confirm('Add new Placeholder (placeholders)?', false);
             $i = 1;
             while ($doPlaceholders) {
                 $item = $this->placeholderCreator('Placeholder (placeholders) #' . $i);
                 $this->phpdoc[] = '{{placeholders.' . $item['var'] . '}}';
                 $this->viewFileDoc[] = '$this->placeholderValue(\'' . $item['var'] . '\');';
                 $this->config['placeholders'][] = $item;
                 $doPlaceholders = $this->confirm('Add one more?', false);
                 ++$i;
             }
         }
     }
     $folder = $this->getFileBasePath() . DIRECTORY_SEPARATOR . 'blocks';
     $filePath = $folder . DIRECTORY_SEPARATOR . $this->blockName . '.php';
     sort($this->phpdoc);
     $content = $this->view->render('@luya/console/commands/views/block/create_block.php', ['namespace' => $this->getFileNamespace(), 'className' => $this->blockName, 'name' => Inflector::camel2words($this->blockName), 'type' => $this->type, 'module' => $this->moduleName, 'isContainer' => $this->isContainer, 'cacheEnabled' => $this->cacheEnabled, 'config' => $this->config, 'phpdoc' => $this->phpdoc, 'extras' => $this->extras, 'luyaText' => $this->getGeneratorText('block/create')]);
     if ($this->dryRun) {
         return $content;
     }
     if (FileHelper::createDirectory($folder) && FileHelper::writeFile($filePath, $content)) {
         // generate view file based on block object view context
         $object = Yii::createObject(['class' => $this->getFileNamespace() . '\\' . $this->blockName]);
         $viewsFolder = Yii::getAlias($object->getViewPath());
         $viewFilePath = $viewsFolder . DIRECTORY_SEPARATOR . $object->getViewFileName('php');
         if (FileHelper::createDirectory($viewsFolder) && FileHelper::writeFile($viewFilePath, $this->generateViewFile($this->blockName))) {
             $this->outputInfo('View file for the block has been created: ' . $viewFilePath);
         }
         return $this->outputSuccess("Block {$this->blockName} has been created: " . $filePath);
     }
     return $this->outputError("Error while creating block '{$filePath}'");
 }
开发者ID:luyadev,项目名称:luya-core,代码行数:81,代码来源:BlockController.php

示例6: actionCreate

 /**
  * Create Ng-Rest-Model, Controller and Api for an existing Database-Table.
  *
  * @return number
  */
 public function actionCreate()
 {
     if ($this->moduleName === null) {
         Console::clearScreenBeforeCursor();
         $this->moduleName = $this->selectModule(['onlyAdmin' => true, 'hideCore' => true, 'text' => 'Select the Module where the CRUD files should be saved:']);
     }
     if ($this->modelName === null) {
         $modelSelection = true;
         while ($modelSelection) {
             $modelName = $this->prompt('Model Name (e.g. Album):', ['required' => true]);
             $camlizeModelName = Inflector::camelize($modelName);
             if ($modelName !== $camlizeModelName) {
                 if ($this->confirm("We have camlized the model name to '{$camlizeModelName}' do you want to continue with this name?")) {
                     $modelName = $camlizeModelName;
                     $modelSelection = false;
                 }
             } else {
                 $modelSelection = false;
             }
             $this->modelName = $modelName;
         }
     }
     if ($this->apiEndpoint === null) {
         $this->apiEndpoint = $this->prompt('Api Endpoint:', ['required' => true, 'default' => $this->getApiEndpointSuggestion()]);
     }
     if ($this->dbTableName === null) {
         $sqlSelection = true;
         while ($sqlSelection) {
             $sqlTable = $this->prompt('Database Table name for the Model:', ['required' => true, 'default' => $this->getDatabaseNameSuggestion()]);
             if ($sqlTable == '?') {
                 foreach ($this->getSqlTablesArray() as $table) {
                     $this->outputInfo("- " . $table);
                 }
             }
             if (isset($this->getSqlTablesArray()[$sqlTable])) {
                 $this->dbTableName = $sqlTable;
                 $sqlSelection = false;
             } else {
                 $this->outputError("The selected database '{$sqlTable}' does not exists in the list of tables. Type '?' to see all tables.");
             }
         }
     }
     if ($this->enableI18n === null) {
         $this->enableI18n = $this->confirm("Would you like to enable i18n field input for text fields? Only required for multilingual pages.");
     }
     $this->ensureBasePathAndNamespace();
     $files = [];
     // api content
     $files['api'] = ['path' => $this->getBasePath() . DIRECTORY_SEPARATOR . 'apis', 'fileName' => $this->getModelNameCamlized() . 'Controller.php', 'content' => $this->generateApiContent($this->getNamespace() . '\\apis', $this->getModelNameCamlized() . 'Controller', $this->getAbsoluteModelNamespace())];
     // controller
     $files['controller'] = ['path' => $this->getBasePath() . DIRECTORY_SEPARATOR . 'controllers', 'fileName' => $this->getModelNameCamlized() . 'Controller.php', 'content' => $this->generateControllerContent($this->getNamespace() . '\\controllers', $this->getModelNameCamlized() . 'Controller', $this->getAbsoluteModelNamespace())];
     // model
     $files['model'] = ['path' => $this->getModelBasePath() . DIRECTORY_SEPARATOR . 'models', 'fileName' => $this->getModelNameCamlized() . '.php', 'content' => $this->generateModelContent($this->getModelNamespace() . '\\models', $this->getModelNameCamlized(), $this->apiEndpoint, $this->getDbTableShema(), $this->enableI18n)];
     foreach ($files as $file) {
         FileHelper::createDirectory($file['path']);
         if (file_exists($file['path'] . DIRECTORY_SEPARATOR . $file['fileName'])) {
             if (!$this->confirm("The File '{$file['fileName']}' already exists, do you want to override the existing file?")) {
                 continue;
             }
         }
         if (FileHelper::writeFile($file['path'] . DIRECTORY_SEPARATOR . $file['fileName'], $file['content'])) {
             $this->outputSuccess("Wrote file '{$file['fileName']}'.");
         } else {
             $this->outputError("Error while writing file '{$file['fileName']}'.");
         }
     }
     return $this->outputSuccess($this->generateBuildSummery($this->apiEndpoint, $this->getNamespace() . '\\apis\\' . $this->getModelNameCamlized() . 'Controller', $this->getModelNameCamlized(), $this->getSummaryControllerRoute()));
 }
开发者ID:luyadev,项目名称:luya-core,代码行数:73,代码来源:CrudController.php


注:本文中的yii\helpers\Console::clearScreenBeforeCursor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。