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


PHP Generator::generate方法代码示例

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


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

示例1: generateCode

 protected function generateCode()
 {
     $files = $this->generator->generate();
     $n = count($files);
     if ($n === 0) {
         echo "No code to be generated.\n";
         return;
     }
     echo "The following files will be generated:\n";
     $skipAll = $this->controller->interactive ? null : !$this->controller->overwrite;
     $answers = [];
     foreach ($files as $file) {
         $path = $file->getRelativePath();
         if (is_file($file->path)) {
             if (file_get_contents($file->path) === $file->content) {
                 echo '  ' . $this->controller->ansiFormat('[unchanged]', Console::FG_GREY);
                 echo $this->controller->ansiFormat(" {$path}\n", Console::FG_CYAN);
                 $answers[$file->id] = false;
             } else {
                 echo '    ' . $this->controller->ansiFormat('[changed]', Console::FG_RED);
                 echo $this->controller->ansiFormat(" {$path}\n", Console::FG_CYAN);
                 if ($skipAll !== null) {
                     $answers[$file->id] = !$skipAll;
                 } else {
                     $answer = $this->controller->select("Do you want to overwrite this file?", ['y' => 'Overwrite this file.', 'n' => 'Skip this file.', 'ya' => 'Overwrite this and the rest of the changed files.', 'na' => 'Skip this and the rest of the changed files.']);
                     $answers[$file->id] = $answer === 'y' || $answer === 'ya';
                     if ($answer === 'ya') {
                         $skipAll = false;
                     } elseif ($answer === 'na') {
                         $skipAll = true;
                     }
                 }
             }
         } else {
             echo '        ' . $this->controller->ansiFormat('[new]', Console::FG_GREEN);
             echo $this->controller->ansiFormat(" {$path}\n", Console::FG_CYAN);
             $answers[$file->id] = true;
         }
     }
     if (!array_sum($answers)) {
         $this->controller->stdout("\nNo files were chosen to be generated.\n", Console::FG_CYAN);
         return;
     }
     if (!$this->controller->confirm("\nReady to generate the selected files?", true)) {
         $this->controller->stdout("\nNo file was generated.\n", Console::FG_CYAN);
         return;
     }
     if ($this->generator->save($files, (array) $answers, $results)) {
         $this->controller->stdout("\nFiles were generated successfully!\n", Console::FG_GREEN);
     } else {
         $this->controller->stdout("\nSome errors occurred while generating the files.", Console::FG_RED);
     }
     echo preg_replace('%<span class="error">(.*?)</span>%', '\\1', $results) . "\n";
 }
开发者ID:Wookashlab,项目名称:MainRepo,代码行数:54,代码来源:GenerateAction.php


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