本文整理匯總了PHP中Terminus\Helpers\Input類的典型用法代碼示例。如果您正苦於以下問題:PHP Input類的具體用法?PHP Input怎麽用?PHP Input使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Input類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: implode
/**
* Invoke `wp` commands on a Pantheon development site
*
* <commands>...
* : The WP-CLI commands you intend to run.
*
* [--<flag>=<value>]
* : Additional WP-CLI flag(s) to pass in to the command.
*
* [--site=<site>]
* : The name (DNS shortname) of your site on Pantheon.
*
* [--env=<environment>]
* : Your Pantheon environment. Default: dev
*
*/
function __invoke($args, $assoc_args)
{
$command = implode($args, ' ');
$this->checkCommand($command);
$sites = new Sites();
$site = $sites->get(Input::sitename($assoc_args));
$environment = Input::env(array('args' => $assoc_args, 'site' => $site));
if (!$site) {
$this->failure('Command could not be completed. Unknown site specified.');
}
/**
* See https://github.com/pantheon-systems/titan-mt/blob/master/..
* ..dashboardng/app/workshops/site/models/environment.coffee
*/
$server = $this->getAppserverInfo(array('site' => $site->get('id'), 'environment' => $environment));
// Sanitize assoc args so we don't try to pass our own flags.
unset($assoc_args['site']);
if (isset($assoc_args['env'])) {
unset($assoc_args['env']);
}
// Create user-friendly output
$flags = '';
foreach ($assoc_args as $k => $v) {
if (isset($v) && (string) $v != '') {
$flags .= "--{$k}=" . escapeshellarg($v) . ' ';
} else {
$flags .= "--{$k} ";
}
}
$this->log()->info('Running wp {cmd} {flags} on {site}-{env}', array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
$result = $this->sendCommand($server, 'wp', $args, $assoc_args);
if (Terminus::getConfig('format') != 'normal') {
$this->output()->outputRecordList($result);
}
}
示例2: sites
/**
* List an organization's sites
*
* ## OPTIONS
*
* [--org=<id>]
* : Organization id
*
* [--tag=<tag>]
* : Tag name to filter sites list by
*
* [--add=<site>]
* : Site to add to organization
*
* [--remove=<site>]
* : Site to remove from organization
*
* @subcommand sites
*
*/
public function sites($args, $assoc_args)
{
$org_id = Input::orgid($assoc_args, 'org', null, array('allow_none' => false));
$org = new Organization($org_id);
if (isset($assoc_args['add'])) {
$add = SiteFactory::instance(Input::sitename($assoc_args, 'add'));
Terminus::confirm("Are you sure you want to add %s to %s ?", $assoc_args, array($add->getName(), $org->name));
$org->addSite($add);
Terminus::success("Added site!");
return true;
}
if (isset($assoc_args['remove'])) {
$remove = SiteFactory::instance(Input::sitename($assoc_args, 'remove'));
Terminus::confirm("Are you sure you want to remove %s to %s ?", $assoc_args, array($remove->getName(), $org->name));
$org->removeSite($remove);
Terminus::success("Removed site!");
return true;
}
$org->siteMemberships->fetch();
$memberships = $org->siteMemberships->all();
foreach ($memberships as $membership) {
if (isset($assoc_args['tag']) && !in_array($assoc_args['tag'], $membership->get('tags'))) {
continue;
}
$site = $membership->get('site');
$data[] = array('name' => $site->name, 'id' => $site->id, 'service_level' => $site->service_level, 'framework' => $site->framework, 'created' => date('Y-m-d H:i:s', $site->created), 'tags' => $membership->get('tags'));
}
$this->handleDisplay($data);
}
示例3: 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'));
}
示例4: sites
/**
* List an organization's sites
*
* ## OPTIONS
*
* <add|remove|list>
* : subfunction to run
*
* [--org=<id|name>]
* : Organization UUID or name
*
* [--tag=<tag>]
* : Tag name to filter sites list by
*
* [--site=<site>]
* : Site to add to or remove from organization
*
* @subcommand sites
*
*/
public function sites($args, $assoc_args)
{
$action = array_shift($args);
$org_id = Input::orgid($assoc_args, 'org', null, array('allow_none' => false));
$orgs = new UserOrganizationMemberships();
$org = $orgs->get($org_id);
$org_info = $org->get('organization');
$memberships = $org->site_memberships->all();
switch ($action) {
case 'add':
if (isset($assoc_args['site'])) {
if ($this->siteIsMember($memberships, $assoc_args['site'])) {
$this->failure('{site} is already a member of {org}', array('site' => $assoc_args['site'], 'org' => $org_info->profile->name));
} else {
$site = $this->sites->get($assoc_args['site']);
}
} else {
$site = $this->sites->get(Input::menu($this->getNonmemberSiteList($memberships), null, 'Choose site'));
}
Terminus::confirm('Are you sure you want to add %s to %s ?', array($site->get('name'), $org_info->profile->name));
$workflow = $org->site_memberships->addMember($site);
$workflow->wait();
$this->workflowOutput($workflow);
break;
case 'remove':
if (isset($assoc_args['site'])) {
if (!$this->siteIsMember($memberships, $assoc_args['site'])) {
$this->failure('{site} is not a member of {org}', array('site' => $assoc_args['site'], 'org' => $org_info->profile->name));
} else {
$site = $this->sites->get($assoc_args['site']);
}
} else {
$site = $this->sites->get(Input::menu($this->getMemberSiteList($memberships), null, 'Choose site'));
}
$member = $org->site_memberships->get($site->get('id'));
Terminus::confirm('Are you sure you want to remove %s from %s ?', array($site->get('name'), $org_info->profile->name));
$workflow = $member->removeMember();
$workflow->wait();
$this->workflowOutput($workflow);
break;
case 'list':
default:
foreach ($memberships as $membership) {
if (isset($assoc_args['tag']) && !in_array($assoc_args['tag'], $membership->get('tags'))) {
continue;
}
$site = $membership->get('site');
$data_array = array('name' => null, 'id' => null, 'service_level' => null, 'framework' => null, 'created' => null, 'tags' => $membership->get('tags'));
foreach ($data_array as $key => $value) {
if ($value == null && isset($site->{$key})) {
$data_array[$key] = $site->{$key};
}
}
$data_array['created'] = date('Y-m-dTH:i:s', $data_array['created']);
$data[] = $data_array;
}
$this->output()->outputRecordList($data);
break;
}
}
示例5: sites
/**
* List an organizations sites
*
* ## OPTIONS
*
* [--org=<org>]
* : Organization name or Id
*
* [--add=<site>]
* : Site to add to organization
*
* [--remove=<site>]
* : Site to remove from organization
*
* @subcommand sites
*
*/
public function sites($args, $assoc_args)
{
$orgs = array();
$user = new User();
foreach ($user->organizations() as $id => $org) {
$orgs[$id] = $org->name;
}
if (!isset($assoc_args['org']) or empty($assoc_args['org'])) {
$selected_org = Terminus::menu($orgs, false, "Choose an organization");
} else {
$selected_org = $assoc_args['org'];
}
$org = new Organization($selected_org);
if (isset($assoc_args['add'])) {
$add = SiteFactory::instance(Input::site($assoc_args, 'add'));
Terminus::confirm("Are you sure you want to add %s to %s ?", $assoc_args, array($add->getName(), $org->name));
$org->addSite($add);
Terminus::success("Added site!");
return true;
}
if (isset($assoc_args['remove'])) {
$remove = SiteFactory::instance(Input::site($assoc_args, 'remove'));
Terminus::confirm("Are you sure you want to remove %s to %s ?", $assoc_args, array($remove->getName(), $org->name));
$org->removeSite($remove);
Terminus::success("Removed site!");
return true;
}
$sites = $org->getSites();
$data = array();
foreach ($sites as $site) {
$data[] = array('name' => $site->site->name, 'service level' => isset($site->site->service_level) ? $site->site->service_level : '', 'framework' => isset($site->site->framework) ? $site->site->framework : '', 'created' => date('Y-m-d H:i:s', $site->site->created));
}
$this->handleDisplay($data);
}
示例6: Sites
/**
* Invoke `drush` commands on a Pantheon development site
*
* <commands>...
* : The Drush commands you intend to run.
*
* [--<flag>=<value>]
* : Additional Drush flag(s) to pass in to the command.
*
* [--site=<site>]
* : The name (DNS shortname) of your site on Pantheon.
*
* [--env=<environment>]
* : Your Pantheon environment. Default: dev
*
*/
function __invoke($args, $assoc_args)
{
$environment = Input::env($assoc_args);
$sites = new Sites();
$site = $sites->get(Input::sitename($assoc_args));
if (!$site) {
throw new TerminusException("Command could not be completed. Unknown site specified.");
}
$server = array('user' => "{$environment}.{$site->get('id')}", 'host' => "appserver.{$environment}.{$site->get('id')}.drush.in", 'port' => '2222');
if (strpos(TERMINUS_HOST, 'onebox') !== FALSE) {
$server['user'] = "appserver.{$environment}.{$site->get('id')}";
$server['host'] = TERMINUS_HOST;
}
# Sanitize assoc args so we don't try to pass our own flags.
# TODO: DRY this out?
unset($assoc_args['site']);
if (isset($assoc_args['env'])) {
unset($assoc_args['env']);
}
# Create user-friendly output
$command = implode($args, ' ');
$flags = '';
foreach ($assoc_args as $k => $v) {
if (isset($v) && (string) $v != '') {
$flags .= "--{$k}={$v} ";
} else {
$flags .= "--{$k} ";
}
}
$this->log()->info("Running drush {cmd} {flags} on {site}-{env}", array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
$this->send_command($server, 'drush', $args, $assoc_args);
}
示例7: Sites
/**
* Invoke `wp` commands on a Pantheon development site
*
* <commands>...
* : The WP-CLI commands you intend to run.
*
* [--<flag>=<value>]
* : Additional WP-CLI flag(s) to pass in to the command.
*
* [--site=<site>]
* : The name (DNS shortname) of your site on Pantheon.
*
* [--env=<environment>]
* : Your Pantheon environment. Default: dev
*
*/
function __invoke($args, $assoc_args)
{
$environment = Input::env($assoc_args);
$sites = new Sites();
$site = $sites->get(Input::sitename($assoc_args));
if (!$site) {
throw new TerminusException("Command could not be completed. Unknown site specified.");
}
# see https://github.com/pantheon-systems/titan-mt/blob/master/dashboardng/app/workshops/site/models/environment.coffee
$server = array('user' => "{$environment}.{$site->get('id')}", 'host' => "appserver.{$environment}.{$site->get('id')}.drush.in", 'port' => '2222');
if (strpos(TERMINUS_HOST, 'onebox') !== FALSE) {
$server['user'] = "appserver.{$environment}.{$site->get('id')}";
$server['host'] = TERMINUS_HOST;
}
# Sanitize assoc args so we don't try to pass our own flags.
# TODO: DRY this out?
unset($assoc_args['site']);
if (isset($assoc_args['env'])) {
unset($assoc_args['env']);
}
# Create user-friendly output
$command = implode($args, ' ');
$flags = '';
foreach ($assoc_args as $k => $v) {
if (isset($v) && (string) $v != '') {
$flags .= "--{$k}=" . escapeshellarg($v) . ' ';
} else {
$flags .= "--{$k} ";
}
}
$this->log()->info("Running wp {cmd} {flags} on {site}-{env}", array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
$this->send_command($server, 'wp', $args, $assoc_args);
}
示例8: delete
/**
* Delete a machine token from your account
*
* ## OPTIONS
* [--machine-token-id=<id>]
* : UUID or name of the site you want to delete
*
* [--force]
* : to skip the confirmations
*/
public function delete($args, $assoc_args)
{
$user = Session::getUser();
$id = $assoc_args['machine-token-id'];
if (empty($id)) {
$this->failure('You must specify a machine token id to delete.');
}
// Find the token
$machine_token = $user->machine_tokens->get($assoc_args['machine-token-id']);
if (empty($machine_token)) {
$this->failure('There are no machine tokens with the id {id}.', array('id' => $id));
}
$name = $machine_token->get('device_name');
if (!isset($assoc_args['force']) && !Terminus::getConfig('yes')) {
//If the force option isn't used, we'll ask you some annoying questions
Input::confirm(array('message' => 'Are you sure you want to delete %s?', 'context' => $name));
}
$this->log()->info('Deleting {name} ...', array('name' => $name));
$response = $machine_token->delete();
if ($response['status_code'] == 200) {
$this->log()->info('Deleted {name}!', array('name' => $name));
} else {
$this->failure('There was an problem deleting the machine token.');
}
}
示例9: __invoke
/**
* Get help on a certain command.
*
* [<commands>...]
* : The command you want information on
*
* [--recursive]
* : Display full information on all subcommands and their subcommands
*
* ## EXAMPLES
*
* # get help for `sites` command
* terminus help sites
*
* # get help for `sites` command and all its subcommands
* terminus help sites --recursive
*
* # get help for `sites list` subcommand
* terminus help sites list
*/
public function __invoke($args, $assoc_args)
{
$this->recursive = Input::optional(array('key' => 'recursive', 'choices' => $assoc_args, 'default' => false));
$command = $this->findSubcommand($args);
if ($command) {
$status = $this->showHelp($command);
exit($status);
}
$this->failure('"{cmd}" is not a registered command.', array('cmd' => $args[0]));
}
示例10: get
/**
* Retrieves the model of the given ID
*
* @param [string] $id ID or name of desired organization
* @return [UserOrganizationMembership] $model
*/
public function get($id)
{
$orgs = $this->getMembers();
$orglist = \Terminus\Helpers\Input::orglist();
$model = null;
if (isset($orgs[$id])) {
$model = $this->models[$id];
} elseif (($location = array_search($id, $orglist)) !== false) {
$model = $this->models[$location];
}
return $model;
}
示例11: orgid
public static function orgid($args, $key, $default = null)
{
$orglist = Input::orglist();
$flip = array_flip($orglist);
if (isset($args[$key]) and array_key_exists($args[$key], $flip)) {
// if we have a valid name provided and we need the id
return $flip[$args[$key]];
} elseif (isset($args[$key]) and array_key_exists($args[$key], $orglist)) {
return $args[$key];
}
$orglist = Input::orglist();
$org = \Terminus::menu($orglist, false, "Choose organization");
if ('-' === $org) {
return $default;
}
return $org;
}
示例12: show
/**
* Show operation details for a workflow
*
* ## OPTIONS
* [--workflow_id]
* : Uuid of workflow to show
* [--site=<site>]
* : Site from which to list workflows
*
* @subcommand show
*/
public function show($args, $assoc_args)
{
$site = $this->sites->get(Input::sitename($assoc_args));
$workflow = Input::workflow($site, $assoc_args, 'workflow_id');
$workflow_data = $workflow->serialize();
if (Terminus::getConfig('format') == 'normal') {
$operations_data = $workflow_data['operations'];
unset($workflow_data['operations']);
$this->output()->outputRecord($workflow_data);
if (count($operations_data)) {
$this->log()->info('Workflow operations:');
$this->output()->outputRecordList($operations_data);
} else {
$this->log()->info('Workflow has no operations');
}
} else {
$this->output()->outputRecordList($workflow_data);
}
}
示例13: __invoke
/**
* Invoke `wp` commands on a Pantheon development site
*
* <commands>...
* : The WP-CLI command you intend to run with its arguments, in quotes
*
* [--site=<site>]
* : The name (DNS shortname) of your site on Pantheon
*
* [--env=<environment>]
* : Your Pantheon environment. Default: dev
*
*/
public function __invoke($args, $assoc_args)
{
$command = array_pop($args);
$this->checkCommand($command);
$sites = new Sites();
$site = $sites->get(Input::sitename($assoc_args));
$environment = Input::env(array('args' => $assoc_args, 'site' => $site));
if (!$site) {
$this->failure('Command could not be completed. Unknown site specified.');
}
/**
* See https://github.com/pantheon-systems/titan-mt/blob/master/..
* ..dashboardng/app/workshops/site/models/environment.coffee
*/
$server = $this->getAppserverInfo(array('site' => $site->get('id'), 'environment' => $environment));
$this->log()->info('Running wp {cmd} on {site}-{env}', array('cmd' => $command, 'site' => $site->get('name'), 'env' => $environment));
$result = $this->sendCommand(array('server' => $server, 'remote_exec' => 'wp', 'command' => $command));
if (Terminus::getConfig('format') != 'normal') {
$this->output()->outputRecordList($result);
}
}
示例14: __invoke
/**
* Invoke `drush` commands on a Pantheon development site
*
* <commands>...
* : The WP-CLI command you intend to run, with its arguments
*
* [--site=<site>]
* : The name (DNS shortname) of your site on Pantheon
*
* [--env=<environment>]
* : Your Pantheon environment. Default: dev
*
*/
public function __invoke($args, $assoc_args)
{
$command = array_pop($args);
$this->checkCommand($command);
$sites = new Sites();
$assoc_args['site'] = Input::sitename($assoc_args);
$site = $sites->get($assoc_args['site']);
if (!$site) {
$this->failure('Command could not be completed. Unknown site specified.');
}
$assoc_args['env'] = $environment = Input::env(array('args' => $assoc_args, 'site' => $site));
$server = $this->getAppserverInfo(array('site' => $site->get('id'), 'environment' => $environment));
if (in_array(Terminus::getConfig('format'), array('bash', 'json', 'silent'))) {
$assoc_args['pipe'] = 1;
}
$this->log()->info("Running drush {cmd} on {site}-{env}", array('cmd' => $command, 'site' => $site->get('name'), 'env' => $environment));
$result = $this->sendCommand(array('server' => $server, 'remote_exec' => 'drush', 'command' => $command));
if (Terminus::getConfig('format') != 'normal') {
$this->output()->outputRecordList($result);
}
}
示例15: index
/**
* List Worflows for a Site
*
* ## OPTIONS
* [--site=<site>]
* : Site from which to list workflows
*
* @subcommand list
*/
public function index($args, $assoc_args)
{
$site = $this->sites->get(Input::sitename($assoc_args));
$workflows = $site->workflows->all();
$data = array();
foreach ($workflows as $workflow) {
$user = 'Pantheon';
if (isset($workflow->get('user')->email)) {
$user = $workflow->get('user')->email;
}
if ($workflow->get('total_time')) {
$elapsed_time = $workflow->get('total_time');
} else {
$elapsed_time = time() - $workflow->get('created_at');
}
$data[] = array('id' => $workflow->id, 'env' => $workflow->get('environment'), 'workflow' => $workflow->get('description'), 'user' => $user, 'status' => $workflow->get('phase'), 'time' => sprintf("%ds", $elapsed_time));
}
if (count($data) == 0) {
$this->log()->warning('No workflows have been run on {site}', array('site' => $site->get('name')));
}
$this->output()->outputRecordList($data, array('update' => 'Last update'));
}