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


PHP Console::prompt方法代码示例

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


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

示例1: actionInit

 /**
  * Инициализация проекта.
  */
 public function actionInit()
 {
     $rawProjectName = pathinfo(Yii::getAlias('@app'), PATHINFO_FILENAME);
     $rawProjectName = Inflector::camelize($rawProjectName);
     $projectId = Inflector::camel2id($rawProjectName);
     $projectId = Console::prompt('Project id', ['default' => $projectId]);
     $projectName = Inflector::titleize($projectId);
     $projectName = Console::prompt('Project name', ['default' => $projectName]);
     $vagrantIp = '192.168.33.' . rand(100, 254);
     $vagrantIp = Console::prompt('Vagrant IP', ['default' => $vagrantIp]);
     $values = ['PROJECT-ID' => $projectId, 'PROJECT-NAME' => $projectName, 'VAGRANT-IP' => $vagrantIp];
     $files = ['@app/build.xml' => ['PROJECT-ID'], '@app/Vagrantfile' => ['VAGRANT-IP', 'PROJECT-ID'], '@app/config/web.php' => ['PROJECT-NAME'], '@app/config/console.php' => ['PROJECT-NAME'], '@app/config/env/vagrant.php' => ['VAGRANT-IP', 'PROJECT-ID']];
     $this->replaceInFiles($files, $values);
 }
开发者ID:herroffizier,项目名称:yii2-app,代码行数:17,代码来源:ProjectController.php

示例2: saveFounderData

 /**
  * 用户创建交互
  * @param $_model
  * @return mixed
  */
 private function saveFounderData($_model)
 {
     $model = clone $_model;
     $model->username = Console::prompt('请输入创始人用户名', ['default' => 'admin']);
     $model->email = Console::prompt('请输入创始人邮箱', ['default' => 'admin@admin.com']);
     $model->password = Console::prompt('请输入创始人密码', ['default' => 'admin']);
     if (!($user = $model->signup())) {
         Console::output(Console::ansiFormat("\n输入数据验证错误:", [Console::FG_RED]));
         foreach ($model->getErrors() as $k => $v) {
             Console::output(Console::ansiFormat(implode("\n", $v), [Console::FG_RED]));
         }
         if (Console::confirm("\n是否重新创建创始人账户:")) {
             $user = $this->saveFounderData($_model);
         }
     }
     return $user;
 }
开发者ID:rocketyang,项目名称:huajuan,代码行数:22,代码来源:m150106_031824_initUserTable.php

示例3: saveUserData

 /**
  * 用户创建交互程序
  * @param $userForm
  * @return mixed
  */
 private function saveUserData($userForm)
 {
     $authManager = Yii::$app->authManager;
     $founder = $authManager->getRole('founder');
     $userForm->username = Console::prompt('请先创建创始人用户', ['default' => 'admin']);
     $userForm->email = Console::prompt('请先创建创始人邮箱', ['default' => 'admin@admin.com']);
     $userForm->password = Console::prompt('请先创建创始人密码', ['default' => 'admin']);
     if (!($user = $userForm->register())) {
         echo '输入数据验证错误:' . PHP_EOL;
         foreach ($userForm->getErrors() as $k => $v) {
             echo $k . ':' . PHP_EOL . implode(PHP_EOL, $v) . PHP_EOL;
         }
         echo '请重新输入' . PHP_EOL;
         $this->saveUserData($user);
     }
     $user->setAttributes([]);
     $success = $user->save();
     $uid = $success ? $user->id : 1;
     // 用户创建成功则指定用户id,否则指定id为1的用户为创始人.
     $founder && $authManager->assign($founder, $uid);
     // 指定创始人身份
     return $success;
 }
开发者ID:igaojie,项目名称:yii-QA,代码行数:28,代码来源:m140910_100200_initUserTable.php

示例4: prompt

 /**
  * Prompts the user for input and validates it
  *
  * @param string $text prompt string
  * @param array $options the options to validate the input:
  *
  *  - required: whether it is required or not
  *  - default: default value if no input is inserted by the user
  *  - pattern: regular expression pattern to validate user input
  *  - validator: a callable function to validate input. The function must accept two parameters:
  *      - $input: the user input to validate
  *      - $error: the error value passed by reference if validation failed.
  * @return string the user input
  */
 public function prompt($text, $options = [])
 {
     if ($this->interactive) {
         return Console::prompt($text, $options);
     } else {
         return isset($options['default']) ? $options['default'] : '';
     }
 }
开发者ID:avron99,项目名称:delayed-orders,代码行数:22,代码来源:Controller.php

示例5: setDatabaseConfiguration

 /**
  * Create database configuration.
  * @param string $config local configuration file name
  */
 public static function setDatabaseConfiguration($config)
 {
     echo "Database configuration...\n";
     if (!file_exists($config)) {
         echo "Config '{$to}' not exists, skipping...\n";
         return;
     }
     $contents = file_get_contents($config);
     $pattern = '/("|\')db("|\')\\s*=>\\s*(\\[.*?\\])/ms';
     top:
     $type = Console::prompt('Database type: mysql, sqlite:', ['default' => 'mysql']);
     switch ($type) {
         case 'mysql':
             $host = Console::prompt('Host:', ['default' => 'localhost']);
             $db = Console::prompt('Database:', ['required' => true]);
             $user = Console::prompt('Username:', ['required' => true]);
             $pass = Console::prompt('Password:', ['required' => true]);
             $contents = preg_replace_callback($pattern, function ($match) use($host, $db, $user, $pass) {
                 $dsn = "mysql:host={$host};dbname={$db}";
                 return "'db' => [\n\t\t'class' => 'yii\\db\\Connection',\n\t\t'dsn' => '{$dsn}',\n\t\t'username' => '{$user}',\n\t\t'password' => '{$pass}',\n\t\t'charset' => 'utf8',\n\t]";
             }, $contents);
             break;
         case 'sqlite':
             $db = Console::prompt('Database file:', ['required' => true, 'default' => '@runtime/db.sq3']);
             $contents = preg_replace_callback($pattern, function ($match) use($db) {
                 return "'db' => [\n\t\t'class' => 'yii\\db\\Connection',\n\t\t'dsn' => 'sqlite:{$db}',\n\t]";
             }, $contents);
             break;
         default:
             goto top;
     }
     file_put_contents($config, $contents);
     echo "\nDone. Now you must import database migrate data by execute following command:\n";
     echo "\n\t\tcd <to-your-project-dir>";
     echo "\n\t\t./bin/yii migrate\n\n";
     if ($type === 'sqlite') {
         echo "\n\nNote for SQLite users: after migrating data don't forget to set write permissions to your database file: chmod 777 {$db}\n\n";
     }
 }
开发者ID:skoro,项目名称:yii2-admin-template,代码行数:43,代码来源:Composer.php

示例6: actionInstall

 public function actionInstall()
 {
     // Determine absolute path
     $root = str_replace('\\', '/', __DIR__);
     preg_match('/.+\\/(?=.+\\/.+$)/', $root, $match);
     $root = $match[0];
     // common/config/main-local.php path
     $main_local = $root . 'common/config/main-local.php';
     if (is_writable($main_local)) {
         $main_local_file = file_get_contents($main_local);
         // Read old values
         preg_match('/(?<=host=).+?(?=;)/', $main_local_file, $default['hostname']);
         preg_match('/(?<=dbname=).+?(?=\',)/', $main_local_file, $default['dbname']);
         preg_match('/(?<=username\' => \').+?(?=\',)/', $main_local_file, $default['username']);
         // Prompt for input
         Console::output("\n" . 'Please specify database connection parameters.' . "\n");
         $config['hostname'] = Console::prompt('Database Hostname', ['default' => $default['hostname'][0]]);
         $config['dbname'] = Console::prompt('Database Name', ['default' => $default['dbname'][0]]);
         $config['username'] = Console::prompt('Database Username', ['default' => $default['username'][0]]);
         $config['password'] = Console::prompt('Database Password []');
         echo "\n";
         // Database Connection
         $db_connection = new \mysqli($config['hostname'], $config['username'], $config['password']);
         if (empty($db_connection->connect_error)) {
             // Write new value
             $main_local_file = preg_replace('/(?<=host=).+?(?=;)/', $config['hostname'], $main_local_file);
             $main_local_file = preg_replace('/(?<=dbname=).+?(?=\',)/', $config['dbname'], $main_local_file);
             $main_local_file = preg_replace('/(?<=username\' => \').+?(?=\',)/', $config['username'], $main_local_file);
             $main_local_file = preg_replace('/(?<=password\' => \').+?(?=\',)/', $config['password'], $main_local_file);
             // Write to file
             file_put_contents($main_local, $main_local_file);
             $import = Console::confirm('Import SQL file ?' . "\n", true);
             if (!empty($import)) {
                 // Import SQL
                 $db_connection->set_charset('utf8');
                 // Read SQL file
                 $sql_file = file_get_contents($root . 'dev/_sql/imagenizer.sql');
                 // Edit Database Name
                 $sql_file = preg_replace('/(?<=CREATE DATABASE IF NOT EXISTS \\`).+?(?=\\`)/', $config['dbname'], $sql_file);
                 $sql_file = preg_replace('/(?<=USE \\`).+?(?=\\`;)/', $config['dbname'], $sql_file);
                 // Skip comments and new lines then concat multi-line SQL into single line and put each line into an array
                 preg_match_all('/^(?!--)\\S.{0,}?;/sm', $sql_file, $sql_line);
                 // Execute each line iteratively (since mysqli::query() cannot execute multiple line at once)
                 foreach ($sql_line[0] as $key => $value) {
                     $db_connection->query($value);
                 }
                 // Setup root account
                 $this->setRoot();
                 // Setup Role Based Access Control
                 $this->setRbac();
             }
             // Close Connections
             $db_connection->close();
         } else {
             if (empty($mute)) {
                 Console::output('Error: Cannot connect to the database.' . "\n");
             }
             exit;
         }
     } else {
         if (empty($mute)) {
             Console::output('Error: The file "' . $main_local . '" is not writable.' . "\n");
         }
         exit;
     }
     if (empty($mute)) {
         Console::output("\n" . 'Imagenizer was installed successfully.' . "\n");
     }
 }
开发者ID:gearger,项目名称:imagenizer,代码行数:69,代码来源:SetupController.php


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