Example #1
0
 /**
  * Launch PHP's built-in web server for this specific WordPress installation.
  *
  * Uses `php -S` to launch a web server serving the WordPress webroot.
  * <http://php.net/manual/en/features.commandline.webserver.php>
  *
  * ## OPTIONS
  *
  * [--host=<host>]
  * : The hostname to bind the server to.
  * ---
  * default: localhost
  * ---
  *
  * [--port=<port>]
  * : The port number to bind the server to.
  * ---
  * default: 8080
  * ---
  *
  * [--docroot=<path>]
  * : The path to use as the document root.
  *
  * [--config=<file>]
  * : Configure the server with a specific .ini file.
  *
  * ## EXAMPLES
  *
  *     # Make the instance available on any address (with port 8080)
  *     $ wp server --host=0.0.0.0
  *     PHP 5.6.9 Development Server started at Tue May 24 01:27:11 2016
  *     Listening on http://0.0.0.0:8080
  *     Document root is /
  *     Press Ctrl-C to quit.
  *
  *     # Run on port 80 (for multisite)
  *     $ sudo wp server --host=localhost.localdomain --port=80
  *     PHP 5.6.9 Development Server started at Tue May 24 01:30:06 2016
  *     Listening on http://localhost1.localdomain1:8080
  *     Document root is /
  *     Press Ctrl-C to quit.
  *
  *     # Configure the server with a specific .ini file
  *     $ wp server --config=development.ini
  *     PHP 7.0.9 Development Server started at Mon Aug 22 12:09:04 2016
  *     Listening on http://localhost:8080
  *     Document root is /
  *     Press Ctrl-C to quit.
  *
  * @when before_wp_load
  */
 function __invoke($_, $assoc_args)
 {
     $min_version = '5.4';
     if (version_compare(PHP_VERSION, $min_version, '<')) {
         WP_CLI::error("The `wp server` command requires PHP {$min_version} or newer.");
     }
     $defaults = array('host' => 'localhost', 'port' => 8080, 'docroot' => false, 'config' => get_cfg_var('cfg_file_path'));
     $assoc_args = array_merge($defaults, $assoc_args);
     $docroot = $assoc_args['docroot'];
     if (!$docroot) {
         $config_path = WP_CLI::get_runner()->project_config_path;
         if (!$config_path) {
             $docroot = ABSPATH;
         } else {
             $docroot = dirname($config_path);
         }
     }
     $cmd = \WP_CLI\Utils\esc_cmd('%s -S %s -t %s -c %s %s', PHP_BINARY, $assoc_args['host'] . ':' . $assoc_args['port'], $docroot, $assoc_args['config'], \WP_CLI\Utils\extract_from_phar(WP_CLI_ROOT . '/php/router.php'));
     $descriptors = array(STDIN, STDOUT, STDERR);
     // https://bugs.php.net/bug.php?id=60181
     $options = array();
     if (\WP_CLI\Utils\is_windows()) {
         $options["bypass_shell"] = TRUE;
     }
     exit(proc_close(proc_open($cmd, $descriptors, $pipes, NULL, NULL, $options)));
 }
Example #2
0
 /**
  * Start a development server.
  *
  * ## OPTIONS
  *
  * --host=<host>
  * : The hostname to bind the server to. Default: localhost
  *
  * --port=<port>
  * : The port number to bind the server to. Default: 8080
  *
  * ## EXAMPLES
  *
  *     # Make the instance available on any address (with port 8080)
  *     wp server --host=0.0.0.0
  *
  *     # Run on port 80 (for multisite)
  *     sudo wp server --host=localhost.localdomain --port=80
  *
  * @when before_wp_load
  * @synopsis [--host=<host>] [--port=<port>]
  */
 function __invoke($_, $assoc_args)
 {
     $defaults = array('host' => 'localhost', 'port' => 8080);
     $assoc_args = array_merge($defaults, $assoc_args);
     $cmd = \WP_CLI\Utils\esc_cmd(PHP_BINARY . ' -S %s %s', $assoc_args['host'] . ':' . $assoc_args['port'], __DIR__ . '/router.php');
     $config_path = WP_CLI::get_runner()->project_config_path;
     if (!$config_path) {
         $docroot = ABSPATH;
     } else {
         $docroot = dirname($config_path);
     }
     $descriptors = array(STDIN, STDOUT, STDERR);
     exit(proc_close(proc_open($cmd, $descriptors, $pipes, $docroot)));
 }
Example #3
0
 /**
  * Launch redis-cli using Redis configuration for WordPress
  */
 public function cli()
 {
     global $redis_server;
     if (empty($redis_server)) {
         # Attempt to automatically load Pantheon's Redis config from the env.
         if (isset($_SERVER['CACHE_HOST'])) {
             $redis_server = array('host' => $_SERVER['CACHE_HOST'], 'port' => $_SERVER['CACHE_PORT'], 'auth' => $_SERVER['CACHE_PASSWORD']);
         } else {
             $redis_server = array('host' => '127.0.0.1', 'port' => 6379);
         }
     }
     if (!isset($redis_server['database'])) {
         $redis_server['database'] = 0;
     }
     $cmd = WP_CLI\Utils\esc_cmd('redis-cli -h %s -p %s -a %s -n %d', $redis_server['host'], $redis_server['port'], $redis_server['auth'], $redis_server['database']);
     WP_CLI::launch($cmd);
 }
Example #4
0
 /**
  * Launch PHP's built-in web server for this specific WordPress installation.
  *
  * <http://php.net/manual/en/features.commandline.webserver.php>
  *
  * ## OPTIONS
  *
  * [--host=<host>]
  * : The hostname to bind the server to. Default: localhost
  *
  * [--port=<port>]
  * : The port number to bind the server to. Default: 8080
  *
  * [--docroot=<path>]
  * : The path to use as the document root.
  *
  * ## EXAMPLES
  *
  *     # Make the instance available on any address (with port 8080)
  *     wp server --host=0.0.0.0
  *
  *     # Run on port 80 (for multisite)
  *     sudo wp server --host=localhost.localdomain --port=80
  *
  * @when before_wp_load
  */
 function __invoke($_, $assoc_args)
 {
     $min_version = '5.4';
     if (version_compare(PHP_VERSION, $min_version, '<')) {
         WP_CLI::error("The `wp server` command requires PHP {$min_version} or newer.");
     }
     $defaults = array('host' => 'localhost', 'port' => 8080, 'docroot' => false);
     $assoc_args = array_merge($defaults, $assoc_args);
     $docroot = $assoc_args['docroot'];
     if (!$docroot) {
         $config_path = WP_CLI::get_runner()->project_config_path;
         if (!$config_path) {
             $docroot = ABSPATH;
         } else {
             $docroot = dirname($config_path);
         }
     }
     $cmd = \WP_CLI\Utils\esc_cmd(PHP_BINARY . ' -S %s -t %s %s', $assoc_args['host'] . ':' . $assoc_args['port'], $docroot, \WP_CLI\Utils\extract_from_phar(WP_CLI_ROOT . '/php/router.php'));
     $descriptors = array(STDIN, STDOUT, STDERR);
     exit(proc_close(proc_open($cmd, $descriptors, $pipes)));
 }
    $wp_config_path = $world->variables['RUN_DIR'] . "/wp-config.php";
    $wp_config_code = file_get_contents($wp_config_path);
    $world->move_files('wp-content', 'my-content');
    $world->add_line_to_wp_config($wp_config_code, "define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/my-content' );");
    $world->move_files('my-content/plugins', 'my-plugins');
    $world->add_line_to_wp_config($wp_config_code, "define( 'WP_PLUGIN_DIR', __DIR__ . '/my-plugins' );");
    file_put_contents($wp_config_path, $wp_config_code);
});
$steps->Given('/^download:$/', function ($world, TableNode $table) {
    foreach ($table->getHash() as $row) {
        $path = $world->replace_variables($row['path']);
        if (file_exists($path)) {
            // assume it's the same file and skip re-download
            continue;
        }
        Process::create(\WP_CLI\Utils\esc_cmd('curl -sSL %s > %s', $row['url'], $path))->run_check();
    }
});
$steps->Given('/^save (STDOUT|STDERR) ([\'].+[^\'])?as \\{(\\w+)\\}$/', function ($world, $stream, $output_filter, $key) {
    $stream = strtolower($stream);
    if ($output_filter) {
        $output_filter = '/' . trim(str_replace('%s', '(.+[^\\b])', $output_filter), "' ") . '/';
        if (false !== preg_match($output_filter, $world->result->{$stream}, $matches)) {
            $output = array_pop($matches);
        } else {
            $output = '';
        }
    } else {
        $output = $world->result->{$stream};
    }
    $world->variables[$key] = trim($output, "\n");
Example #6
0
 /**
  * Create a default composer.json, should one not already exist
  *
  * @param string $composer_path Where the composer.json should be created
  * @return true|WP_Error
  */
 private function create_default_composer_json($composer_path)
 {
     $composer_dir = pathinfo($composer_path, PATHINFO_DIRNAME);
     if (!is_dir($composer_dir)) {
         \WP_CLI\Process::create(WP_CLI\Utils\esc_cmd('mkdir -p %s', $composer_dir))->run();
     }
     if (!is_dir($composer_dir)) {
         WP_CLI::error("Composer directory for packages couldn't be created.");
     }
     $json_file = new JsonFile($composer_path);
     $author = (object) array('name' => 'WP-CLI', 'email' => '*****@*****.**');
     $repositories = (object) array('wp-cli' => (object) array('type' => 'composer', 'url' => self::PACKAGE_INDEX_URL));
     $options = array('name' => 'wp-cli/wp-cli', 'description' => 'Installed community packages used by WP-CLI', 'version' => self::get_wp_cli_version_composer(), 'authors' => array($author), 'homepage' => self::PACKAGE_INDEX_URL, 'require' => new stdClass(), 'require-dev' => new stdClass(), 'minimum-stability' => 'dev', 'license' => 'MIT', 'repositories' => $repositories);
     try {
         $json_file->write($options);
     } catch (Exception $e) {
         WP_CLI::error($e->getMessage());
     }
     return true;
 }