PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/php/commands/eval-file.php

https://github.com/rclilly/wp-cli
PHP | 36 lines | 14 code | 7 blank | 15 comment | 1 complexity | 4515e3265f315620cec381b713b9da92 MD5 | raw file
  1. <?php
  2. class EvalFile_Command extends WP_CLI_Command {
  3. /**
  4. * Load and execute a PHP file after loading WordPress.
  5. *
  6. * ## OPTIONS
  7. *
  8. * <file>
  9. * : The path to the PHP file to execute.
  10. *
  11. * [<arg>...]
  12. * : One or more arguments to pass to the file. They are placed in the $args variable.
  13. *
  14. * ## EXAMPLES
  15. *
  16. * wp eval-file my-code.php value1 value2
  17. */
  18. public function __invoke( $args ) {
  19. $file = array_shift( $args );
  20. if ( !file_exists( $file ) ) {
  21. WP_CLI::error( "'$file' does not exist." );
  22. }
  23. self::_eval( $file, $args );
  24. }
  25. private static function _eval( $file, $args ) {
  26. include( $file );
  27. }
  28. }
  29. WP_CLI::add_command( 'eval-file', 'EvalFile_Command' );