Exemplo n.º 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";
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [
         [['moduleID','moduleDir'], 'filter', 'filter' => 'trim'],
         [['moduleDir'], 'required'],
         [['moduleDir'], 'match', 'pattern' => '/^[\w]+$/', 'message' => 'Only word characters'],
         [['moduleID'], 'match', 'pattern' => '/^[\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'],
     ]);
 }
Exemplo n.º 3
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]);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Loads the generator with the specified ID.
  * @param  string                $id the ID of the generator to be loaded.
  * @return \yii\gii\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}");
     }
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['type'], 'in', 'range' => static::$types, 'skipOnEmpty' => false], [['moduleID', 'moduleClass', 'moduleName'], 'filter', 'filter' => 'trim'], [['moduleID', 'moduleName', 'moduleClass', 'version'], 'required'], [['moduleID'], 'match', 'pattern' => '/^[\\w]+$/', 'message' => '{attribute}只能包含字母,数字和_符号'], [['moduleClass'], 'validateModuleClass'], [['version'], 'match', 'pattern' => '/^\\d+[.\\d]+\\d+$/', 'message' => '{attribute}只能包含数字和.符号并符合版本命名规则, 例如<code>1.0.0</code>'], [['migration', 'admin', 'replyRule'], 'boolean'], [['author'], 'string', 'max' => 50], [['site'], 'string', 'max' => 255], [['category'], 'in', 'range' => array_keys($this->getCategories()), 'skipOnEmpty' => false]]);
 }
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['controller', 'actions', 'baseClass', 'ns'], 'filter', 'filter' => 'trim'], [['controller', 'baseClass'], 'required'], [['controller'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-\\/]*$/', 'message' => 'Only a-z, 0-9, dashes (-) and slashes (/) are allowed.'], [['actions'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-,\\s]*$/', 'message' => 'Only a-z, 0-9, dashes (-), spaces and commas are allowed.'], [['baseClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['ns'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.']]);
 }
Exemplo n.º 7
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['db'], 'filter', 'filter' => 'trim'], [['db'], 'required']]);
 }
Exemplo n.º 8
0
 /**
  * @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.']);
 }
Exemplo n.º 9
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), []);
 }
Exemplo n.º 10
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(\yii\gii\Generator::rules(), [[['moduleID', 'controllerID', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['modelClass', 'controllerID', 'baseControllerClass', 'indexWidgetType'], 'required'], [['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class must not be equal to Model Class.'], [['modelClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['modelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerID'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-\\/]*$/', 'message' => 'Only a-z, 0-9, dashes (-) and slashes (/) are allowed.'], [['searchModelClass'], 'validateNewClass'], [['controllerClass'], 'filter', 'filter' => function () {
         return $this->getControllerClass();
     }, 'skipOnEmpty' => false], [['indexWidgetType'], 'in', 'range' => ['grid', 'list']], [['modelClass'], 'validateModelClass'], [['moduleID'], 'validateModuleID'], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false]]);
 }
Exemplo n.º 11
0
 public function stickyAttributes()
 {
     return ArrayHelper::merge(parent::stickyAttributes(), ['db', 'migrationPath']);
 }
Exemplo n.º 12
0
 /**
  * @inheritdoc
  */
 public function hints()
 {
     return array_merge(parent::hints(), ['modelClass' => 'This is the model class. You should provide a fully qualified class name, e.g., <code>app\\models\\Post</code>.', 'fixtureClass' => 'This is the name for fixture class, e.g., <code>PostFixture</code>.', 'fixtureNs' => 'This is the namespace for fixture class file, e.g., <code>tests\\codeception\\fixtures</code>.', 'dataFile' => 'This is the name for the generated fixture data file, e.g., <code>post.php</code>.', 'dataPath' => 'This is the root path to keep the generated fixture data files. You may provide either a directory or a path alias, e.g., <code>@tests/codeception/fixtures/data</code>.', 'grabData' => 'If checked, the existed data from database will be grabbed into data file.']);
 }
Exemplo n.º 13
0
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['db', 'migrationPath', 'usePrefix', 'tableIgnore']);
 }
Exemplo n.º 14
0
 public function getDescription()
 {
     return parent::getDescription();
     // TODO: Change the autogenerated stub
 }
Exemplo n.º 15
0
 /**
  * @inheritdoc
  */
 public function hints()
 {
     return array_merge(parent::hints(), ['path' => 'Specify the directory for storing the migration for your  block. You may use path alias here, e.g.,
             <code>@app/migrations</code>']);
 }
Exemplo n.º 16
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['moduleID', 'controllerID', 'actions', 'formActions', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['controllerID', 'baseControllerClass'], 'required'], [['controllerID'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-\\/]*$/', 'message' => 'Only a-z, 0-9, dashes (-) and slashes (/) are allowed.'], [['actions', 'formActions'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-,\\s]*$/', 'message' => 'Only a-z, 0-9, dashes (-), spaces and commas are allowed.'], [['baseControllerClass', 'modelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['scenarioName'], 'match', 'pattern' => '/^[\\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'], [['modelClass'], 'validateClass', 'params' => ['extends' => Model::className()]], [['moduleID'], 'validateModuleID']]);
 }
Exemplo n.º 17
0
 /**
  * Returns the validation rules for attributes.
  *
  * Validation rules are used by [[validate()]] to check if attribute values are valid.
  * Child classes may override this method to declare different validation rules.
  * @return array validation rules
  * @see scenarios()
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['enumerableClass', 'constValues', 'description', 'ns'], 'filter', 'filter' => 'trim'], [['enumerableClass', 'constValues', 'start'], 'required'], [['start'], 'integer'], [['sort'], 'boolean'], [['enumerableClass'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-\\/]*$/', 'message' => 'Only a-z, 0-9, dashes (-) and slashes (/) are allowed.']]);
 }
Exemplo n.º 18
0
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['baseModelClass']);
 }
Exemplo n.º 19
0
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments']);
 }
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['db', 'skippedColumns', 'hiddenColumns', 'nameAttribute', 'nsModel', 'nsSearchModel', 'nsController', 'nsTraits', 'baseModelClass', 'queryNs', 'queryBaseClass', 'optimisticLock', 'createdBy', 'updatedBy', 'deletedBy', 'createdAt', 'timestampValue', 'updatedAt', 'deletedAt', 'blameableValue', 'UUIDColumn', 'baseControllerClass', 'indexWidgetType', 'viewPath']);
 }
Exemplo n.º 21
0
 /**
  * @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']]);
 }
Exemplo n.º 22
0
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['ns', 'db', 'baseClass']);
 }
Exemplo n.º 23
0
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['baseControllerClass', 'indexWidgetType']);
 }
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['db', 'templatePath', 'tableIgnore']);
 }
Exemplo n.º 25
0
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments', 'queryNs', 'queryBaseClass', 'addingI18NStrings', 'messagesPaths', 'imagesPath', 'imagesDomain']);
 }
Exemplo n.º 26
0
 /**
  * @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.']]);
 }
Exemplo n.º 27
0
 /**
  * @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']]);
 }
Exemplo n.º 28
0
 /**
  * Returns the validation rules for attributes.
  *
  * Validation rules are used by [[validate()]] to check if attribute values are valid.
  * Child classes may override this method to declare different validation rules.
  * @return array validation rules
  * @see scenarios()
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['enumerableClass', 'constValues', 'ns'], 'filter', 'filter' => 'trim'], [['enumerableClass', 'constValues', 'start'], 'required'], [['start'], 'integer'], [['sort'], 'boolean'], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false], [['enumerableClass'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-\\/]*$/', 'message' => 'Only a-z, 0-9, dashes (-) and slashes (/) are allowed.']]);
 }
Exemplo n.º 29
0
 /**
  * @inheritdoc
  */
 public function stickyAttributes()
 {
     return array_merge(parent::stickyAttributes(), ['migrationPath', 'db', 'generateRelations', 'useTablePrefix']);
 }
 /**
  * @inheritdoc
  */
 public function load($data, $formName = null)
 {
     if (!parent::load($data, $formName)) {
         return false;
     }
     $this->migrationName = preg_replace('/\\s+/', '_', $this->migrationName);
     $dataFix = ['Table' => [], 'Column' => []];
     if (isset($data['Table'])) {
         foreach ($data['Table'] as $temp) {
             $dataFix['Table'][] = $temp;
         }
     }
     if (isset($data['Column'])) {
         foreach ($data['Column'] as $temp) {
             $columnFix = [];
             foreach ($temp as $colTemp) {
                 $columnFix[] = $colTemp;
             }
             $temp = $columnFix;
             $dataFix['Column'][] = $temp;
         }
     }
     if (isset($data['Index'])) {
         foreach ($data['Index'] as $temp) {
             $dataFix['Index'][] = $temp;
         }
     }
     if (isset($data['ForeignKey'])) {
         foreach ($data['ForeignKey'] as $temp) {
             $dataFix['ForeignKey'][] = $temp;
         }
     }
     $data = $dataFix;
     if (isset($data['Table'])) {
         $this->tables = static::createMultiple(Table::className(), [], $data);
         Table::loadMultiple($this->tables, $data);
         $loadData = [];
         for ($i = 0; $i < count($this->tables); ++$i) {
             $loadData['Column'] = $data['Column'][$i];
             $this->tables[$i]->columns = static::createMultiple(Column::className(), [], $loadData);
             $this->tables[$i]->isNewRecord = false;
             Column::loadMultiple($this->tables[$i]->columns, $loadData);
         }
     } else {
         $this->tables = [new Table()];
     }
     if (isset($data['Index'])) {
         $this->indices = static::createMultiple(Index::className(), [], $data);
         Index::loadMultiple($this->indices, $data);
         foreach ($this->indices as $index) {
             $index->isNewRecord = false;
         }
     } else {
         $this->indices = [new Index()];
     }
     if (isset($data['ForeignKey'])) {
         $this->foreignKeys = static::createMultiple(ForeignKey::className(), [], $data);
         ForeignKey::loadMultiple($this->foreignKeys, $data);
         foreach ($this->foreignKeys as $fKey) {
             $fKey->isNewRecord = false;
         }
     } else {
         $this->foreignKeys = [new ForeignKey()];
     }
     return true;
 }