From bbfed2f39cae6053e59860f27bef0c8a19e9b110 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 25 Mar 2019 14:53:55 +0100 Subject: [PATCH] Use proper endpoint --- src/Console/AsmpCommand.php | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Console/AsmpCommand.php b/src/Console/AsmpCommand.php index 62fd935..51a311c 100644 --- a/src/Console/AsmpCommand.php +++ b/src/Console/AsmpCommand.php @@ -30,7 +30,12 @@ final class AsmpCommand { * Instantiate a AsmpCommand object. */ public function __construct() { - $this->config = Configuration::getDefaultConfiguration(); + if ( ! $this->is_supported() ) { + return; + } + + $this->config = Configuration::getDefaultConfiguration() + ->setHost( $this->get_endpoint() ); } /** @@ -120,11 +125,7 @@ public function status( array $args = [], array $assoc_args = [] ): void { * @param array $assoc_args Optional. Array of associative arguments. */ public function is_available( array $args = [], array $assoc_args = [] ): void { - if ( false === \getenv( ASMP::VERSION ) ) { - exit( 1 ); - } - - exit( 0 ); + exit( $this->is_supported() ? 0 : 1 ); } /** @@ -136,7 +137,7 @@ public function is_available( array $args = [], array $assoc_args = [] ): void { public function version( array $args = [], array $assoc_args = [] ): void { $this->ensure_asmp_is_available(); - WP_CLI::log( \getenv( ASMP::VERSION ) ); + WP_CLI::log( $this->get_version() ); } /** @@ -148,7 +149,7 @@ public function version( array $args = [], array $assoc_args = [] ): void { public function endpoint( array $args = [], array $assoc_args = [] ): void { $this->ensure_asmp_is_available(); - WP_CLI::log( \getenv( ASMP::ENDPOINT ) ); + WP_CLI::log( $this->get_endpoint() ); } /** @@ -160,6 +161,24 @@ private function is_supported(): bool { return false !== \getenv( ASMP::VERSION ); } + /** + * Get the version of ASMP. + * + * @return string ASMP version. + */ + private function get_version(): string { + return \getenv( ASMP::VERSION ); + } + + /** + * Get the endpoint for ASMP. + * + * @return string ASMP endpoint. + */ + private function get_endpoint(): string { + return \getenv( ASMP::ENDPOINT ); + } + /** * Ensure that ASMP is available. *