コード例 #1
0
ファイル: CLICreateModel.php プロジェクト: o-log/php-model
 public static function chooseNamespaceScreen()
 {
     echo CliUtil::delimiter();
     echo "Select new model namespace:\n";
     //echo "Example: \"Test\", \"Deep\\Test\"\n";
     // TODO: sanitize
     // TODO: support empty namespaces
     // TODO: check for leading '\' and correct format
     $cwd = getcwd();
     self::$model_namespace_for_path = CLIFileSelector::selectFileName($cwd, false);
     // убираем из начала текущую папку
     if (strpos(self::$model_namespace_for_path, $cwd) === 0) {
         self::$model_namespace_for_path = substr(self::$model_namespace_for_path, strlen($cwd));
     } else {
         throw new \Exception('fail');
     }
     // отрезаем слэш в начале если есть
     if (substr(self::$model_namespace_for_path, 0, 1) == DIRECTORY_SEPARATOR) {
         self::$model_namespace_for_path = substr(self::$model_namespace_for_path, strlen(DIRECTORY_SEPARATOR));
     }
     self::$model_namespace_for_class = str_replace(DIRECTORY_SEPARATOR, '\\', self::$model_namespace_for_path);
     self::chooseModelDBIndex();
 }
コード例 #2
0
 public function extraFieldFunctionsScreen()
 {
     if (!$this->model_file_path) {
         echo "\nChoose model class file:\n";
         $this->model_file_path = CLIFileSelector::selectFileName(getcwd());
         echo "\nClass file: " . $this->model_file_path . "\n";
     }
     $class_file_obj = new PHPClassFile($this->model_file_path);
     if (!$this->field_name) {
         $this->field_name = $this->askFieldName($class_file_obj);
     }
     Assert::assert($this->model_file_path);
     Assert::assert($this->field_name);
     while (true) {
         echo CliUtil::delimiter();
         echo "Extra functions:\n";
         echo "\t" . self::FUNCTION_CODE_ADD_UNIQUE_KEY . ": create unique key for field\n";
         echo "\t" . self::FUNCTION_ADD_FOREIGN_KEY . ": create foreign key for field\n";
         echo "\t" . self::FUNCTION_ADD_SELECTOR . ": create selector for field\n";
         echo "\t" . "ENTER: exit to menu\n";
         // TODO: use constants
         $function_code = trim(fgets(STDIN));
         // TODO: check format
         switch ($function_code) {
             case self::FUNCTION_CODE_ADD_UNIQUE_KEY:
                 $this->addUniqueKey();
                 break;
             case self::FUNCTION_ADD_FOREIGN_KEY:
                 $this->addForeignKey();
                 break;
             case self::FUNCTION_ADD_SELECTOR:
                 $this->addSelector();
                 break;
             case '':
                 return;
         }
     }
 }