diff --git a/src/Configuration/ConsoleConfiguration.php b/src/Configuration/ConsoleConfiguration.php index 5287093..676666d 100644 --- a/src/Configuration/ConsoleConfiguration.php +++ b/src/Configuration/ConsoleConfiguration.php @@ -28,14 +28,12 @@ class ConsoleConfiguration implements ContainerConfigurationInterface */ public function modify(Container $container) { - $container['is_wp_cli'] = defined('WP_CLI') && WP_CLI; $container['commands'] = $container->service(function (Container $container) { return [ new Console\CreateAttachmentMetadataCommand($container['file_manager']), new Console\CreateCroppedImageCommand($container['file_manager'], $container['event_manager']), new Console\CreateSiteIconCommand($container['file_manager'], $container['event_manager'], $container['site_icon']), new Console\EditAttachmentImageCommand($container['file_manager']), - new Console\InstallObjectCacheCommand($container['content_directory'], $container['filesystem'], $container['plugin_dir_path']), new Console\ResizeAttachmentImageCommand($container['file_manager']), new Console\RunAllCronCommand($container['console_client'], $container['site_query']), ]; @@ -43,5 +41,11 @@ public function modify(Container $container) $container['console_client'] = $container->service(function (Container $container) { return new LambdaClient($container['ymir_http_client'], $container['cloud_provider_function_name'], $container['cloud_provider_key'], $container['cloud_provider_region'], $container['cloud_provider_secret'], $container['site_url']); }); + $container['is_wp_cli'] = defined('WP_CLI') && WP_CLI; + $container['local_commands'] = $container->service(function (Container $container) { + return [ + new Console\InstallObjectCacheCommand($container['content_directory'], $container['filesystem'], $container['plugin_dir_path']), + ]; + }); } } diff --git a/src/Plugin.php b/src/Plugin.php index 6890e56..211a958 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -115,6 +115,14 @@ public function load() CloudStorageStreamWrapper::register($this->container['cloud_storage_client']); + foreach ($this->container['local_commands'] as $command) { + $this->registerCommand($command); + } + + if ($this->isLocal()) { + return; + } + foreach ($this->container['priority_subscribers'] as $subscriber) { $this->container['event_manager']->addSubscriber($subscriber); } @@ -130,6 +138,14 @@ public function load() $this->loaded = true; } + /** + * Checks if the code is running locally. + */ + private function isLocal(): bool + { + return empty($this->container['ymir_environment']); + } + /** * Register the given command with WP-CLI. */