diff --git a/src/src/Auth.php b/src/src/Auth.php index 9479ee05..14a7c32e 100644 --- a/src/src/Auth.php +++ b/src/src/Auth.php @@ -3,11 +3,11 @@ namespace QIT_CLI; class Auth { - /** @var ManagerBackend $manager_backend */ - protected $manager_backend; + /** @var Cache $cache */ + protected $cache; - public function __construct( ManagerBackend $manager_backend ) { - $this->manager_backend = $manager_backend; + public function __construct( Cache $cache ) { + $this->cache = $cache; } /** @@ -15,12 +15,12 @@ public function __construct( ManagerBackend $manager_backend ) { */ public function get_partner_auth() { // Migrate "application_password" to "qit_token" if it exists. - if ( empty( $this->manager_backend->get_cache()->get( 'qit_token' ) ) && ! empty( $this->manager_backend->get_cache()->get( 'application_password' ) ) ) { - $this->manager_backend->get_cache()->set( 'qit_token', $this->manager_backend->get_cache()->get( 'application_password' ), - 1 ); + if ( empty( $this->cache->get( 'qit_token' ) ) && ! empty( $this->cache->get( 'application_password' ) ) ) { + $this->cache->set( 'qit_token', $this->cache->get( 'application_password' ), - 1 ); } - $user = $this->manager_backend->get_cache()->get( 'user' ); - $qit_token = $this->manager_backend->get_cache()->get( 'qit_token' ); + $user = $this->cache->get( 'user' ); + $qit_token = $this->cache->get( 'qit_token' ); if ( ! empty( $user ) && ! empty( $qit_token ) ) { return base64_encode( sprintf( '%s:%s', $user, $qit_token ) ); @@ -33,7 +33,7 @@ public function get_partner_auth() { * @return string|null MANAGER_SECRET, or null if not defined. */ public function get_manager_secret() { - return $this->manager_backend->get_cache()->get( 'manager_secret' ); + return $this->cache->get( 'manager_secret' ); } /** @@ -43,8 +43,8 @@ public function get_manager_secret() { * @return void */ public function set_partner_auth( $user, $qit_token ): void { - $this->manager_backend->get_cache()->set( 'user', $user, - 1 ); - $this->manager_backend->get_cache()->set( 'qit_token', $qit_token, - 1 ); + $this->cache->set( 'user', $user, - 1 ); + $this->cache->set( 'qit_token', $qit_token, - 1 ); } /** @@ -53,10 +53,10 @@ public function set_partner_auth( $user, $qit_token ): void { * @return void */ public function set_manager_secret( $manager_secret ): void { - $this->manager_backend->get_cache()->set( 'manager_secret', $manager_secret, - 1 ); + $this->cache->set( 'manager_secret', $manager_secret, - 1 ); } public function delete_manager_secret(): void { - $this->manager_backend->get_cache()->delete( 'manager_secret' ); + $this->cache->delete( 'manager_secret' ); } } diff --git a/src/src/Cache.php b/src/src/Cache.php index 249c9581..cf02a42a 100644 --- a/src/src/Cache.php +++ b/src/src/Cache.php @@ -8,17 +8,10 @@ class Cache { /** @var array> $cache */ protected $cache = []; - /** @var ManagerBackend $manager_backend */ - protected $manager_backend; - - /** @var bool */ - protected $did_init = false; - /** @var string */ protected $cache_file_path; public function __construct() { - $this->cache_file_path = $this->make_cache_path_for_manager_environment( Config::get_current_manager_backend() ); $this->init_cache(); } @@ -26,7 +19,7 @@ public function get_cache_file_path(): string { return $this->cache_file_path; } - public function make_cache_path_for_manager_environment( string $manager_backend ): string { + public function make_cache_path( string $manager_backend ): string { return Config::get_qit_dir() . ".env-$manager_backend.json"; } @@ -38,10 +31,6 @@ public function make_cache_path_for_manager_environment( string $manager_backend * @return void */ public function set( string $key, $value, int $expire ): void { - if ( ! $this->did_init ) { - throw new \LogicException( 'Cache not initialized.' ); - } - if ( $expire !== - 1 ) { $expire = time() + $expire; } @@ -107,8 +96,8 @@ public function delete( string $key ) { * * @throws \RuntimeException When could not read the cache file. */ - protected function init_cache(): void { - $this->did_init = true; + public function init_cache(): void { + $this->cache_file_path = static::make_cache_path( Config::get_current_manager_backend() ); if ( ! file_exists( $this->cache_file_path ) ) { return; @@ -123,7 +112,7 @@ protected function init_cache(): void { $cache = json_decode( $data, true ); if ( ! is_array( $cache ) ) { - throw new \RuntimeException( 'Could not parse cache file. Resetting environment, please remove the current Partner/ManagerBackend and add it again.' ); + throw new \RuntimeException( 'Could not parse cache file. Resetting environment, please remove the current Partner/Manager backend and add it again.' ); } $this->cache = $cache; diff --git a/src/src/Commands/Backend/AddBackend.php b/src/src/Commands/Backend/AddBackend.php index 7ac45a13..690193bd 100644 --- a/src/src/Commands/Backend/AddBackend.php +++ b/src/src/Commands/Backend/AddBackend.php @@ -3,6 +3,7 @@ namespace QIT_CLI\Commands\Backend; use QIT_CLI\Auth; +use QIT_CLI\Cache; use QIT_CLI\ManagerBackend; use QIT_CLI\WooExtensionsList; use Symfony\Component\Console\Command\Command; @@ -25,10 +26,14 @@ class AddBackend extends Command { /** @var ManagerBackend $manager_backend */ protected $manager_backend; - public function __construct( ManagerBackend $manager_backend, Auth $auth, WooExtensionsList $woo_extensions_list ) { + /** @var Cache $cache */ + protected $cache; + + public function __construct( ManagerBackend $manager_backend, Cache $cache, Auth $auth, WooExtensionsList $woo_extensions_list ) { $this->manager_backend = $manager_backend; $this->auth = $auth; $this->woo_extensions_list = $woo_extensions_list; + $this->cache = $cache; parent::__construct(); } @@ -114,7 +119,7 @@ protected function execute( InputInterface $input, OutputInterface $output ): in } $this->auth->set_manager_secret( $qit_secret ); - $this->manager_backend->get_cache()->set( 'manager_url', $manager_url, - 1 ); + $this->cache->set( 'manager_url', $manager_url, - 1 ); $output->writeln( "Validating your Manager Secret against $manager_url..." ); try { @@ -124,7 +129,7 @@ protected function execute( InputInterface $input, OutputInterface $output ): in } } catch ( \Exception $e ) { $this->auth->delete_manager_secret(); - $this->manager_backend->get_cache()->delete( 'manager_url' ); + $this->cache->delete( 'manager_url' ); $output->writeln( sprintf( 'We could not authenticate to %s using the provided Manager Secret.', escapeshellarg( $manager_url ) ) ); return Command::FAILURE; diff --git a/src/src/Commands/CreateMassTestCommands.php b/src/src/Commands/CreateMassTestCommands.php index df63fa6f..17700154 100644 --- a/src/src/Commands/CreateMassTestCommands.php +++ b/src/src/Commands/CreateMassTestCommands.php @@ -4,7 +4,7 @@ use QIT_CLI\App; use QIT_CLI\Auth; -use QIT_CLI\ManagerBackend; +use QIT_CLI\Cache; use QIT_CLI\IO\Output; use QIT_CLI\RequestBuilder; use Symfony\Component\Console\Application; @@ -15,8 +15,8 @@ class CreateMassTestCommands extends DynamicCommandCreator { - /** @var ManagerBackend $manager_backend */ - protected $manager_backend; + /** @var Cache $cache */ + protected $cache; /** @var Auth $auth */ protected $auth; @@ -24,10 +24,10 @@ class CreateMassTestCommands extends DynamicCommandCreator { /** @var OutputInterface $output */ protected $output; - public function __construct( ManagerBackend $manager_backend, Auth $auth ) { - $this->manager_backend = $manager_backend; - $this->auth = $auth; - $this->output = App::make( Output::class ); + public function __construct( Cache $cache, Auth $auth ) { + $this->cache = $cache; + $this->auth = $auth; + $this->output = App::make( Output::class ); } public function register_commands( Application $application ): void { @@ -58,7 +58,7 @@ public function execute( InputInterface $input, OutputInterface $output ) { ->setName( 'mass-test' ); try { - $schema = $this->manager_backend->get_cache()->get_manager_sync_data( 'schemas' )['mass'] ?? null; + $schema = $this->cache->get_manager_sync_data( 'schemas' )['mass'] ?? null; if ( ! is_array( $schema ) ) { throw new \Exception(); diff --git a/src/src/Commands/CreateRunCommands.php b/src/src/Commands/CreateRunCommands.php index bccd2973..d57896de 100644 --- a/src/src/Commands/CreateRunCommands.php +++ b/src/src/Commands/CreateRunCommands.php @@ -4,7 +4,7 @@ use QIT_CLI\App; use QIT_CLI\Auth; -use QIT_CLI\ManagerBackend; +use QIT_CLI\Cache; use QIT_CLI\IO\Output; use QIT_CLI\RequestBuilder; use QIT_CLI\Upload; @@ -20,8 +20,8 @@ use function QIT_CLI\get_manager_url; class CreateRunCommands extends DynamicCommandCreator { - /** @var ManagerBackend $manager_backend */ - protected $manager_backend; + /** @var Cache $cache */ + protected $cache; /** @var Auth $auth */ protected $auth; @@ -35,8 +35,8 @@ class CreateRunCommands extends DynamicCommandCreator { /** @var WooExtensionsList $woo_extensions_list */ protected $woo_extensions_list; - public function __construct( ManagerBackend $manager_backend, Auth $auth, Upload $upload, WooExtensionsList $woo_extensions_list ) { - $this->manager_backend = $manager_backend; + public function __construct( Cache $cache, Auth $auth, Upload $upload, WooExtensionsList $woo_extensions_list ) { + $this->cache = $cache; $this->auth = $auth; $this->output = App::make( Output::class ); $this->upload = $upload; @@ -44,8 +44,8 @@ public function __construct( ManagerBackend $manager_backend, Auth $auth, Upload } public function register_commands( Application $application ): void { - foreach ( $this->manager_backend->get_cache()->get_manager_sync_data( 'test_types' ) as $test_type ) { - $this->register_command_by_schema( $application, $test_type, $this->manager_backend->get_cache()->get_manager_sync_data( 'schemas' )[ $test_type ] ); + foreach ( $this->cache->get_manager_sync_data( 'test_types' ) as $test_type ) { + $this->register_command_by_schema( $application, $test_type, $this->cache->get_manager_sync_data( 'schemas' )[ $test_type ] ); } } @@ -313,7 +313,7 @@ public function execute( InputInterface $input, OutputInterface $output ) { // This will be hidden while custom test type is in development, but kept as an alias to "woo-e2e". if ( $test_type === 'e2e' ) { try { - $hide_e2e = $this->manager_backend->get_cache()->get_manager_sync_data( 'hide_e2e' ); + $hide_e2e = $this->cache->get_manager_sync_data( 'hide_e2e' ); } catch ( \Exception $e ) { // If it throws it's because it's not set, so we hide it. $hide_e2e = true; diff --git a/src/src/Commands/DevModeCommand.php b/src/src/Commands/DevModeCommand.php index 486bdd57..19bfc4d2 100644 --- a/src/src/Commands/DevModeCommand.php +++ b/src/src/Commands/DevModeCommand.php @@ -3,7 +3,6 @@ namespace QIT_CLI\Commands; use QIT_CLI\Config; -use QIT_CLI\ManagerBackend; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -11,14 +10,6 @@ class DevModeCommand extends Command { protected static $defaultName = 'dev'; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase - /** @var ManagerBackend $manager_backend */ - protected $manager_backend; - - public function __construct( ManagerBackend $manager_backend ) { - $this->manager_backend = $manager_backend; - parent::__construct(); - } - protected function configure() { $this ->setDescription( 'Enabled QIT CLI development mode.' ) diff --git a/src/src/Commands/ListCommand.php b/src/src/Commands/ListCommand.php index 0541bfd6..f1c118ed 100644 --- a/src/src/Commands/ListCommand.php +++ b/src/src/Commands/ListCommand.php @@ -3,7 +3,7 @@ namespace QIT_CLI\Commands; use QIT_CLI\Auth; -use QIT_CLI\ManagerBackend; +use QIT_CLI\Cache; use QIT_CLI\RequestBuilder; use QIT_CLI\WooExtensionsList; use Symfony\Component\Console\Command\Command; @@ -16,8 +16,8 @@ class ListCommand extends Command { protected static $defaultName = 'list-tests'; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase - /** @var ManagerBackend $manager_backend */ - protected $manager_backend; + /** @var Cache $cache */ + protected $cache; /** @var Auth $auth */ protected $auth; @@ -25,15 +25,15 @@ class ListCommand extends Command { /** @var WooExtensionsList $woo_extensions_list */ protected $woo_extensions_list; - public function __construct( ManagerBackend $manager_backend, Auth $auth, WooExtensionsList $woo_extensions_list ) { - $this->manager_backend = $manager_backend; + public function __construct( Cache $cache, Auth $auth, WooExtensionsList $woo_extensions_list ) { + $this->cache = $cache; $this->auth = $auth; $this->woo_extensions_list = $woo_extensions_list; parent::__construct(); } protected function configure() { - $test_types_list = implode( ', ', $this->manager_backend->get_cache()->get_manager_sync_data( 'test_types' ) ); + $test_types_list = implode( ', ', $this->cache->get_manager_sync_data( 'test_types' ) ); $this ->setDescription( 'List test runs.' ) ->addOption( 'extensions', 'e', InputOption::VALUE_OPTIONAL, '(Optional) Retrieve results for these extensions (Accepts slugs or IDs, comma-separated).' ) diff --git a/src/src/Commands/Partner/AddPartner.php b/src/src/Commands/Partner/AddPartner.php index 43bf28e6..9245a7da 100644 --- a/src/src/Commands/Partner/AddPartner.php +++ b/src/src/Commands/Partner/AddPartner.php @@ -3,6 +3,7 @@ namespace QIT_CLI\Commands\Partner; use QIT_CLI\Auth; +use QIT_CLI\Cache; use QIT_CLI\ManagerBackend; use QIT_CLI\WooExtensionsList; use Symfony\Component\Console\Command\Command; @@ -27,10 +28,14 @@ class AddPartner extends Command { /** @var ManagerBackend $manager_backend */ protected $manager_backend; - public function __construct( ManagerBackend $manager_backend, Auth $auth, WooExtensionsList $woo_extensions_list ) { + /** @var Cache $cache */ + protected $cache; + + public function __construct( ManagerBackend $manager_backend, Cache $cache, Auth $auth, WooExtensionsList $woo_extensions_list ) { $this->manager_backend = $manager_backend; $this->auth = $auth; $this->woo_extensions_list = $woo_extensions_list; + $this->cache = $cache; parent::__construct(); } @@ -142,10 +147,10 @@ protected function execute( InputInterface $input, OutputInterface $output ): in $this->manager_backend->add_partner( $user_environment ); $this->auth->set_partner_auth( $user, $qit_token ); - $this->manager_backend->get_cache()->set( 'manager_url', $manager_url, - 1 ); + $this->cache->set( 'manager_url', $manager_url, - 1 ); $this->woo_extensions_list->fetch_woo_extensions_available(); - $output->writeln( sprintf( "Cache file written to: %s. Keep this file safe, as it contains your QIT Token.\n", $this->manager_backend->get_cache()->get_cache_file_path() ) ); + $output->writeln( sprintf( "Cache file written to: %s. Keep this file safe, as it contains your QIT Token.\n", $this->cache->get_cache_file_path() ) ); $output->writeln( "Treat this file as you would treat your SSH keys. For more tips on hardening security, check the README of the QIT CLI.\n" ); $output->writeln( 'Initialization complete! You can now start using the QIT CLI!' ); diff --git a/src/src/Commands/SetProxyCommand.php b/src/src/Commands/SetProxyCommand.php index 7d8092fe..13e19cbd 100644 --- a/src/src/Commands/SetProxyCommand.php +++ b/src/src/Commands/SetProxyCommand.php @@ -3,7 +3,6 @@ namespace QIT_CLI\Commands; use QIT_CLI\Config; -use QIT_CLI\ManagerBackend; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -14,14 +13,6 @@ class SetProxyCommand extends Command { protected static $defaultName = 'proxy'; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase - /** @var ManagerBackend $manager_backend */ - protected $manager_backend; - - public function __construct( ManagerBackend $manager_backend ) { - $this->manager_backend = $manager_backend; - parent::__construct(); - } - protected function configure() { $this ->setDescription( 'Change the default URL that we use to connect to Automattic proxy locally.' ) diff --git a/src/src/Config.php b/src/src/Config.php index f99f17f0..80c5046e 100644 --- a/src/src/Config.php +++ b/src/src/Config.php @@ -47,6 +47,9 @@ public static function is_development_mode(): bool { public static function set_current_manager_environment( string $manager_backend ): void { App::make( self::class )->set( 'current_environment', $manager_backend ); + + // Update the existing Cache singleton with the new environment. + App::make( Cache::class )->init_cache(); } public static function get_current_manager_backend(): string { diff --git a/src/src/ManagerBackend.php b/src/src/ManagerBackend.php index d9136cb4..8269963c 100644 --- a/src/src/ManagerBackend.php +++ b/src/src/ManagerBackend.php @@ -23,7 +23,7 @@ public function __construct( Cache $cache ) { $this->cache = $cache; } - public function is_allowed_manager_backend( string $manager_backend ): bool { + protected function is_allowed_manager_backend( string $manager_backend ): bool { // Partner environment. if ( substr( $manager_backend, 0, 8 ) === 'partner-' ) { $parts = explode( '-', $manager_backend ); @@ -57,7 +57,7 @@ public function add_manager_backend( string $manager_backend, bool $switch_now = throw new \InvalidArgumentException( 'Invalid Manager backend.' ); } - $new_manager_backend_file = $this->cache->make_cache_path_for_manager_environment( $manager_backend ); + $new_manager_backend_file = $this->cache->make_cache_path( $manager_backend ); if ( file_exists( $new_manager_backend_file ) ) { $unlinked = unlink( $new_manager_backend_file ); @@ -107,12 +107,11 @@ public function switch_to_manager_backend( string $manager_backend ): void { throw new \InvalidArgumentException( 'Invalid backend.' ); } - if ( ! file_exists( $this->cache->make_cache_path_for_manager_environment( $manager_backend ) ) ) { + if ( ! file_exists( $this->cache->make_cache_path( $manager_backend ) ) ) { throw new \RuntimeException( "Cannot switch to backend '$manager_backend', as it has not been configured yet." ); } Config::set_current_manager_environment( $manager_backend ); - $this->cache = App::make( Cache::class ); } public function add_partner( string $partner, bool $switch_now = true ): void { @@ -131,7 +130,7 @@ public function partner_exists( string $partner ): bool { return $this->manager_backend_exists( $this->get_partner_filename( $partner ) ); } - public function get_partner_filename( string $partner ): string { + protected function get_partner_filename( string $partner ): string { $current_backend = Config::get_current_manager_backend(); /* @@ -155,11 +154,7 @@ public function manager_backend_exists( string $manager_backend ): bool { throw new \InvalidArgumentException( "The environment $manager_backend is not allowed." ); } - return file_exists( $this->cache->make_cache_path_for_manager_environment( $manager_backend ) ); - } - - public function get_cache(): Cache { - return $this->cache; + return file_exists( $this->cache->make_cache_path( $manager_backend ) ); } /** @@ -241,7 +236,7 @@ public function remove_manager_backend( string $manager_backend ): void { throw new \RuntimeException( "Manager environment '$manager_backend' does not exist/is not configured yet." ); } - $unlinked = unlink( $this->cache->make_cache_path_for_manager_environment( $manager_backend ) ); + $unlinked = unlink( $this->cache->make_cache_path( $manager_backend ) ); if ( ! $unlinked ) { throw new \RuntimeException( sprintf( 'Could not remove Manager environment "%s". Please delete the cache file manually: %s', $manager_backend, $this->cache->get_cache_file_path() ) ); diff --git a/src/src/ManagerSync.php b/src/src/ManagerSync.php index 82dc2336..dd0b0cbe 100644 --- a/src/src/ManagerSync.php +++ b/src/src/ManagerSync.php @@ -12,8 +12,8 @@ class ManagerSync { /** @var Auth $auth */ protected $auth; - /** @var ManagerBackend $manager_backend */ - protected $manager_backend; + /** @var Cache $cache */ + protected $cache; /** @var OutputInterface $output */ protected $output; @@ -21,19 +21,19 @@ class ManagerSync { /** @var string $sync_cache_key */ public $sync_cache_key; - public function __construct( ManagerBackend $manager_backend, Auth $auth ) { - $this->auth = $auth; - $this->manager_backend = $manager_backend; - $this->output = App::make( Output::class ); - $this->sync_cache_key = sprintf( 'manager_sync_v%s', App::getVar( 'CLI_VERSION' ) ); + public function __construct( Cache $cache, Auth $auth ) { + $this->auth = $auth; + $this->cache = $cache; + $this->output = App::make( Output::class ); + $this->sync_cache_key = sprintf( 'manager_sync_v%s', App::getVar( 'CLI_VERSION' ) ); } public function maybe_sync( bool $force_resync = false ): void { if ( $force_resync ) { - $this->manager_backend->get_cache()->delete( $this->sync_cache_key ); + $this->cache->delete( $this->sync_cache_key ); } - $manager_sync = $this->manager_backend->get_cache()->get( $this->sync_cache_key ); + $manager_sync = $this->cache->get( $this->sync_cache_key ); if ( ! is_null( $manager_sync ) ) { return; @@ -81,7 +81,7 @@ public function maybe_sync( bool $force_resync = false ): void { // 1 hour if we can connect to the Manager. $expiration = App::getVar( 'offline_mode' ) ? 0 : 3600; - $this->manager_backend->get_cache()->set( $this->sync_cache_key, $manager_sync, $expiration ); + $this->cache->set( $this->sync_cache_key, $manager_sync, $expiration ); } public function enforce_latest_version(): void { @@ -92,8 +92,8 @@ public function enforce_latest_version(): void { return; } - $latest_version = $this->manager_backend->get_cache()->get_manager_sync_data( 'latest_cli_version' ); - $minimum_cli_version = $this->manager_backend->get_cache()->get_manager_sync_data( 'minimum_cli_version' ); + $latest_version = $this->cache->get_manager_sync_data( 'latest_cli_version' ); + $minimum_cli_version = $this->cache->get_manager_sync_data( 'minimum_cli_version' ); if ( version_compare( $current_version, $latest_version, '<' ) ) { $header = 'There\'s a new version of the QIT CLI available!'; diff --git a/src/src/WooExtensionsList.php b/src/src/WooExtensionsList.php index 7c5b2f3d..7fb65be7 100644 --- a/src/src/WooExtensionsList.php +++ b/src/src/WooExtensionsList.php @@ -3,8 +3,8 @@ namespace QIT_CLI; class WooExtensionsList { - /** @var ManagerBackend $manager_backend */ - protected $manager_backend; + /** @var Cache $cache */ + protected $cache; /** @var string $woo_extensions_cache_key */ protected $woo_extensions_cache_key; @@ -12,8 +12,8 @@ class WooExtensionsList { /** @var ManagerSync $manager_sync */ protected $manager_sync; - public function __construct( ManagerBackend $manager_backend, ManagerSync $manager_sync ) { - $this->manager_backend = $manager_backend; + public function __construct( Cache $cache, ManagerSync $manager_sync ) { + $this->cache = $cache; $this->manager_sync = $manager_sync; $this->woo_extensions_cache_key = sprintf( 'woo_extensions_%s', md5( get_manager_url() ) ); } @@ -32,7 +32,7 @@ public function fetch_woo_extensions_available(): void { */ public function get_woo_extension_list(): array { try { - return $this->manager_backend->get_cache()->get_manager_sync_data( 'extensions' ); + return $this->cache->get_manager_sync_data( 'extensions' ); } catch ( \Exception $e ) { return []; } diff --git a/src/src/bootstrap.php b/src/src/bootstrap.php index 7fcf246f..db71a245 100644 --- a/src/src/bootstrap.php +++ b/src/src/bootstrap.php @@ -1,6 +1,7 @@ singleton( ManagerSync::class ); $container->singleton( Config::class ); $container->singleton( ManagerBackend::class ); +$container->singleton( Cache::class ); $application->configureIO( $container->make( Input::class ), $container->make( Output::class ) ); @@ -214,7 +216,7 @@ public function filter( $in, $out, &$consumed, $closing ): int { } if ( $container->make( Output::class )->isVerbose() ) { - $container->make( Output::class )->writeln( sprintf( 'QIT ManagerBackend: %s', Config::get_current_manager_backend() ) ); + $container->make( Output::class )->writeln( sprintf( 'QIT Manager Backend: %s', Config::get_current_manager_backend() ) ); } return $application; diff --git a/src/src/helpers.php b/src/src/helpers.php index 982062c7..c422ec77 100644 --- a/src/src/helpers.php +++ b/src/src/helpers.php @@ -75,14 +75,14 @@ function open_in_browser( string $url ): void { * @return string The URL of the WCCOM Marketplace to use. */ function get_wccom_url(): string { - return App::make( ManagerBackend::class )->get_cache()->get_manager_sync_data( 'wccom_url' ); + return App::make( Cache::class )->get_manager_sync_data( 'wccom_url' ); } /** * @return string The URL to the CD Manager instance to use. */ function get_manager_url(): string { - $override = App::make( ManagerBackend::class )->get_cache()->get( 'manager_url' ); + $override = App::make( Cache::class )->get( 'manager_url' ); if ( ! is_null( $override ) ) { // If it's not staging. @@ -90,7 +90,7 @@ function get_manager_url(): string { // And it's contains the old domain. if ( strpos( $override, 'compatibilitydashboard.wpcomstaging' ) !== false ) { // Update it to the new domain. - App::make( ManagerBackend::class )->get_cache()->set( 'manager_url', 'https://qit.woo.com', - 1 ); + App::make( Cache::class )->set( 'manager_url', 'https://qit.woo.com', - 1 ); return 'https://qit.woo.com'; } diff --git a/src/tests/PartnerManagementTest.php b/src/tests/PartnerManagementTest.php index 593ac7ea..c89b256e 100644 --- a/src/tests/PartnerManagementTest.php +++ b/src/tests/PartnerManagementTest.php @@ -3,6 +3,7 @@ namespace QIT_CLI_Tests; use QIT_CLI\App; +use QIT_CLI\Cache; use QIT_CLI\Commands\Backend\AddBackend; use QIT_CLI\Commands\Backend\SwitchBackend; use QIT_CLI\Commands\Partner\AddPartner; @@ -39,7 +40,7 @@ protected function add_partner( string $user, string $app_pass, array $extension } protected function get_snapshot_friendly_cache(): string { - $json = file_get_contents( App::make( ManagerBackend::class )->get_cache()->get_cache_file_path() ); + $json = file_get_contents( App::make( Cache::class )->get_cache_file_path() ); /* * To ensure consistent snapshot testing results, replace the time-dependent "expire" property in the JSON