-
Notifications
You must be signed in to change notification settings - Fork 19
Add passthrough arguments to PHP binary via -- separator
#90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e926c03
c5179eb
6d022b6
558b46a
ab589c1
bfee089
20d13ff
00eed65
cefd4f1
38c8b98
d215542
820f666
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,10 @@ class Server_Command extends WP_CLI_Command { | |||||||||
| * [--config=<file>] | ||||||||||
| * : Configure the server with a specific .ini file. | ||||||||||
| * | ||||||||||
| * [<passthrough>...] | ||||||||||
| * : Optional arguments to pass to the PHP binary. Any arguments after `--` | ||||||||||
| * will be passed through to the `php` command. | ||||||||||
| * | ||||||||||
| * ## EXAMPLES | ||||||||||
| * | ||||||||||
| * # Make the instance available on any address (with port 8080) | ||||||||||
|
|
@@ -57,9 +61,20 @@ class Server_Command extends WP_CLI_Command { | |||||||||
| * Document root is / | ||||||||||
| * Press Ctrl-C to quit. | ||||||||||
| * | ||||||||||
| * # Pass extra parameters to the PHP binary | ||||||||||
| * $ wp server --docroot=public -- -dzend_extension=xdebug.so | ||||||||||
| * PHP 7.4.0 Development Server started at Wed Nov 10 18:00:00 2025 | ||||||||||
| * Listening on http://localhost:8080 | ||||||||||
| * Document root is /var/www/public | ||||||||||
| * Press Ctrl-C to quit. | ||||||||||
| * | ||||||||||
| * @when before_wp_load | ||||||||||
| * | ||||||||||
| * @param array<string> $args Positional arguments passed through to the PHP binary. | ||||||||||
| * @param array{host: string, port: string, docroot?: string, config?: string} $assoc_args Associative arguments passed to the command. | ||||||||||
| * @return void | ||||||||||
| */ | ||||||||||
| public function __invoke( $_, $assoc_args ) { | ||||||||||
| public function __invoke( $args, $assoc_args ) { | ||||||||||
swissspidy marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| $defaults = array( | ||||||||||
| 'host' => 'localhost', | ||||||||||
| 'port' => 8080, | ||||||||||
|
|
@@ -86,14 +101,25 @@ public function __invoke( $_, $assoc_args ) { | |||||||||
| if ( ! file_exists( $router_path ) ) { | ||||||||||
| WP_CLI::error( "Couldn't find router.php" ); | ||||||||||
| } | ||||||||||
| $cmd = Utils\esc_cmd( | ||||||||||
| '%s -S %s -t %s -c %s %s', | ||||||||||
| WP_CLI::get_php_binary(), | ||||||||||
| $assoc_args['host'] . ':' . $assoc_args['port'], | ||||||||||
| $docroot, | ||||||||||
| $assoc_args['config'], | ||||||||||
| Utils\extract_from_phar( $router_path ) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| // Build the command with passthrough arguments | ||||||||||
| $cmd_format = '%s'; | ||||||||||
| $cmd_args = array( WP_CLI::get_php_binary() ); | ||||||||||
|
|
||||||||||
| // Add passthrough arguments before the -S flag | ||||||||||
| if ( ! empty( $args ) ) { | ||||||||||
| $cmd_format .= str_repeat( ' %s', count( $args ) ); | ||||||||||
| $cmd_args = array_merge( $cmd_args, $args ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Add the server flags | ||||||||||
| $cmd_format .= ' -S %s -t %s -c %s %s'; | ||||||||||
| $cmd_args[] = $assoc_args['host'] . ':' . $assoc_args['port']; | ||||||||||
| $cmd_args[] = $docroot; | ||||||||||
| $cmd_args[] = $assoc_args['config']; | ||||||||||
| $cmd_args[] = Utils\extract_from_phar( $router_path ); | ||||||||||
|
|
||||||||||
| $cmd = Utils\esc_cmd( $cmd_format, ...$cmd_args ); | ||||||||||
|
||||||||||
| $cmd = Utils\esc_cmd( $cmd_format, ...$cmd_args ); | |
| $esc_cmd_args = $cmd_args; | |
| array_unshift( $esc_cmd_args, $cmd_format ); | |
| $cmd = call_user_func_array( 'WP_CLI\Utils\esc_cmd', $esc_cmd_args ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot This is incorrect. We require PHP 7.2+. Remove that check from server-command.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 820f666. Removed the before_invoke PHP 5.4 version check from server-command.php and updated the @require-php-5.4 Behat feature tag to @require-php-7.2 to match the actual requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PHPDoc array-shape for
$assoc_argsdoesn't match the actual values used in this method:portis anintby default, and bothdocrootandconfigcan befalse(see$defaults). Withphpstan.neon.distno longer suppressing missing types, this mismatch can lead to incorrect static analysis results. Update the PHPDoc to reflect the real types (e.g.,port: int|string,docroot: string|false,config: string|false).