From 5df32e0d2d4b3c88daa88b358c0e4c0328238f16 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Wed, 28 Aug 2019 16:55:51 +0200 Subject: [PATCH] EZP-30898: Dropped dependency on Installers to get InstallType --- composer.json | 1 + src/lib/Core/Environment/Environment.php | 29 +++++++++--------------- src/lib/Core/Environment/InstallType.php | 7 ++++++ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 3984c484..518aff4f 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "prefer-stable": true, "require": { "php": "^7.3", + "ext-json": "*", "ezsystems/ezpublish-kernel": "^8.0@dev", "fzaninotto/faker": "^1.8", "behat/behat": "^3.5", diff --git a/src/lib/Core/Environment/Environment.php b/src/lib/Core/Environment/Environment.php index 49d6125d..46a4dc2d 100644 --- a/src/lib/Core/Environment/Environment.php +++ b/src/lib/Core/Environment/Environment.php @@ -6,7 +6,7 @@ */ namespace EzSystems\Behat\Core\Environment; -use EzSystems\PlatformInstallerBundle\Installer\Installer; +use RuntimeException; use Symfony\Component\DependencyInjection\ContainerInterface; class Environment @@ -14,12 +14,6 @@ class Environment /** @var \Symfony\Component\DependencyInjection\ContainerInterface Symfony DI service container */ private $serviceContainer; - /** @var array Names of available installer services in Studio */ - private $installerServices = ['platform' => 'ezplatform.installer.clean_installer', - 'platform-demo' => 'app.installer.demo_installer', - 'platform-ee' => 'ezstudio.installer.studio_installer', - 'platform-ee-demo' => 'App\Installer\PlatformEEDemoInstaller', ]; - /** * Environment constructor. * @@ -32,20 +26,19 @@ public function __construct(ContainerInterface $serviceContainer) public function getInstallType(): int { - if ($this->serviceContainer->has($this->installerServices['platform-ee-demo'])) { - return InstallType::ENTERPRISE_DEMO; - } - - if ($this->serviceContainer->has($this->installerServices['platform-ee'])) { - return InstallType::ENTERPRISE; + $projectDir = $this->serviceContainer->getParameter('kernel.project_dir'); + $composerJsonPath = realpath($projectDir . '/composer.json'); + if (false === $composerJsonPath) { + throw new RuntimeException( + "Unable to find composer.json in {$projectDir} to determine meta repository and installation type" + ); } - if ($this->serviceContainer->has($this->installerServices['platform-demo'])) { - return InstallType::PLATFORM_DEMO; + $composerConfig = json_decode(file_get_contents($composerJsonPath)); + if (!isset(InstallType::PACKAGE_NAME_MAP[$composerConfig->name])) { + throw new RuntimeException("Unknown installation type for the package: {$composerConfig->name}"); } - if ($this->serviceContainer->has($this->installerServices['platform'])) { - return InstallType::PLATFORM; - } + return InstallType::PACKAGE_NAME_MAP[$composerConfig->name]; } } diff --git a/src/lib/Core/Environment/InstallType.php b/src/lib/Core/Environment/InstallType.php index 1ceee022..ce12558f 100644 --- a/src/lib/Core/Environment/InstallType.php +++ b/src/lib/Core/Environment/InstallType.php @@ -12,4 +12,11 @@ abstract class InstallType public const PLATFORM_DEMO = 2; public const ENTERPRISE = 3; public const ENTERPRISE_DEMO = 4; + + public const PACKAGE_NAME_MAP = [ + 'ezsystems/ezplatform' => InstallType::PLATFORM, + 'ezsystems/ezplatform-ee' => InstallType::ENTERPRISE, + 'ezsystems/ezplatform-demo' => InstallType::PLATFORM_DEMO, + 'ezsystems/ezplatform-ee-demo' => InstallType::ENTERPRISE_DEMO, + ]; }