Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-30898: Dropped dependency on Installers to get InstallType #100

Merged
merged 1 commit into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 11 additions & 18 deletions src/lib/Core/Environment/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@
*/
namespace EzSystems\Behat\Core\Environment;

use EzSystems\PlatformInstallerBundle\Installer\Installer;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerInterface;

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.
*
Expand All @@ -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];
}
}
7 changes: 7 additions & 0 deletions src/lib/Core/Environment/InstallType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}