forked from wp-cli/server-command
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.php
54 lines (45 loc) · 1.21 KB
/
command.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
class Server_Command extends WP_CLI_Command {
/**
* 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 ) ) );
}
}
WP_CLI::add_command( 'server', 'Server_Command' );