本文整理汇总了PHP中drush_set_context函数的典型用法代码示例。如果您正苦于以下问题:PHP drush_set_context函数的具体用法?PHP drush_set_context怎么用?PHP drush_set_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drush_set_context函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preflight
function preflight()
{
// We need our constants before commandfile searching like DRUSH_BOOTSTRAP_DRUPAL_LOGIN.
require_once __DIR__ . '/bootstrap.inc';
require_once __DIR__ . '/command.inc';
drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
}
示例2: testCommandVersionSpecific
/**
* Assure that matching version-specific command files are loaded and others are ignored.
*/
function testCommandVersionSpecific()
{
$path = Path::join(UNISH_SANDBOX, 'commandUnitCase');
$major = $this->drush_major_version();
$major_plus1 = $major + 1;
// Write matched and unmatched files to the system search path.
$files = array(Path::join($path, "{$major}.drush{$major}.inc"), Path::join($path, "drush{$major}/drush{$major}.drush.inc"), Path::join($path, "{$major_plus1}.drush{$major_plus1}.inc"), Path::join($path, "drush{$major_plus1}/drush{$major_plus1}.drush.inc"));
$this->mkdir(Path::join($path, 'drush' . $major));
$this->mkdir(Path::join($path, 'drush' . $major_plus1));
foreach ($files as $file) {
$contents = <<<EOD
<?php
// Written by Unish. This file is safe to delete.
\$GLOBALS['unish_foo'][] = '{$file}';
EOD;
$return = file_put_contents($file, $contents);
}
drush_set_context('DRUSH_INCLUDE', array($path));
drush_preflight();
$loaded = drush_commandfile_list();
$this->assertContains($files[0], $loaded);
//Loaded a version-specific command file.
$this->assertContains($files[1], $loaded);
//Loaded a version-specific command directory.
$this->assertNotContains($files[2], $loaded);
//Did not load a mismatched version-specific command file.
$this->assertNotContains($files[3], $loaded);
//Did not load a a mismatched version-specific command directory.
}
示例3: testCommandVersionSpecific
/**
* Assure that matching version-specific command files are loaded and others are ignored.
*/
function testCommandVersionSpecific()
{
$path = UNISH_SANDBOX . '/commandUnitCase';
$major = $this->drush_major_version();
$major_plus1 = $major + 1;
// Write matched and unmatched files to the system search path.
$files = array($path . "/{$major}.drush{$major}.inc", $path . "/drush{$major}/drush{$major}.drush.inc", $path . "/{$major_plus1}.drush{$major_plus1}.inc", $path . "/drush{$major_plus1}/drush{$major_plus1}.drush.inc");
mkdir($path);
mkdir($path . '/drush' . $major);
mkdir($path . '/drush' . $major_plus1);
foreach ($files as $file) {
$contents = <<<EOD
<?php
// Written by Unish. This file is safe to delete.
\$GLOBALS['unish_foo'][] = '{$file}';
EOD;
$return = file_put_contents($file, $contents);
}
drush_set_context('DRUSH_INCLUDE', array($path));
drush_preflight();
$loaded = drush_commandfile_list();
$this->assertTrue(in_array(realpath($files[0]), $loaded), 'Loaded a version-specific command file.');
$this->assertTrue(in_array(realpath($files[1]), $loaded), 'Loaded a version-specific command directory.');
$this->assertFalse(in_array(realpath($files[2]), $loaded), 'Did not load a mismatched version-specific command file.');
$this->assertFalse(in_array(realpath($files[3]), $loaded), 'Did not load a a mismatched version-specific command directory.');
}
示例4: drush_main
/**
* The main Drush function.
*
* - Runs "early" option code, if set (see global options).
* - Parses the command line arguments, configuration files and environment.
* - Prepares and executes a Drupal bootstrap, if possible,
* - Dispatches the given command.
*
* function_exists('drush_main') may be used by modules to detect whether
* they are being called from Drush. See http://drupal.org/node/1181308
* and http://drupal.org/node/827478
*
* @return mixed
* Whatever the given command returns.
*/
function drush_main()
{
// Load Drush core include files, and parse command line arguments.
require dirname(__FILE__) . '/includes/preflight.inc';
if (drush_preflight_prepare() === FALSE) {
return 1;
}
// Start code coverage collection.
if ($coverage_file = drush_get_option('drush-coverage', FALSE)) {
drush_set_context('DRUSH_CODE_COVERAGE', $coverage_file);
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
register_shutdown_function('drush_coverage_shutdown');
}
// Load the global Drush configuration files, and global Drush commands.
// Find the selected site based on --root, --uri or cwd
// Preflight the selected site, and load any configuration and commandfiles associated with it.
// Select and return the bootstrap class.
$bootstrap = drush_preflight();
// Reset our bootstrap phase to the beginning
drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
$return = '';
if (!drush_get_error()) {
if ($file = drush_get_option('early', FALSE)) {
require_once $file;
$function = 'drush_early_' . basename($file, '.inc');
if (function_exists($function)) {
if ($return = $function()) {
// If the function returns FALSE, we continue and attempt to bootstrap
// as normal. Otherwise, we exit early with the returned output.
if ($return === TRUE) {
$return = '';
}
}
}
} else {
// Do any necessary preprocessing operations on the command,
// perhaps handling immediately.
$command_handled = drush_preflight_command_dispatch();
if (!$command_handled) {
$return = $bootstrap->bootstrap_and_dispatch();
}
}
}
// TODO: Get rid of global variable access here, and just trust
// the bootstrap object returned from drush_preflight(). This will
// require some adjustments to Drush bootstrapping.
// See: https://github.com/drush-ops/drush/pull/1303
if ($bootstrap = drush_get_bootstrap_object()) {
$bootstrap->terminate();
}
drush_postflight();
// How strict are we? If we are very strict, turn 'ok' into 'error'
// if there are any warnings in the log.
if ($return == 0 && drush_get_option('strict') > 1 && drush_log_has_errors()) {
$return = 1;
}
// After this point the drush_shutdown function will run,
// exiting with the correct exit code.
return $return;
}
示例5: listTables
public function listTables()
{
$current = drush_get_context('DRUSH_SIMULATE');
drush_set_context('DRUSH_SIMULATE', FALSE);
$return = $this->query('SHOW TABLES;');
$tables = drush_shell_exec_output();
drush_set_context('DRUSH_SIMULATE', $current);
return $tables;
}
示例6: drushMain
/**
* Calls a Drush command.
*
* This is an exact copy of drush_main from drush.php, but that file
* cannot be loaded because it produces side effects.
*
* @see drush_main
*
* @return int|string
*/
protected static function drushMain()
{
$return = '';
// Start code coverage collection.
if ($coverage_file = drush_get_option('drush-coverage', false)) {
drush_set_context('DRUSH_CODE_COVERAGE', $coverage_file);
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
register_shutdown_function('drush_coverage_shutdown');
}
/* Set up bootstrap object, so that
* - 'early' files can bootstrap when needed.
* - bootstrap constants are available.
*/
$bootstrap_class = drush_get_option('bootstrap_class', 'Drush\\Boot\\DrupalBoot');
$bootstrap = new $bootstrap_class();
drush_set_context('DRUSH_BOOTSTRAP_OBJECT', $bootstrap);
$bootstrap->preflight();
// Process initial global options such as --debug.
_drush_preflight_global_options();
$return = '';
drush_preflight();
if (!drush_get_error()) {
if ($file = drush_get_option('early', false)) {
require_once $file;
$function = 'drush_early_' . basename($file, '.inc');
if (function_exists($function)) {
if ($return = $function()) {
// If the function returns FALSE, we continue and attempt to bootstrap
// as normal. Otherwise, we exit early with the returned output.
if ($return === TRUE) {
$return = '';
}
}
}
} else {
// Do any necessary preprocessing operations on the command,
// perhaps handling immediately.
$command_handled = drush_preflight_command_dispatch();
if (!$command_handled) {
$bootstrap = drush_get_context('DRUSH_BOOTSTRAP_OBJECT');
$return = $bootstrap->bootstrap_and_dispatch();
}
}
}
drush_postflight();
// How strict are we? If we are very strict, turn 'ok' into 'error'
// if there are any warnings in the log.
if ($return == 0 && drush_get_option('strict') > 1 && drush_log_has_errors()) {
$return = 1;
}
// After this point the drush_shutdown function will run,
// exiting with the correct exit code.
return $return;
}
示例7: install
public function install($profile)
{
$options['account-name'] = drush_prompt(dt('Enter the administrator (uid=1) account name'));
$options['account-pass'] = drush_prompt(dt('Enter the administrator (uid=1) password'));
$options['account-mail'] = drush_prompt(dt('Enter the administrator (uid=1) e-mail address'));
$options['locale'] = drush_prompt(dt('Enter your desired locale'));
$options['site-name'] = drush_prompt(dt('Enter the name of your site'));
$options['site-mail'] = drush_prompt(dt('Enter the global mail address of your site'));
// Setting the options as a drush command specific context so the site install
// routine picks it up.
drush_set_context('specific', $options);
// Determin the major version and launch version specific installation.
drush_include_engine('drupal', 'site_install', drush_drupal_major_version());
drush_core_site_install_version($profile, $options);
drush_log(dt('Installation finished.'), 'success');
}
示例8: get_selected_uri
/**
* Find the URI that has been selected by the cwd if it was not previously set
* via the --uri / -l option.
*
* @return string The site URI.
*
* @see _drush_bootstrap_selected_uri()
*/
protected function get_selected_uri()
{
$uri = drush_get_context('DRUSH_SELECTED_URI');
if (empty($uri)) {
$site_path = $this->site_path();
$elements = explode('/', $site_path);
$current = array_pop($elements);
if (!$current) {
$current = 'default';
}
$uri = 'http://' . $current;
$uri = drush_set_context('DRUSH_SELECTED_URI', $uri);
$this->create_self_alias();
}
return $uri;
}
示例9: bootstrap_drupal_login
/**
* Log into the bootstrapped Drupal site with a specific
* username or user id.
*/
function bootstrap_drupal_login()
{
$uid_or_name = drush_set_context('DRUSH_USER', drush_get_option('user', 0));
$userversion = drush_user_get_class();
if (!($account = $userversion->load_by_uid($uid_or_name))) {
if (!($account = $userversion->load_by_name($uid_or_name))) {
if (is_numeric($uid_or_name)) {
$message = dt('Could not login with user ID !user.', array('!user' => $uid_or_name));
if ($uid_or_name === 0) {
$message .= ' ' . dt('This is typically caused by importing a MySQL database dump from a faulty tool which re-numbered the anonymous user ID in the users table. See !link for help recovering from this situation.', array('!link' => 'http://drupal.org/node/1029506'));
}
} else {
$message = dt('Could not login with user account `!user\'.', array('!user' => $uid_or_name));
}
return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message);
}
}
$userversion->setCurrentUser($account);
_drush_log_drupal_messages();
}
示例10: drush_main
/**
* The main Drush function.
*
* - Parses the command line arguments, configuration files and environment.
* - Prepares and executes a Drupal bootstrap, if possible,
* - Dispatches the given command.
*
* @return
* Whatever the given command returns.
*/
function drush_main()
{
$phases = _drush_bootstrap_phases(FALSE, TRUE);
drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
// We need some global options processed at this early stage. Namely --debug.
drush_parse_args();
_drush_bootstrap_global_options();
$return = '';
$command_found = FALSE;
foreach ($phases as $phase) {
if (drush_bootstrap_to_phase($phase)) {
$command = drush_parse_command();
// Process a remote command if 'remote-host' option is set.
if (drush_remote_command()) {
$command_found = TRUE;
break;
}
if (is_array($command)) {
$bootstrap_result = drush_bootstrap_to_phase($command['bootstrap']);
drush_enforce_requirement_bootstrap_phase($command);
drush_enforce_requirement_core($command);
drush_enforce_requirement_drupal_dependencies($command);
drush_enforce_requirement_drush_dependencies($command);
if ($bootstrap_result && empty($command['bootstrap_errors'])) {
drush_log(dt("Found command: !command (commandfile=!commandfile)", array('!command' => $command['command'], '!commandfile' => $command['commandfile'])), 'bootstrap');
$command_found = TRUE;
// Dispatch the command(s).
$return = drush_dispatch($command);
// prevent a '1' at the end of the output
if ($return === TRUE) {
$return = '';
}
if (drush_get_context('DRUSH_DEBUG')) {
drush_print_timers();
}
drush_log(dt('Peak memory usage was !peak', array('!peak' => drush_format_size(memory_get_peak_usage()))), 'memory');
break;
}
}
} else {
break;
}
}
if (!$command_found) {
// If we reach this point, we have not found either a valid or matching command.
$args = implode(' ', drush_get_arguments());
if (isset($command) && is_array($command)) {
foreach ($command['bootstrap_errors'] as $key => $error) {
drush_set_error($key, $error);
}
drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The drush command '!args' could not be executed.", array('!args' => $args)));
} elseif (!empty($args)) {
drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt("The drush command '!args' could not be found.", array('!args' => $args)));
}
// Set errors that ocurred in the bootstrap phases.
$errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', array());
foreach ($errors as $code => $message) {
drush_set_error($code, $message);
}
}
// We set this context to let the shutdown function know we reached the end of drush_main();
drush_set_context("DRUSH_EXECUTION_COMPLETED", TRUE);
// After this point the drush_shutdown function will run,
// exiting with the correct exit code.
return $return;
}
示例11: initializeDrush
/**
* Initializes Drush which boostraps Drupal core
*/
public function initializeDrush()
{
define('DRUSH_BASE_PATH', sprintf('%s/../drush', $this->root));
define('DRUSH_REQUEST_TIME', microtime(TRUE));
require_once DRUSH_BASE_PATH . '/includes/bootstrap.inc';
require_once DRUSH_BASE_PATH . '/includes/environment.inc';
require_once DRUSH_BASE_PATH . '/includes/command.inc';
require_once DRUSH_BASE_PATH . '/includes/drush.inc';
require_once DRUSH_BASE_PATH . '/includes/backend.inc';
require_once DRUSH_BASE_PATH . '/includes/batch.inc';
require_once DRUSH_BASE_PATH . '/includes/context.inc';
require_once DRUSH_BASE_PATH . '/includes/sitealias.inc';
require_once DRUSH_BASE_PATH . '/includes/exec.inc';
require_once DRUSH_BASE_PATH . '/includes/drupal.inc';
require_once DRUSH_BASE_PATH . '/includes/output.inc';
require_once DRUSH_BASE_PATH . '/includes/cache.inc';
require_once DRUSH_BASE_PATH . '/includes/filesystem.inc';
require_once DRUSH_BASE_PATH . '/includes/dbtng.inc';
$drush_info = drush_read_drush_info();
define('DRUSH_VERSION', $drush_info['drush_version']);
$version_parts = explode('.', DRUSH_VERSION);
define('DRUSH_MAJOR_VERSION', $version_parts[0]);
define('DRUSH_MINOR_VERSION', $version_parts[1]);
$GLOBALS['argv'][0] = 'default';
drush_set_context('arguments', array('default', 'help'));
drush_set_context('argc', $GLOBALS['argc']);
drush_set_context('argv', $GLOBALS['argv']);
drush_set_option('root', $this->root);
// make sure the default path point to the correct instance
$currentDirectory = getcwd();
chdir($this->root);
$phases = _drush_bootstrap_phases(FALSE, TRUE);
drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
// We need some global options processed at this early stage. Namely --debug.
_drush_bootstrap_global_options();
$return = '';
$command_found = FALSE;
foreach ($phases as $phase) {
drush_bootstrap_to_phase($phase);
}
chdir($currentDirectory);
}
示例12: tearDown
/**
* Teardown after each test.
*/
public function tearDown()
{
// Reset drush_log for good me assure.
drush_set_context('DRUSH_LOG_CALLBACK', $this->prevLog);
}
示例13: die
* @file
* drush is a PHP script implementing a command line shell for Drupal.
*
* @requires PHP CLI 4.3.0, PHP CLI 5.x, or newer.
*/
// Terminate immediately unless invoked as a command line script
if (!drush_verify_cli()) {
die('drush.php is designed to run via the command line.');
}
require_once dirname(__FILE__) . '/includes/environment.inc';
require_once dirname(__FILE__) . '/includes/command.inc';
require_once dirname(__FILE__) . '/includes/drush.inc';
require_once dirname(__FILE__) . '/includes/backend.inc';
require_once dirname(__FILE__) . '/includes/context.inc';
drush_set_context('argc', $GLOBALS['argc']);
drush_set_context('argv', $GLOBALS['argv']);
exit(drush_main());
/**
* Verify that we are running PHP through the command line interface.
*
* This function is useful for making sure that code cannot be run via the web server,
* such as a function that needs to write files to which the web server should not have
* access to.
*
* @return
* A boolean value that is true when PHP is being run through the command line,
* and false if being run through cgi or mod_php.
*/
function drush_verify_cli()
{
if (php_sapi_name() == 'cgi') {
示例14: testFormatTableWordWrap
/**
* Tests drush_format_table() with word wrapping.
*
* @see drush_format_table().
*/
public function testFormatTableWordWrap()
{
drush_set_context('DRUSH_COLUMNS', 60);
$output = drush_format_table($this->words);
$expected = ' Drush is a command scripting for Drupal ' . PHP_EOL . ' line shell interface ' . PHP_EOL . ' A veritable Swiss Army knife designed to make ' . PHP_EOL . ' life easier for us ' . PHP_EOL;
$this->assertEquals($expected, $output);
}
示例15: drush_main
/**
* The main Drush function.
*
* - Parses the command line arguments, configuration files and environment.
* - Prepares and executes a Drupal bootstrap, if possible,
* - Dispatches the given command.
*
* @return
* Whatever the given command returns.
*/
function drush_main()
{
$phases = _drush_bootstrap_phases();
$return = '';
$command_found = FALSE;
foreach ($phases as $phase) {
if (drush_bootstrap($phase)) {
$command = drush_parse_command();
if (is_array($command)) {
if ($command['bootstrap'] == $phase && empty($command['bootstrap_errors'])) {
drush_log(dt("Found command: !command", array('!command' => $command['command'])), 'bootstrap');
$command_found = TRUE;
// Dispatch the command(s).
$return = drush_dispatch($command);
break;
}
}
} else {
break;
}
}
if (!$command_found) {
// If we reach this point, we have not found either a valid or matching command.
$args = implode(' ', drush_get_arguments());
$drush_command = array_pop(explode('/', DRUSH_COMMAND));
if (isset($command) && is_array($command)) {
foreach ($command['bootstrap_errors'] as $key => $error) {
drush_set_error($key, $error);
}
drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The command '!drush_command !args' could not be executed.", array('!drush_command' => $drush_command, '!args' => $args)));
} elseif (!empty($args)) {
drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt("The command '!drush_command !args' could not be found.", array('!drush_command' => $drush_command, '!args' => $args)));
} else {
// This can occur if we get an error during _drush_bootstrap_drush_validate();
drush_set_error('DRUSH_COULD_NOT_EXECUTE', dt("Drush could not execute."));
}
}
// We set this context to let the shutdown function know we reached the end of drush_main();
drush_set_context("DRUSH_EXECUTION_COMPLETED", TRUE);
// After this point the drush_shutdown function will run,
// exiting with the correct exit code.
return $return;
}