From b9cf24535d68900a2e0e4edf519609cfc5b0d39b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Smoli=C5=84ski?= Date: Sun, 21 Apr 2019 04:53:15 +0200 Subject: [PATCH 01/21] Implement CS checking based on the `WP_CLI_CS` ruleset --- .distignore | 3 +++ .gitignore | 3 +++ composer.json | 2 +- php.xml.dist | 54 ++++++++++++++++++++++++++++++++++++++++++++++ server-command.php | 6 +++--- 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 php.xml.dist diff --git a/.distignore b/.distignore index b964b40..b5a65a8 100644 --- a/.distignore +++ b/.distignore @@ -1,4 +1,5 @@ .DS_Store + .git .gitignore .gitlab-ci.yml @@ -6,6 +7,8 @@ .travis.yml behat.yml circle.yml +phpcs.xml.dist +phpunit.xml.dist bin/ features/ utils/ diff --git a/.gitignore b/.gitignore index ff49419..580eb7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ .DS_Store +.phpcs.xml wp-cli.local.yml node_modules/ vendor/ *.zip *.tar.gz composer.lock +phpunit.xml +phpcs.xml *.log diff --git a/composer.json b/composer.json index 05e7dde..18c3fa7 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "wp-cli/wp-cli": "^2" }, "require-dev": { - "wp-cli/wp-cli-tests": "^2.0.7" + "wp-cli/wp-cli-tests": "^2.1" }, "config": { "process-timeout": 7200, diff --git a/php.xml.dist b/php.xml.dist new file mode 100644 index 0000000..1db639d --- /dev/null +++ b/php.xml.dist @@ -0,0 +1,54 @@ + + + Custom ruleset for WP-CLI server-command + + + + + . + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server-command.php b/server-command.php index 3714abb..fd33c98 100644 --- a/server-command.php +++ b/server-command.php @@ -4,9 +4,9 @@ return; } -$autoload = dirname( __FILE__ ) . '/vendor/autoload.php'; -if ( file_exists( $autoload ) ) { - require_once $autoload; +$wpcli_server_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php'; +if ( file_exists( $wpcli_server_autoloader ) ) { + require_once $wpcli_server_autoloader; } WP_CLI::add_command( 'server', 'Server_Command', array( From 27ac3e24ae536ad21b5fb136c1ab11d454105a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Smoli=C5=84ski?= Date: Sun, 21 Apr 2019 04:59:17 +0200 Subject: [PATCH 02/21] remove blank line --- .distignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.distignore b/.distignore index b5a65a8..95b52fb 100644 --- a/.distignore +++ b/.distignore @@ -1,5 +1,4 @@ .DS_Store - .git .gitignore .gitlab-ci.yml From 138e6e1a94a4c593c518e03fadf6684bbc2e8e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Smoli=C5=84ski?= Date: Sun, 21 Apr 2019 05:13:34 +0200 Subject: [PATCH 03/21] rename custom rulset file + phpcbf --- php.xml.dist => phpcs.xml.dist | 0 router.php | 89 ++++++++++++++++++++-------------- server-command.php | 20 +++++--- src/Server_Command.php | 21 ++++---- 4 files changed, 75 insertions(+), 55 deletions(-) rename php.xml.dist => phpcs.xml.dist (100%) diff --git a/php.xml.dist b/phpcs.xml.dist similarity index 100% rename from php.xml.dist rename to phpcs.xml.dist diff --git a/router.php b/router.php index 9c3bdc6..e2aedce 100644 --- a/router.php +++ b/router.php @@ -8,11 +8,14 @@ * * We duplicate it because WordPress is not loaded yet. */ -function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) { +function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { global $wp_filter, $merged_filters; - $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority); - $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); + $idx = _wp_filter_build_unique_id( $tag, $function_to_add, $priority ); + $wp_filter[ $tag ][ $priority ][ $idx ] = array( + 'function' => $function_to_add, + 'accepted_args' => $accepted_args, + ); unset( $merged_filters[ $tag ] ); return true; } @@ -22,30 +25,32 @@ function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) * * We duplicate it because WordPress is not loaded yet. */ -function _wp_filter_build_unique_id($tag, $function, $priority) { +function _wp_filter_build_unique_id( $tag, $function, $priority ) { global $wp_filter; static $filter_id_count = 0; - if ( is_string($function) ) + if ( is_string( $function ) ) { return $function; + } - if ( is_object($function) ) { + if ( is_object( $function ) ) { // Closures are currently implemented as objects $function = array( $function, '' ); } else { $function = (array) $function; } - if (is_object($function[0]) ) { + if ( is_object( $function[0] ) ) { // Object Class Calling - if ( function_exists('spl_object_hash') ) { - return spl_object_hash($function[0]) . $function[1]; + if ( function_exists( 'spl_object_hash' ) ) { + return spl_object_hash( $function[0] ) . $function[1]; } else { - $obj_idx = get_class($function[0]).$function[1]; - if ( !isset($function[0]->wp_filter_id) ) { - if ( false === $priority ) + $obj_idx = get_class( $function[0] ) . $function[1]; + if ( ! isset( $function[0]->wp_filter_id ) ) { + if ( false === $priority ) { return false; - $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count; + } + $obj_idx .= isset( $wp_filter[ $tag ][ $priority ] ) ? count( (array) $wp_filter[ $tag ][ $priority ] ) : $filter_id_count; $function[0]->wp_filter_id = $filter_id_count; ++$filter_id_count; } else { @@ -54,7 +59,7 @@ function _wp_filter_build_unique_id($tag, $function, $priority) { return $obj_idx; } - } else if ( is_string($function[0]) ) { + } elseif ( is_string( $function[0] ) ) { // Static Calling return $function[0] . '::' . $function[1]; } @@ -64,46 +69,56 @@ function _get_full_host( $url ) { $parsed_url = parse_url( $url ); $host = $parsed_url['host']; - if ( isset( $parsed_url['port'] ) && $parsed_url['port'] != 80 ) + if ( isset( $parsed_url['port'] ) && $parsed_url['port'] != 80 ) { $host .= ':' . $parsed_url['port']; + } return $host; } // We need to trick WordPress into using the URL set by `wp server`, especially on multisite. -add_filter( 'option_home', function ( $url ) { - $GLOBALS['_wp_cli_original_url'] = $url; - - return 'http://' . $_SERVER['HTTP_HOST']; -}, 20 ); - -add_filter( 'option_siteurl', function ( $url ) { - if ( !isset( $GLOBALS['_wp_cli_original_url'] ) ) - get_option('home'); // trigger the option_home filter +add_filter( + 'option_home', + function ( $url ) { + $GLOBALS['_wp_cli_original_url'] = $url; + + return 'http://' . $_SERVER['HTTP_HOST']; + }, + 20 +); + +add_filter( + 'option_siteurl', + function ( $url ) { + if ( ! isset( $GLOBALS['_wp_cli_original_url'] ) ) { + get_option( 'home' ); // trigger the option_home filter + } - $home_url_host = _get_full_host( $GLOBALS['_wp_cli_original_url'] ); - $site_url_host = _get_full_host( $url ); + $home_url_host = _get_full_host( $GLOBALS['_wp_cli_original_url'] ); + $site_url_host = _get_full_host( $url ); - if ( $site_url_host == $home_url_host ) { - $url = str_replace( $site_url_host, $_SERVER['HTTP_HOST'], $url ); - } + if ( $site_url_host == $home_url_host ) { + $url = str_replace( $site_url_host, $_SERVER['HTTP_HOST'], $url ); + } - return $url; -}, 20 ); + return $url; + }, + 20 +); $_SERVER['SERVER_ADDR'] = gethostbyname( $_SERVER['SERVER_NAME'] ); -$root = $_SERVER['DOCUMENT_ROOT']; -$path = '/'. ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ) )['path'], '/' ); +$root = $_SERVER['DOCUMENT_ROOT']; +$path = '/' . ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ) )['path'], '/' ); -if ( file_exists( $root.$path ) ) { - if ( is_dir( $root.$path ) && substr( $path, -1 ) !== '/' ) { +if ( file_exists( $root . $path ) ) { + if ( is_dir( $root . $path ) && substr( $path, -1 ) !== '/' ) { header( "Location: $path/" ); exit; } if ( strpos( $path, '.php' ) !== false ) { - chdir( dirname( $root.$path ) ); - require_once $root.$path; + chdir( dirname( $root . $path ) ); + require_once $root . $path; } else { return false; } diff --git a/server-command.php b/server-command.php index fd33c98..d1f5d56 100644 --- a/server-command.php +++ b/server-command.php @@ -9,11 +9,15 @@ require_once $wpcli_server_autoloader; } -WP_CLI::add_command( 'server', 'Server_Command', array( - 'before_invoke' => function() { - $min_version = '5.4'; - if ( version_compare( PHP_VERSION, $min_version, '<' ) ) { - WP_CLI::error( "The `wp server` command requires PHP {$min_version} or newer." ); - } - } -) ); +WP_CLI::add_command( + 'server', + 'Server_Command', + array( + 'before_invoke' => function() { + $min_version = '5.4'; + if ( version_compare( PHP_VERSION, $min_version, '<' ) ) { + WP_CLI::error( "The `wp server` command requires PHP {$min_version} or newer." ); + } + }, + ) +); diff --git a/src/Server_Command.php b/src/Server_Command.php index 93a2ed6..10a5f01 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -58,20 +58,20 @@ class Server_Command extends WP_CLI_Command { * @when before_wp_load */ function __invoke( $_, $assoc_args ) { - $defaults = array( - 'host' => 'localhost', - 'port' => 8080, + $defaults = array( + 'host' => 'localhost', + 'port' => 8080, 'docroot' => ! is_null( WP_CLI::get_runner()->config['path'] ) ? WP_CLI::get_runner()->config['path'] : false, - 'config' => get_cfg_var( 'cfg_file_path' ) + 'config' => get_cfg_var( 'cfg_file_path' ), ); $assoc_args = array_merge( $defaults, $assoc_args ); $docroot = $assoc_args['docroot']; - if ( !$docroot ) { + if ( ! $docroot ) { $config_path = WP_CLI::get_runner()->project_config_path; - if ( !$config_path ) { + if ( ! $config_path ) { $docroot = ABSPATH; } else { $docroot = dirname( $config_path ); @@ -80,11 +80,12 @@ function __invoke( $_, $assoc_args ) { // Get the path to the router file $command_root = WP_CLI\Utils\phar_safe_path( dirname( __DIR__ ) ); - $router_path = $command_root . '/router.php'; + $router_path = $command_root . '/router.php'; if ( ! file_exists( $router_path ) ) { WP_CLI::error( "Couldn't find router.php" ); } - $cmd = \WP_CLI\Utils\esc_cmd( '%s -S %s -t %s -c %s %s', + $cmd = \WP_CLI\Utils\esc_cmd( + '%s -S %s -t %s -c %s %s', WP_CLI::get_php_binary(), $assoc_args['host'] . ':' . $assoc_args['port'], $docroot, @@ -97,9 +98,9 @@ function __invoke( $_, $assoc_args ) { // https://bugs.php.net/bug.php?id=60181 $options = array(); if ( \WP_CLI\Utils\is_windows() ) { - $options["bypass_shell"] = TRUE; + $options['bypass_shell'] = true; } - exit( proc_close( proc_open( $cmd, $descriptors, $pipes, NULL, NULL, $options ) ) ); + exit( proc_close( proc_open( $cmd, $descriptors, $pipes, null, null, $options ) ) ); } } From c7fbcd36e4902b6d84f763402bef9a86ae40efe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Smoli=C5=84ski?= Date: Sun, 21 Apr 2019 05:52:16 +0200 Subject: [PATCH 04/21] update rulset --- phpcs.xml.dist | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 1db639d..30d393b 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -46,9 +46,14 @@ + - + + + + */src/Server_Command\.php$ + From 7b056ee2185161bae41ed77609503085be8e891e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Smoli=C5=84ski?= Date: Sun, 21 Apr 2019 05:53:20 +0200 Subject: [PATCH 05/21] fix phpcs in router.php --- router.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/router.php b/router.php index e2aedce..fa04f2f 100644 --- a/router.php +++ b/router.php @@ -1,7 +1,7 @@ Date: Sun, 21 Apr 2019 06:41:52 +0200 Subject: [PATCH 06/21] Update phpcs.xml.dist Co-Authored-By: wojsmol --- phpcs.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 30d393b..ee23721 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -45,7 +45,6 @@ - From bf66f5dd974403b13f1c05e124da662cceb989bb Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 21 Apr 2019 06:42:04 +0200 Subject: [PATCH 07/21] Update phpcs.xml.dist Co-Authored-By: wojsmol --- phpcs.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index ee23721..542077c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -45,7 +45,7 @@ - + From ba6f8f62c162a9851cd87f6afc2ec67dfba21013 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 21 Apr 2019 06:42:26 +0200 Subject: [PATCH 08/21] Update router.php Co-Authored-By: wojsmol --- router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router.php b/router.php index fa04f2f..290f5f0 100644 --- a/router.php +++ b/router.php @@ -1,7 +1,7 @@ Date: Sun, 21 Apr 2019 06:42:38 +0200 Subject: [PATCH 09/21] Update router.php Co-Authored-By: wojsmol --- router.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/router.php b/router.php index 290f5f0..874d8b4 100644 --- a/router.php +++ b/router.php @@ -11,7 +11,8 @@ function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { global $wp_filter, $merged_filters; - $idx = _wp_filter_build_unique_id( $tag, $function_to_add, $priority ); + $idx = _wp_filter_build_unique_id( $tag, $function_to_add, $priority ); + $wp_filter[ $tag ][ $priority ][ $idx ] = array( 'function' => $function_to_add, 'accepted_args' => $accepted_args, From ed8d78806bea22bcd8bc89abca7ed932c29619e3 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 21 Apr 2019 06:42:48 +0200 Subject: [PATCH 10/21] Update src/Server_Command.php Co-Authored-By: wojsmol --- src/Server_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server_Command.php b/src/Server_Command.php index 10a5f01..0b752fd 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -79,7 +79,7 @@ function __invoke( $_, $assoc_args ) { } // Get the path to the router file - $command_root = WP_CLI\Utils\phar_safe_path( dirname( __DIR__ ) ); + $command_root = Utils\phar_safe_path( dirname( __DIR__ ) ); $router_path = $command_root . '/router.php'; if ( ! file_exists( $router_path ) ) { WP_CLI::error( "Couldn't find router.php" ); From 76680aafc8d18e1ed4b987995cb90adfcd9fa4bc Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 21 Apr 2019 06:43:44 +0200 Subject: [PATCH 11/21] Update src/Server_Command.php Co-Authored-By: wojsmol --- src/Server_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server_Command.php b/src/Server_Command.php index 0b752fd..a0f7d07 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -84,7 +84,7 @@ function __invoke( $_, $assoc_args ) { if ( ! file_exists( $router_path ) ) { WP_CLI::error( "Couldn't find router.php" ); } - $cmd = \WP_CLI\Utils\esc_cmd( + $cmd = Utils\esc_cmd( '%s -S %s -t %s -c %s %s', WP_CLI::get_php_binary(), $assoc_args['host'] . ':' . $assoc_args['port'], From 078f865d609472744e3e6370c94a399c870bff2f Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 21 Apr 2019 06:43:53 +0200 Subject: [PATCH 12/21] Update src/Server_Command.php Co-Authored-By: wojsmol --- src/Server_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server_Command.php b/src/Server_Command.php index a0f7d07..445f0cd 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -97,7 +97,7 @@ function __invoke( $_, $assoc_args ) { // https://bugs.php.net/bug.php?id=60181 $options = array(); - if ( \WP_CLI\Utils\is_windows() ) { + if ( Utils\is_windows() ) { $options['bypass_shell'] = true; } From 68d4d347f1247be5edc3ce3df23ec3c4145345b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Smoli=C5=84ski?= Date: Sun, 21 Apr 2019 06:49:48 +0200 Subject: [PATCH 13/21] use WP_CLI\Utils --- src/Server_Command.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Server_Command.php b/src/Server_Command.php index 445f0cd..f2be536 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -1,4 +1,5 @@ Date: Sun, 21 Apr 2019 06:53:18 +0200 Subject: [PATCH 14/21] Update router.php Co-Authored-By: wojsmol --- router.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/router.php b/router.php index 874d8b4..b937836 100644 --- a/router.php +++ b/router.php @@ -51,7 +51,10 @@ function _wp_filter_build_unique_id( $tag, $function, $priority ) { if ( false === $priority ) { return false; } - $obj_idx .= isset( $wp_filter[ $tag ][ $priority ] ) ? count( (array) $wp_filter[ $tag ][ $priority ] ) : $filter_id_count; + $obj_idx .= isset( $wp_filter[ $tag ][ $priority ] ) + ? count( (array) $wp_filter[ $tag ][ $priority ] ) + : $filter_id_count; + $function[0]->wp_filter_id = $filter_id_count; ++$filter_id_count; } else { From ba4e5b2a539a3ac82960522eb1c424d9f22ae437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Smoli=C5=84ski?= Date: Sun, 21 Apr 2019 06:56:45 +0200 Subject: [PATCH 15/21] add ; --- src/Server_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server_Command.php b/src/Server_Command.php index f2be536..43e975b 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -1,5 +1,5 @@ Date: Sun, 21 Apr 2019 10:45:28 +0200 Subject: [PATCH 16/21] add phpcs:ignore --- router.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/router.php b/router.php index b937836..028306b 100644 --- a/router.php +++ b/router.php @@ -13,6 +13,7 @@ function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 $idx = _wp_filter_build_unique_id( $tag, $function_to_add, $priority ); + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $wp_filter[ $tag ][ $priority ][ $idx ] = array( 'function' => $function_to_add, 'accepted_args' => $accepted_args, @@ -70,6 +71,7 @@ function _wp_filter_build_unique_id( $tag, $function, $priority ) { } function _get_full_host( $url ) { + // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url $parsed_url = parse_url( $url ); $host = $parsed_url['host']; @@ -112,7 +114,8 @@ function ( $url ) { $_SERVER['SERVER_ADDR'] = gethostbyname( $_SERVER['SERVER_NAME'] ); $wpcli_server_root = $_SERVER['DOCUMENT_ROOT']; -$path = '/' . ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ) )['path'], '/' ); +// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url +$path = '/' . ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ) )['path'], '/' ); if ( file_exists( $wpcli_server_root . $path ) ) { if ( is_dir( $wpcli_server_root . $path ) && substr( $path, -1 ) !== '/' ) { From ab3f72cd282efc7a263dbd8622f1a542b708594e Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 21 Apr 2019 10:48:53 +0200 Subject: [PATCH 17/21] Update src/Server_Command.php Co-Authored-By: wojsmol --- src/Server_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server_Command.php b/src/Server_Command.php index 43e975b..932e097 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -58,7 +58,7 @@ class Server_Command extends WP_CLI_Command { * * @when before_wp_load */ - function __invoke( $_, $assoc_args ) { + public function __invoke( $_, $assoc_args ) { $defaults = array( 'host' => 'localhost', 'port' => 8080, From 8d20c7f11f23bf7a4dfc7a24c3fe0651d0aa081c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Smoli=C5=84ski?= Date: Sun, 21 Apr 2019 10:53:54 +0200 Subject: [PATCH 18/21] simplify --- src/Server_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server_Command.php b/src/Server_Command.php index 932e097..b95c9eb 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -91,7 +91,7 @@ public function __invoke( $_, $assoc_args ) { $assoc_args['host'] . ':' . $assoc_args['port'], $docroot, $assoc_args['config'], - \WP_CLI\Utils\extract_from_phar( $router_path ) + Utils\extract_from_phar( $router_path ) ); $descriptors = array( STDIN, STDOUT, STDERR ); From 196f29b81c6dca8b8289c035e9810d82e7897791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Smoli=C5=84ski?= Date: Sun, 21 Apr 2019 11:05:32 +0200 Subject: [PATCH 19/21] rename $path --- router.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/router.php b/router.php index 028306b..fc5aba5 100644 --- a/router.php +++ b/router.php @@ -115,17 +115,17 @@ function ( $url ) { $_SERVER['SERVER_ADDR'] = gethostbyname( $_SERVER['SERVER_NAME'] ); $wpcli_server_root = $_SERVER['DOCUMENT_ROOT']; // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -$path = '/' . ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ) )['path'], '/' ); +$wpcli_server_path = '/' . ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ) )['path'], '/' ); -if ( file_exists( $wpcli_server_root . $path ) ) { - if ( is_dir( $wpcli_server_root . $path ) && substr( $path, -1 ) !== '/' ) { - header( "Location: $path/" ); +if ( file_exists( $wpcli_server_root . $wpcli_server_path ) ) { + if ( is_dir( $wpcli_server_root . $wpcli_server_path ) && substr( $wpcli_server_path, -1 ) !== '/' ) { + header( "Location: $wpcli_server_path/" ); exit; } - if ( strpos( $path, '.php' ) !== false ) { - chdir( dirname( $wpcli_server_root . $path ) ); - require_once $wpcli_server_root . $path; + if ( strpos( $wpcli_server_path, '.php' ) !== false ) { + chdir( dirname( $wpcli_server_root . $wpcli_server_path ) ); + require_once $wpcli_server_root . $wpcli_server_path; } else { return false; } From 0d453d36cdca148873f38ff5ec36a700759b84c4 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 21 Apr 2019 11:35:01 +0200 Subject: [PATCH 20/21] Update router.php Co-Authored-By: wojsmol --- router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router.php b/router.php index fc5aba5..86b2f3a 100644 --- a/router.php +++ b/router.php @@ -71,7 +71,7 @@ function _wp_filter_build_unique_id( $tag, $function, $priority ) { } function _get_full_host( $url ) { - // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url + // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url $parsed_url = parse_url( $url ); $host = $parsed_url['host']; From 890fc9ea356e8b339798511cb46f906fc8bc8fee Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 21 Apr 2019 11:35:20 +0200 Subject: [PATCH 21/21] Update src/Server_Command.php Co-Authored-By: wojsmol --- src/Server_Command.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Server_Command.php b/src/Server_Command.php index b95c9eb..ce1be23 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -1,4 +1,5 @@