コード例 #1
0
 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";
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $stickyAttributes = $this->model->stickyAttributes();
     if (in_array($this->attribute, $stickyAttributes)) {
         $this->sticky();
     }
     $hints = $this->model->hints();
     if (isset($hints[$this->attribute])) {
         $this->hint($hints[$this->attribute]);
     }
     $autoCompleteData = $this->model->autoCompleteData();
     if (isset($autoCompleteData[$this->attribute])) {
         if (is_callable($autoCompleteData[$this->attribute])) {
             $this->autoComplete(call_user_func($autoCompleteData[$this->attribute]));
         } else {
             $this->autoComplete($autoCompleteData[$this->attribute]);
         }
     }
 }
コード例 #3
0
 /**
  * Loads the generator with the specified ID.
  * @param string $id the ID of the generator to be loaded.
  * @return \app\modules\admgii\Generator the loaded generator
  * @throws NotFoundHttpException
  */
 protected function loadGenerator($id)
 {
     if (isset($this->module->generators[$id])) {
         $this->generator = $this->module->generators[$id];
         $this->generator->loadStickyAttributes();
         $this->generator->load($_POST);
         return $this->generator;
     } else {
         throw new NotFoundHttpException("Code generator not found: {$id}");
     }
 }
コード例 #4
0
ファイル: Generator.php プロジェクト: pavlinter/yii2-adm-app
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['vendorName', 'packageName'], 'filter', 'filter' => 'trim'], [['vendorName', 'packageName', 'namespace', 'type', 'license', 'title', 'description', 'authorName', 'authorEmail', 'outputPath'], 'required'], [['keywords'], 'safe'], [['authorEmail'], 'email'], [['vendorName', 'packageName'], 'match', 'pattern' => '/^[a-z0-9\\-\\.]+$/', 'message' => 'Only lowercase word characters, dashes and dots are allowed.'], [['namespace'], 'match', 'pattern' => '/^[a-zA-Z0-9\\\\]+\\\\$/', 'message' => 'Only letters, numbers and backslashes are allowed. PSR-4 namespaces must end with a namespace separator.']]);
 }
コード例 #5
0
ファイル: Generator.php プロジェクト: pavlinter/yii2-adm-app
 /**
  * @inheritdoc
  */
 public function hints()
 {
     return array_merge(parent::hints(), ['modelClass' => 'This is the model class for collecting the form input. You should provide a fully qualified class name, e.g., <code>app\\models\\Post</code>.', 'viewName' => 'This is the view name with respect to the view path. For example, <code>site/index</code> would generate a <code>site/index.php</code> view file under the view path.', 'viewPath' => 'This is the root view path to keep the generated view files. You may provide either a directory or a path alias, e.g., <code>@app/views</code>.', 'scenarioName' => 'This is the scenario to be used by the model when collecting the form input. If empty, the default scenario will be used.']);
 }
コード例 #6
0
ファイル: Generator.php プロジェクト: pavlinter/yii2-adm-app
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['baseControllerClass', 'moduleID', 'indexWidgetType']);
 }
コード例 #7
0
ファイル: Generator.php プロジェクト: pavlinter/yii2-adm-app
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments']);
 }
コード例 #8
0
ファイル: Generator.php プロジェクト: pavlinter/yii2-adm-app
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['db']);
 }
コード例 #9
0
ファイル: Generator.php プロジェクト: pavlinter/yii2-adm-app
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['moduleID', 'moduleClass'], 'filter', 'filter' => 'trim'], [['moduleID', 'moduleClass'], 'required'], [['moduleID'], 'match', 'pattern' => '/^[\\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'], [['moduleClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['moduleClass'], 'validateModuleClass']]);
 }
コード例 #10
0
ファイル: Generator.php プロジェクト: pavlinter/yii2-adm-app
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['controllerClass', 'actions', 'baseClass'], 'filter', 'filter' => 'trim'], [['controllerClass', 'baseClass'], 'required'], ['controllerClass', 'match', 'pattern' => '/^[\\w\\\\]*Controller$/', 'message' => 'Only word characters and backslashes are allowed, and the class name must end with "Controller".'], ['controllerClass', 'validateNewClass'], ['baseClass', 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], ['actions', 'match', 'pattern' => '/^[a-z][a-z0-9\\-,\\s]*$/', 'message' => 'Only a-z, 0-9, dashes (-), spaces and commas are allowed.'], ['viewPath', 'safe']]);
 }