本文整理汇总了PHP中Terminus\Helpers\Input::prompt方法的典型用法代码示例。如果您正苦于以下问题:PHP Input::prompt方法的具体用法?PHP Input::prompt怎么用?PHP Input::prompt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Terminus\Helpers\Input
的用法示例。
在下文中一共展示了Input::prompt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
/**
* Log in as a user
*
* ## OPTIONS
* [<email>]
* : Email address to log in as.
*
* [--password=<value>]
* : Log in non-interactively with this password. Useful for automation.
*
* [--machine-token=<value>]
* : Authenticate using an Auth0 token
*
* [--session=<value>]
* : Authenticate using an existing session token
* [--debug]
* : dump call information when logging in.
*/
public function login($args, $assoc_args)
{
// Try to login using a machine token, if provided.
if (isset($assoc_args['machine-token']) || empty($args) && isset($_SERVER['TERMINUS_MACHINE_TOKEN'])) {
if (isset($assoc_args['machine-token'])) {
$token = $assoc_args['machine-token'];
} elseif (isset($_SERVER['TERMINUS_MACHINE_TOKEN'])) {
$token = $_SERVER['TERMINUS_MACHINE_TOKEN'];
}
$this->auth->logInViaMachineToken($token);
} elseif (isset($assoc_args['session'])) {
$this->auth->logInViaSessionToken($assoc_args['session']);
} else {
// Otherwise, do a normal email/password-based login.
if (empty($args)) {
if (isset($_SERVER['TERMINUS_USER'])) {
$email = $_SERVER['TERMINUS_USER'];
} else {
$email = Input::prompt(array('message' => 'Your email address?'));
}
} else {
$email = $args[0];
}
if (isset($assoc_args['password'])) {
$password = $assoc_args['password'];
} else {
$password = Input::promptSecret(array('message' => 'Your dashboard password (input will not be shown)'));
}
$this->auth->logInViaUsernameAndPassword($email, $password);
}
$this->log()->debug(get_defined_vars());
Terminus::launchSelf('art', array('fist'));
}
示例2: loadBackup
/**
* Loads a single backup
*
* @params array $assoc_args Parameters and flags from the command line
* @return bool Always true, else the function has thrown an exception
*/
private function loadBackup($assoc_args)
{
$assoc_args['to'] = '/tmp';
$assoc_args['element'] = 'database';
if (isset($assoc_args['database'])) {
$database = $assoc_args['database'];
} else {
$database = escapeshellarg(Input::prompt(array('message' => 'Name of database to import to')));
}
if (isset($assoc_args['username'])) {
$username = $assoc_args['username'];
} else {
$username = escapeshellarg(Input::prompt(array('message' => 'Username')));
}
if (isset($assoc_args['password'])) {
$password = $assoc_args['password'];
} else {
$password = Input::promptSecret(array('message' => 'Your MySQL password (input will not be shown)'));
}
exec('mysql --version', $stdout, $exit);
if ($exit != 0) {
$this->failure('MySQL does not appear to be installed on your server.');
}
$target = $this->getBackup($assoc_args);
$target = '/tmp/' . Utils\getFilenameFromUrl($target);
if (!file_exists($target)) {
$this->failure('Cannot read database file {target}', compact('target'));
}
$this->log()->info('Unziping database');
exec("gunzip {$target}", $stdout, $exit);
// trim the gz of the target
$target = Utils\sqlFromZip($target);
$target = escapeshellarg($target);
exec(sprintf('mysql %s -u %s -p"%s" < %s', $database, $username, $password, $target), $stdout, $exit);
if ($exit != 0) {
$this->failure('Could not import database');
}
$this->log()->info('{target} successfully imported to {db}', array('target' => $target, 'db' => $database));
return true;
}
示例3: promptArgs
/**
* Parses the arguments for prompting in interactive mode
*
* @param array $args Array of command line non-params and non-flags
* @param array $assoc_args Array of command line params and flags
* @return array Elements as follows:
* [array] Array of command line non-params and non-flags
* [array] Array of command line params and flags
* @todo This function is unused; remove?
*/
private function promptArgs($args, $assoc_args)
{
$synopsis = $this->getSynopsis();
if (!$synopsis) {
return array($args, $assoc_args);
}
$spec = array_filter(Terminus\SynopsisParser::parse($synopsis), function ($spec_arg) {
$is_in_array = in_array($spec_arg['type'], array('generic', 'positional', 'assoc', 'flag'));
return $is_in_array;
});
$spec = array_values($spec);
// 'positional' arguments are positional (aka zero-indexed)
// so $args needs to be reset before prompting for new arguments
$args = array();
foreach ($spec as $key => $spec_arg) {
$current_prompt = $key + 1 . '/' . count($spec) . ' ';
$default = false;
if ($spec_arg['optional']) {
$default = '';
}
// 'generic' permits arbitrary key=value (e.g. [--<field>=<value>])
$input = new Input();
if ($spec_arg['type'] == 'generic') {
list($key_token, $value_token) = explode('=', $spec_arg['token']);
$repeat = false;
do {
if (!$repeat) {
$key_prompt = $current_prompt . $key_token;
} else {
$key_prompt = str_repeat(" ", strlen($current_prompt)) . $key_token;
}
$key = $input->prompt(array('message' => $key_prompt, 'default' => $default));
if ($key === false) {
return array($args, $assoc_args);
}
if ($key) {
$key_prompt_count = strlen($key_prompt) - strlen($value_token) - 1;
$value_prompt = str_repeat(' ', $key_prompt_count) . '=' . $value_token;
$value = $input->prompt(array('message' => $value_prompt, 'default' => $default));
if (false === $value) {
return array($args, $assoc_args);
}
$assoc_args[$key] = $value;
$repeat = true;
$required = false;
} else {
$repeat = false;
}
} while ($required || $repeat);
} else {
$prompt = $current_prompt . $spec_arg['token'];
if ('flag' == $spec_arg['type']) {
$prompt .= ' (Y/n)';
}
$response = $input->prompt(array('message' => $prompt, 'default' => $default));
if (false === $response) {
return array($args, $assoc_args);
}
if ($response) {
switch ($spec_arg['type']) {
case 'positional':
if ($spec_arg['repeating']) {
$response = explode(' ', $response);
} else {
$response = array($response);
}
$args = array_merge($args, $response);
break;
case 'assoc':
$assoc_args[$spec_arg['name']] = $response;
break;
case 'flag':
if ($response == 'Y') {
$assoc_args[$spec_arg['name']] = true;
}
break;
}
}
}
}
$args_array = array($args, $assoc_args);
return $args_array;
}