diff --git a/README.md b/README.md index 159f1a657..be9e4494d 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ to be explicitly globalized. **OPTIONS** - The path to the PHP file to execute. + The path to the PHP file to execute. Use '-' to run code from STDIN. [...] One or more arguments to pass to the file. They are placed in the $args variable. diff --git a/features/eval.feature b/features/eval.feature index f2df1e61b..727f03aca 100644 --- a/features/eval.feature +++ b/features/eval.feature @@ -57,3 +57,17 @@ Feature: Evaluating PHP code and files. """ bool(false) """ + + Scenario: Eval stdin with args + Given an empty directory + And a script.php file: + """ + - * : The path to the PHP file to execute. + * : The path to the PHP file to execute. Use '-' to run code from STDIN. * * [...] * : One or more arguments to pass to the file. They are placed in the $args variable. @@ -28,7 +28,7 @@ class EvalFile_Command extends WP_CLI_Command { public function __invoke( $args, $assoc_args ) { $file = array_shift( $args ); - if ( !file_exists( $file ) ) { + if ( '-' !== $file && !file_exists( $file ) ) { WP_CLI::error( "'$file' does not exist." ); } @@ -40,7 +40,11 @@ public function __invoke( $args, $assoc_args ) { } private static function _eval( $file, $args ) { - include( $file ); + if ( '-' === $file ) { + eval( '?>' . file_get_contents('php://stdin') ); + } else { + include $file; + } } }