本文整理汇总了PHP中Terminus::menu方法的典型用法代码示例。如果您正苦于以下问题:PHP Terminus::menu方法的具体用法?PHP Terminus::menu怎么用?PHP Terminus::menu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Terminus
的用法示例。
在下文中一共展示了Terminus::menu方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: upstream
/**
* Helper function to select valid upstream
*
* @param [array] $args Args to parse value from
* @param [string] $key Index to search for in args
* @param [boolean] $exit If true, throw error when no value is found
*
* @return [Upstream] $upstream
*/
public static function upstream($args, $key, $exit = true)
{
$upstreams = new Upstreams();
if (isset($args[$key])) {
$upstream = $upstreams->getByIdOrName($args[$key]);
if ($upstream == null) {
\Terminus::error("Couldn't find upstream: %s", array($args['upstream']));
}
} else {
$upstream = $upstreams->get(\Terminus::menu($upstreams->getMemberList('id', 'longname')));
}
if (!$upstream && $exit) {
\Terminus::error('Upstream is required.');
}
return $upstream;
}
示例4: delete
/**
* Delete a site from pantheon
*
* ## OPTIONS
* --site=<site>
* : Id of the site you want to delete
*
* [--all]
* : Just kidding ... we won't let you do that.
*
* [--force]
* : to skip the confirmations
*
*/
function delete($args, $assoc_args)
{
$site_to_delete = SiteFactory::instance(@$assoc_args['site']);
if (!$site_to_delete) {
foreach (SiteFactory::instance() as $id => $site) {
$site->id = $id;
$sites[] = $site;
$menu[] = $site->information->name;
}
$index = Terminus::menu($menu, null, "Select a site to delete");
$site_to_delete = $sites[$index];
}
if (!isset($assoc_args['force']) and !Terminus::get_config('yes')) {
// if the force option isn't used we'll ask you some annoying questions
Terminus::confirm(sprintf("Are you sure you want to delete %s?", $site_to_delete->information->name));
Terminus::confirm("Are you really sure?");
}
Terminus::line(sprintf("Deleting %s ...", $site_to_delete->information->name));
$response = \Terminus_Command::request('sites', $site_to_delete->id, '', 'DELETE');
Terminus::success("Deleted %s!", $site_to_delete->information->name);
}
示例5: backup
/**
* Get, load, create, or list backup information
*
* ## OPTIONS
*
* <get|load|create|list>
* : function to run - get, load, create, or list
*
* [--site=<site>]
* : Site to load
*
* [--env=<env>]
* : Environment to load
*
* [--element=<code|files|db|all>]
* : Element to download or create. *all* only used for the 'create'
*
* [--to-directory=<directory>]
* : Download the file if set
*
* [--latest]
* : if set no the latest backup will be selected automatically
*
* [--keep-for]
* : number of days to keep this backup.
*
* @subcommand backup
*
*/
public function backup($args, $assoc_args)
{
$action = array_shift($args);
$site = SiteFactory::instance(Input::site($assoc_args));
$env = Input::env($assoc_args, 'env');
switch ($action) {
case 'get':
// prompt for backup type
if (!($element = @$assoc_args['element'])) {
$element = Terminus::menu(array('code', 'files', 'database'), null, "Select type backup", TRUE);
}
if (!in_array($element, array('code', 'files', 'database'))) {
Terminus::error("Invalid backup element specified.");
}
$latest = Input::optional('latest', $assoc_args, false);
$backups = $site->environment($env)->backups($element, $latest);
if (empty($backups)) {
\Terminus::error('No backups available.');
}
$menu = $folders = array();
// build a menu for selecting back ups
foreach ($backups as $folder => $backup) {
if (!isset($backup->filename)) {
continue;
}
if (!isset($backup->folder)) {
$backup->folder = $folder;
}
$buckets[] = $backup->folder;
$menu[] = $backup->filename;
}
if (empty($menu)) {
Terminus::error("No backups available. Create one with `terminus site backup create --site=%s --env=%s`", array($site->getName(), $env));
}
$index = 0;
if (!$latest) {
$index = Terminus::menu($menu, null, "Select backup");
}
$bucket = $buckets[$index];
$filename = $menu[$index];
$url = $site->environment($env)->backupUrl($bucket, $element);
if (isset($assoc_args['to-directory'])) {
Terminus::line("Downloading ... please wait ...");
$filename = \Terminus\Utils\get_filename_from_url($url->url);
$target = sprintf("%s/%s", $assoc_args['to-directory'], $filename);
if (Terminus_Command::download($url->url, $target)) {
Terminus::success("Downloaded %s", $target);
return $target;
} else {
Terminus::error("Could not download file");
}
}
echo $url->url;
return $url->url;
break;
case 'load':
$assoc_args['to-directory'] = '/tmp';
$assoc_args['element'] = 'database';
$database = @$assoc_args['database'] ?: false;
$username = @$assoc_args['username'] ?: false;
$password = @$assoc_args['password'] ?: false;
exec("mysql -e 'show databases'", $stdout, $exit);
if (0 != $exit) {
Terminus::error("MySQL does not appear to be installed on your server.");
}
$assoc_args['env'] = $env;
$target = $this->backup(array('get'), $assoc_args);
$target = \Terminus\Utils\get_filename_from_url($target);
$target = "/tmp/{$target}";
if (!file_exists($target)) {
Terminus::error("Can't read database file %s", array($target));
//.........这里部分代码省略.........
示例6: backups
/**
* Get, load, create, or list backup information
*
* ## OPTIONS
*
* <get|load|create|list>
* : Function to run - get, load, create, or list
*
* [--site=<site>]
* : Site to load
*
* [--env=<env>]
* : Environment to load
*
* [--element=<code|files|db|all>]
* : Element to download or create. `all` is only used for 'create'
*
* [--to=<directory|file>]
* : Absolute path of a directory or filename to save the downloaded backup to
*
* [--file=<filename>]
* : Select one of the files from the list subcommand. Only used for 'get'
*
* [--latest]
* : If set the latest backup will be selected automatically
*
* [--keep-for]
* : Number of days to keep this backup
*
* @subcommand backups
*
*/
public function backups($args, $assoc_args)
{
$action = array_shift($args);
$site = $this->sites->get(Input::sitename($assoc_args));
$env = Input::env($assoc_args, 'env');
//Backward compatability supports "database" as a valid element value.
if (isset($assoc_args['element']) && $assoc_args['element'] == 'database') {
$assoc_args['element'] = 'db';
}
switch ($action) {
case 'get':
$file = Input::optional('file', $assoc_args, false);
if ($file) {
$regex = sprintf("/%s_%s_\\d{4}-\\d{2}-\\d{2}T\\d{2}-\\d{2}-\\d{2}_UTC_(.*).tar.gz/", $site->get('name'), $env);
preg_match($regex, $file, $matches);
$element = $matches[1];
} elseif (isset($assoc_args['element'])) {
$element = $assoc_args['element'];
} else {
$element = Terminus::menu(array('code', 'files', 'db'), null, 'Select backup element', true);
if (!in_array($element, array('code', 'files', 'db'))) {
$this->failure('Invalid backup element specified.');
}
}
$latest = (bool) Input::optional('latest', $assoc_args, false);
if (!in_array($element, array('code', 'files', 'db'))) {
$this->failure('Invalid backup element specified.');
}
$latest = Input::optional('latest', $assoc_args, false);
$backups = $site->environments->get($env)->backups($element);
if (empty($backups)) {
$this->failure('No backups available. Create one with `terminus site backup create --site={site} --env={env}`', array('site' => $site->get('name'), 'env' => $env));
}
//Ensure that that backups being presented for retrieval have finished
$backups = array_filter($backups, function ($backup) {
return isset($backup->finish_time) && $backup->finish_time;
});
if ($latest) {
$backup = array_pop($backups);
} elseif ($file) {
do {
try {
$candidate = array_pop($backups);
} catch (\Exception $e) {
$this->failure("{$file} is not a valid backup archive");
}
if ($candidate->filename == $file) {
$backup = $candidate;
}
} while (!isset($backup));
}
if (!isset($backup)) {
$menu = $folders = array();
foreach ($backups as $folder => $backup) {
if (!isset($backup->filename)) {
continue;
}
if (!isset($backup->folder)) {
$backup->folder = $folder;
}
$menu[] = $backup->filename;
}
$index = Terminus::menu($menu, null, 'Select backup');
$backup_elements = array_values($backups);
$backup = $backup_elements[$index];
}
if (empty($menu)) {
$this->failure('No backups available. Create one with `terminus site backup create --site={site} --env={env}`', array('site' => $site->get('name'), 'env' => $env));
//.........这里部分代码省略.........
示例7: backups
/**
* Get, load, create, or list backup information
*
* ## OPTIONS
*
* <get|load|create|list>
* : Function to run - get, load, create, or list
*
* [--site=<site>]
* : Site to load
*
* [--env=<env>]
* : Environment to load
*
* [--element=<code|files|db|all>]
* : Element to download or create. *all* only used for 'create'
*
* [--to-directory=<directory>]
* : Absolute path of directory to download the file
*
* [--latest]
* : If set the latest backup will be selected automatically
*
* [--keep-for]
* : Number of days to keep this backup
*
* @subcommand backups
*
*/
public function backups($args, $assoc_args)
{
$action = array_shift($args);
$site = $this->sites->get(Input::sitename($assoc_args));
$env = Input::env($assoc_args, 'env');
//Backward compatability supports "database" as a valid element value.
if (isset($assoc_args['element']) && $assoc_args['element'] == 'database') {
$assoc_args['element'] = 'db';
}
switch ($action) {
case 'get':
if (isset($assoc_args['element'])) {
$element = $assoc_args['element'];
} else {
$element = Terminus::menu(array('code', 'files', 'db'), null, 'Select backup element', true);
}
if (!in_array($element, array('code', 'files', 'db'))) {
Terminus::error('Invalid backup element specified.');
}
$latest = Input::optional('latest', $assoc_args, false);
$backups = $site->environments->get($env)->backups($element);
//Ensure that that backups being presented for retrieval have finished
$backups = array_filter($backups, function ($backup) {
return isset($backup->finish_time) && $backup->finish_time;
});
if ($latest) {
$backups = array(array_pop($backups));
}
if (empty($backups)) {
\Terminus::error('No backups available.');
}
$menu = $folders = array();
foreach ($backups as $folder => $backup) {
if (!isset($backup->filename)) {
continue;
}
if (!isset($backup->folder)) {
$backup->folder = $folder;
}
$buckets[] = $backup->folder;
$menu[] = $backup->filename;
}
if (empty($menu)) {
Terminus::error('No backups available. Create one with ' . '`terminus site backup create --site=%s --env=%s`', array($site->get('name'), $env));
}
$index = 0;
if (!$latest) {
$index = Terminus::menu($menu, null, 'Select backup');
}
$bucket = $buckets[$index];
$filename = $menu[$index];
$url = $site->environments->get($env)->backupUrl($bucket, $element);
if (isset($assoc_args['to-directory'])) {
Terminus::line('Downloading ... please wait ...');
$filename = \Terminus\Utils\get_filename_from_url($url->url);
$target = sprintf('%s/%s', $assoc_args['to-directory'], $filename);
if (TerminusCommand::download($url->url, $target)) {
Terminus::success('Downloaded %s', $target);
return $target;
} else {
Terminus::error('Could not download file');
}
}
Terminus::success($url->url);
return $url->url;
break;
case 'load':
$assoc_args['to-directory'] = '/tmp';
$assoc_args['element'] = 'database';
if (isset($assoc_args['database'])) {
$database = $assoc_args['database'];
//.........这里部分代码省略.........
示例8: upstream
/**
* Helper function to select valid upstream
*
* @param [array] $args Args to parse value from
* @param [string] $key Index to search for in args
* @param [boolean] $exit If true, throw error when no value is found
*
* @return [Upstream] $upstream
*/
public static function upstream($args, $key, $exit = true)
{
$upstreams = new Upstreams();
if (isset($args[$key])) {
$upstream = $upstreams->getByIdOrName($args[$key]);
if ($upstream == null) {
throw new TerminusException("Couldn't find upstream: {upstream}", array('upstream' => $args['upstream']));
}
} else {
$upstream = $upstreams->get(\Terminus::menu($upstreams->getMemberList('id', 'longname')));
}
return $upstream;
}
示例9: orgname
/**
* Input helper that provides interactive menu to select org name
*
* @param [array] $args The args passed in from argv
* @param [string] $key Args key to search for
* @return [string] Site name
*/
public static function orgname($args, $key)
{
$orglist = Input::orglist();
if (isset($args[$key])) {
//If org id is sent, fetch the name
if (array_key_exists($args[$key], $orglist)) {
return $orglist[$args[$key]];
}
return $args[$key];
}
$org = \Terminus::menu($orglist, false, "Choose organization");
return $orglist[$org];
}
示例10: upstream
/**
* Helper function to select valid upstream
*
* @param [array] $args Args to parse value from
* @param [string] $key Index to search for in args
* @param [boolean] $exit If true, throw error when no value is found
*
* @return [array] $upstream
*/
public static function upstream($args, $key, $exit = true)
{
if (isset($args[$key])) {
$upstream = Upstreams::getByIdOrName($args[$key]);
if (!$upstream) {
\Terminus::error("Couldn't find upstream: %s", array($args['upstream']));
}
} else {
$upstream = \Terminus::menu(Upstreams::selectList());
$upstream = Upstreams::getByIndex($upstream);
}
if (!$upstream and $exit) {
\Terminus::error("Upstream is required.");
}
return $upstream;
}