Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ to be explicitly globalized.
**OPTIONS**

<file>
The path to the PHP file to execute.
The path to the PHP file to execute. Use '-' to run code from STDIN.

[<arg>...]
One or more arguments to pass to the file. They are placed in the $args variable.
Expand Down
14 changes: 14 additions & 0 deletions features/eval.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
<?php
WP_CLI::line( implode( ' ', $args ) );
"""

When I run `cat script.php | wp eval-file - x y z --skip-wordpress`
Then STDOUT should contain:
"""
x y z
"""
10 changes: 7 additions & 3 deletions src/EvalFile_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EvalFile_Command extends WP_CLI_Command {
* ## OPTIONS
*
* <file>
* : The path to the PHP file to execute.
* : The path to the PHP file to execute. Use '-' to run code from STDIN.
*
* [<arg>...]
* : One or more arguments to pass to the file. They are placed in the $args variable.
Expand All @@ -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." );
}

Expand All @@ -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;
}
}
}