当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_CLI::logger方法代码示例

本文整理汇总了PHP中WP_CLI::logger方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::logger方法的具体用法?PHP WP_CLI::logger怎么用?PHP WP_CLI::logger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_CLI的用法示例。


在下文中一共展示了WP_CLI::logger方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: set_logger

 /**
  * Set the logger instance.
  *
  * @param object $logger
  */
 public static function set_logger($logger)
 {
     self::$logger = $logger;
 }
开发者ID:pardakhtchi,项目名称:wp-cli,代码行数:9,代码来源:class-wp-cli.php

示例2: runcommand

 /**
  * Run a WP-CLI command.
  *
  * Launch a new child process, or run the command in the current process.
  * Optionally:
  * * Prevent halting script execution on error.
  * * Capture and return STDOUT, or full details about command execution.
  * * Parse JSON output if the command rendered it.
  *
  * ```
  * $options = array(
  *   'return'     => true,   // Return 'STDOUT'; use 'all' for full object.
  *   'parse'      => 'json', // Parse captured STDOUT to JSON array.
  *   'launch'     => false,  // Reuse the current process.
  *   'exit_error' => true,   // Halt script execution on error.
  * );
  * $plugins = WP_CLI::runcommand( 'plugin list --format=json', $options );
  * ```
  *
  * @access public
  * @category Execution
  *
  * @param string $command WP-CLI command to run, including arguments.
  * @param array  $options Configuration options for command execution.
  * @return mixed
  */
 public static function runcommand($command, $options = array())
 {
     $defaults = array('launch' => true, 'exit_error' => true, 'return' => false, 'parse' => false);
     $options = array_merge($defaults, $options);
     $launch = $options['launch'];
     $exit_error = $options['exit_error'];
     $return = $options['return'];
     $parse = $options['parse'];
     $retval = null;
     if ($launch) {
         if ($return) {
             $descriptors = array(0 => STDIN, 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
         } else {
             $descriptors = array(0 => STDIN, 1 => STDOUT, 2 => STDERR);
         }
         $php_bin = self::get_php_binary();
         $script_path = $GLOBALS['argv'][0];
         // Persist runtime arguments unless they've been specified otherwise.
         $configurator = \WP_CLI::get_configurator();
         $argv = array_slice($GLOBALS['argv'], 1);
         list($_, $_, $runtime_config) = $configurator->parse_args($argv);
         foreach ($runtime_config as $k => $v) {
             if (preg_match("|^--{$key}=?\$|", $command)) {
                 unset($runtime_config[$k]);
             }
         }
         $runtime_config = Utils\assoc_args_to_str($runtime_config);
         $runcommand = "{$php_bin} {$script_path} {$runtime_config} {$command}";
         $env_vars = array('HOME', 'WP_CLI_AUTO_CHECK_UPDATE_DAYS', 'WP_CLI_CACHE_DIR', 'WP_CLI_CONFIG_PATH', 'WP_CLI_DISABLE_AUTO_CHECK_UPDATE', 'WP_CLI_PACKAGES_DIR', 'WP_CLI_PHP_USED', 'WP_CLI_PHP', 'WP_CLI_STRICT_ARGS_MODE');
         $env = array();
         foreach ($env_vars as $var) {
             $env[$var] = getenv($var);
         }
         $proc = proc_open($runcommand, $descriptors, $pipes, getcwd(), $env);
         if ($return) {
             $stdout = stream_get_contents($pipes[1]);
             fclose($pipes[1]);
             $stderr = stream_get_contents($pipes[2]);
             fclose($pipes[2]);
         }
         $return_code = proc_close($proc);
         if (-1 == $return_code) {
             self::warning("Spawned process returned exit code -1, which could be caused by a custom compiled version of PHP that uses the --enable-sigchild option.");
         } else {
             if ($return_code && $exit_error) {
                 exit($return_code);
             }
         }
         if (true === $return || 'stdout' === $return) {
             $retval = trim($stdout);
         } else {
             if ('stderr' === $return) {
                 $retval = trim($stderr);
             } else {
                 if ('return_code' === $return) {
                     $retval = $return_code;
                 } else {
                     if ('all' === $return) {
                         $retval = (object) array('stdout' => trim($stdout), 'stderr' => trim($stderr), 'return_code' => $return_code);
                     }
                 }
             }
         }
     } else {
         $configurator = self::get_configurator();
         $argv = Utils\parse_str_to_argv($command);
         list($args, $assoc_args, $runtime_config) = $configurator->parse_args($argv);
         if ($return) {
             ob_start();
             $existing_logger = self::$logger;
             self::$logger = new WP_CLI\Loggers\Execution();
         }
         if (!$exit_error) {
             self::$capture_exit = true;
//.........这里部分代码省略.........
开发者ID:wp-cli,项目名称:wp-cli,代码行数:101,代码来源:class-wp-cli.php


注:本文中的WP_CLI::logger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。