OSDN Git Service

move set_url_params() to WP_CLI\Runner
authorscribu <mail@scribu.net>
Wed, 17 Jul 2013 00:36:23 +0000 (03:36 +0300)
committerscribu <mail@scribu.net>
Wed, 17 Jul 2013 00:36:26 +0000 (03:36 +0300)
It wasn't really meant to be a public utility. We just didn't have a
runner class back then.

php/WP_CLI/Runner.php
php/utils.php

index 497208b..dc18ebf 100644 (file)
@@ -143,6 +143,28 @@ class Runner {
                return false;
        }
 
+       private static function set_url_params( $url_parts ) {
+               $f = function( $key ) use ( $url_parts ) {
+                       return isset( $url_parts[ $key ] ) ? $url_parts[ $key ] : '';
+               };
+
+               if ( isset( $url_parts['host'] ) ) {
+                       $_SERVER['HTTP_HOST'] = $url_parts['host'];
+                       if ( isset( $url_parts['port'] ) ) {
+                               $_SERVER['HTTP_HOST'] .= ':' . $url_parts['port'];
+                       }
+
+                       $_SERVER['SERVER_NAME'] = substr($_SERVER['HTTP_HOST'], 0, strrpos($_SERVER['HTTP_HOST'], '.'));
+               }
+
+               $_SERVER['REQUEST_URI'] = $f('path') . ( isset( $url_parts['query'] ) ? '?' . $url_parts['query'] : '' );
+               $_SERVER['SERVER_PORT'] = isset( $url_parts['port'] ) ? $url_parts['port'] : '80';
+               $_SERVER['QUERY_STRING'] = $f('query');
+               $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0';
+               $_SERVER['HTTP_USER_AGENT'] = '';
+               $_SERVER['REQUEST_METHOD'] = 'GET';
+       }
+
        private function cmd_starts_with( $prefix ) {
                return $prefix == array_slice( $this->arguments, 0, count( $prefix ) );
        }
@@ -342,7 +364,7 @@ class Runner {
                $url = self::guess_url( $this->config );
                if ( $url ) {
                        $url_parts = self::parse_url( $url );
-                       Utils\set_url_params( $url_parts );
+                       self::set_url_params( $url_parts );
                }
 
                $this->do_early_invoke( 'before_wp_load' );
@@ -376,7 +398,7 @@ class Runner {
                        // We really need a URL here
                        if ( !isset( $_SERVER['HTTP_HOST'] ) ) {
                                $url_parts = self::parse_url( 'http://example.com' );
-                               Utils\set_url_params( $url_parts );
+                               self::set_url_params( $url_parts );
                        }
 
                        if ( 'multisite-install' == $this->arguments[1] ) {
index cb21c7a..9c03963 100644 (file)
@@ -137,33 +137,6 @@ function esc_cmd( $cmd ) {
        return vsprintf( $cmd, array_map( 'escapeshellarg', $args ) );
 }
 
-/**
- * Sets the appropriate $_SERVER keys based on a given string
- *
- * @param array $url_parts The URL, as represented by parse_url()
- */
-function set_url_params( $url_parts ) {
-       $f = function( $key ) use ( $url_parts ) {
-               return isset( $url_parts[ $key ] ) ? $url_parts[ $key ] : '';
-       };
-
-       if ( isset( $url_parts['host'] ) ) {
-               $_SERVER['HTTP_HOST'] = $url_parts['host'];
-               if ( isset( $url_parts['port'] ) ) {
-                       $_SERVER['HTTP_HOST'] .= ':' . $url_parts['port'];
-               }
-
-               $_SERVER['SERVER_NAME'] = substr($_SERVER['HTTP_HOST'], 0, strrpos($_SERVER['HTTP_HOST'], '.'));
-       }
-
-       $_SERVER['REQUEST_URI'] = $f('path') . ( isset( $url_parts['query'] ) ? '?' . $url_parts['query'] : '' );
-       $_SERVER['SERVER_PORT'] = isset( $url_parts['port'] ) ? $url_parts['port'] : '80';
-       $_SERVER['QUERY_STRING'] = $f('query');
-       $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0';
-       $_SERVER['HTTP_USER_AGENT'] = '';
-       $_SERVER['REQUEST_METHOD'] = 'GET';
-}
-
 function locate_wp_config() {
        static $path;