Skip to content

Commit

Permalink
Merge branch 'b-6.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
MantasVaitkunas committed Dec 18, 2018
2 parents c2cfea1 + ca87642 commit 4b95f24
Show file tree
Hide file tree
Showing 22 changed files with 302 additions and 142 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
/source/Internal/Application/containercache.php

# DI for modules and packages
/source/project.yaml
/tests/Integration/Internal/Application/Dao/project.yaml
/source/generated_project.yaml
/tests/Integration/Internal/Application/Dao/generated_project.yaml
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@
"psr/container": "1.0.*",
"symfony/event-dispatcher": "^3.4",
"symfony/dependency-injection": "^3.4",
"symfony/console": "^v3.4.15"
"symfony/console": "^v3.4.15",
"webmozart/path-util": "^2.3"
},
"require-dev": {
"oxid-esales/flow-theme": "^v3.0.2",
"oxid-esales/oxideshop-doctrine-migration-wrapper": "^v2.1.2",
"oxid-esales/oxideshop-db-views-generator": "^v1.2.0",
"oxid-esales/oxideshop-demodata-installer": "^v1.1.2",
"oxid-esales/oxideshop-composer-plugin": "^v2.0.3",
"oxid-esales/oxideshop-composer-plugin": "dev-master",
"oxid-esales/oxideshop-unified-namespace-generator": "^2.0.0",
"oxid-esales/testing-library": "dev-master",
"oxid-esales/coding-standards": "^v3.0.5",
"oxid-esales/coding-standards-wrapper": "^v1.0.0",
"incenteev/composer-parameter-handler": "~v2.0",
"oxid-esales/oxideshop-ide-helper": "^3.0",
"oxid-esales/azure-theme": "^v1.4.1"
"oxid-esales/azure-theme": "^v1.4.1",
"oxid-esales/oxideshop-facts": "^2.3.1"
},
"autoload": {
"psr-4": {
Expand Down
84 changes: 47 additions & 37 deletions source/Internal/Application/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
use OxidEsales\EshopCommunity\Internal\Application\Dao\ProjectYamlDao;
use OxidEsales\EshopCommunity\Internal\Application\Service\ProjectYamlImportService;
use OxidEsales\EshopCommunity\Internal\Utility\FactsContext;
use OxidEsales\Facts\Facts;
use OxidEsales\EshopCommunity\Internal\Utility\FactsContextInterface;
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand All @@ -24,23 +25,16 @@
class ContainerBuilder
{
/**
* @var array
* @var FactsContextInterface
*/
private $serviceFilePaths = [
'services.yaml',
];
private $context;

/**
* @var Facts
* @param FactsContextInterface $context
*/
private $facts;

/**
* @param Facts $facts
*/
public function __construct(Facts $facts)
public function __construct(FactsContextInterface $context)
{
$this->facts = $facts;
$this->context = $context;
}

/**
Expand All @@ -52,13 +46,7 @@ public function getContainer(): Container
$symfonyContainer->addCompilerPass(new RegisterListenersPass());
$symfonyContainer->addCompilerPass(new ConsoleCommandPass());
$this->loadServiceFiles($symfonyContainer);
if ($this->facts->isProfessional()) {
$this->loadEditionServices($symfonyContainer, $this->facts->getProfessionalEditionRootPath());
}
if ($this->facts->isEnterprise()) {
$this->loadEditionServices($symfonyContainer, $this->facts->getProfessionalEditionRootPath());
$this->loadEditionServices($symfonyContainer, $this->facts->getEnterpriseEditionRootPath());
}
$this->loadEditionServices($symfonyContainer);
$this->loadProjectServices($symfonyContainer);

return $symfonyContainer;
Expand All @@ -69,29 +57,27 @@ public function getContainer(): Container
*/
private function loadServiceFiles(SymfonyContainerBuilder $symfonyContainer)
{
foreach ($this->serviceFilePaths as $path) {
$loader = new YamlFileLoader($symfonyContainer, new FileLocator(Path::join($this->facts->getCommunityEditionSourcePath(), 'Internal/Application')));
$loader->load($path);
}
$loader = new YamlFileLoader(
$symfonyContainer,
new FileLocator(Path::join($this->context->getCommunityEditionSourcePath(), 'Internal/Application'))
);
$loader->load('services.yaml');
}

/**
* Loads a 'project.yaml' file if it can be found in the shop directory.
*
* @param SymfonyContainerBuilder $symfonyContainer
*
* @return void
*/
private function loadProjectServices(SymfonyContainerBuilder $symfonyContainer)
{

if (! file_exists($this->facts->getSourcePath() .
DIRECTORY_SEPARATOR . ProjectYamlDao::PROJECT_FILE_NAME)) {
return;
try {
$this->cleanupProjectYaml();
$loader = new YamlFileLoader($symfonyContainer, new FileLocator($this->context->getSourcePath()));
$loader->load(FactsContext::GENERATED_PROJECT_FILE_NAME);
} catch (FileLocatorFileNotFoundException $exception) {
// In case project file not found, do nothing.
}
$this->cleanupProjectYaml();
$loader = new YamlFileLoader($symfonyContainer, new FileLocator($this->facts->getSourcePath()));
$loader->load(ProjectYamlDao::PROJECT_FILE_NAME);
}

/**
Expand All @@ -106,11 +92,35 @@ private function cleanupProjectYaml()

/**
* @param SymfonyContainerBuilder $symfonyContainer
* @param string $editionPath
*/
private function loadEditionServices(SymfonyContainerBuilder $symfonyContainer, string $editionPath)
private function loadEditionServices(SymfonyContainerBuilder $symfonyContainer)
{
$servicesLoader = new YamlFileLoader($symfonyContainer, new FileLocator($editionPath));
$servicesLoader->load('Internal/Application/services.yaml');
foreach ($this->getEditionsRootPaths() as $path) {
$servicesLoader = new YamlFileLoader($symfonyContainer, new FileLocator($path));
$servicesLoader->load('Internal/Application/services.yaml');
}
}

/**
* @return array
*/
private function getEditionsRootPaths(): array
{
$allEditionPaths = [
FactsContext::COMMUNITY_EDITION => [
$this->context->getCommunityEditionSourcePath(),
],
FactsContext::PROFESSIONAL_EDITION => [
$this->context->getCommunityEditionSourcePath(),
$this->context->getProfessionalEditionRootPath(),
],
FactsContext::ENTERPRISE_EDITION => [
$this->context->getCommunityEditionSourcePath(),
$this->context->getProfessionalEditionRootPath(),
$this->context->getEnterpriseEditionRootPath(),
],
];

return $allEditionPaths[$this->context->getEdition()];
}
}
23 changes: 23 additions & 0 deletions source/Internal/Application/ContainerBuilderFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);
/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

namespace OxidEsales\EshopCommunity\Internal\Application;

use OxidEsales\EshopCommunity\Internal\Utility\FactsContext;

/**
* @internal
*/
class ContainerBuilderFactory
{
/**
* @return ContainerBuilder
*/
public function create(): ContainerBuilder
{
return new ContainerBuilder(new FactsContext());
}
}
3 changes: 1 addition & 2 deletions source/Internal/Application/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace OxidEsales\EshopCommunity\Internal\Application;

use OxidEsales\EshopCommunity\Internal\Utility\FactsContext;
use OxidEsales\Facts\Facts;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;

Expand Down Expand Up @@ -79,7 +78,7 @@ private function loadContainerFromCache($cachefile)
*/
private function getCompiledSymfonyContainer()
{
$containerBuilder = new ContainerBuilder(new Facts());
$containerBuilder = (new ContainerBuilderFactory())->create();
$this->symfonyContainer = $containerBuilder->getContainer();
$this->symfonyContainer->compile();
}
Expand Down
16 changes: 2 additions & 14 deletions source/Internal/Application/Dao/ProjectYamlDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@

namespace OxidEsales\EshopCommunity\Internal\Application\Dao;

use OxidEsales\EshopCommunity\Internal\Application\Events\ProjectYamlChangedEvent;
use OxidEsales\EshopCommunity\Internal\Application\DataObject\DIConfigWrapper;
use OxidEsales\EshopCommunity\Internal\Utility\FactsContextInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Yaml\Yaml;

/**
* @internal
*/
class ProjectYamlDao implements ProjectYamlDaoInterface
{
const PROJECT_FILE_NAME = 'project.yaml';

/**
* @var FactsContextInterface $context
*/
Expand All @@ -37,15 +33,15 @@ public function __construct(FactsContextInterface $context)
*/
public function loadProjectConfigFile(): DIConfigWrapper
{
return $this->loadDIConfigFile($this->getProjectFileName());
return $this->loadDIConfigFile($this->context->getGeneratedProjectFilePath());
}

/**
* @param DIConfigWrapper $config
*/
public function saveProjectConfigFile(DIConfigWrapper $config)
{
file_put_contents($this->getProjectFileName(), Yaml::dump($config->getConfigAsArray(), 3, 2));
file_put_contents($this->context->getGeneratedProjectFilePath(), Yaml::dump($config->getConfigAsArray(), 3, 2));
}

/**
Expand All @@ -63,12 +59,4 @@ public function loadDIConfigFile(string $path): DIConfigWrapper

return new DIConfigWrapper($yamlArray);
}

/**
* @return string
*/
private function getProjectFileName(): string
{
return $this->context->getSourcePath() . DIRECTORY_SEPARATOR . self::PROJECT_FILE_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use OxidEsales\EshopCommunity\Internal\Application\Dao\ProjectYamlDaoInterface;

/**
* Class ProjectYamlImportService
* @internal
*/
class ProjectYamlImportService implements ProjectYamlImportServiceInterface
{
const SERVICE_FILE_NAME = 'services.yaml';

/**
* @var ProjectYamlDaoInterface
*/
Expand All @@ -37,7 +39,7 @@ public function addImport(string $serviceDir)
{
$projectConfig = $this->projectYamlDao->loadProjectConfigFile();

$projectConfig->addImport($serviceDir . DIRECTORY_SEPARATOR . 'services.yaml');
$projectConfig->addImport($serviceDir . DIRECTORY_SEPARATOR . static::SERVICE_FILE_NAME);

$this->projectYamlDao->saveProjectConfigFile($projectConfig);
}
Expand All @@ -49,7 +51,7 @@ public function removeImport(string $serviceDir)
{
$projectConfig = $this->projectYamlDao->loadProjectConfigFile();

$projectConfig->removeImport($serviceDir . DIRECTORY_SEPARATOR . 'services.yaml');
$projectConfig->removeImport($serviceDir . DIRECTORY_SEPARATOR . static::SERVICE_FILE_NAME);

$this->projectYamlDao->saveProjectConfigFile($projectConfig);
}
Expand Down
24 changes: 0 additions & 24 deletions source/Internal/Console/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,3 @@ services:
class: OxidEsales\EshopCommunity\Internal\Console\CommandsProvider\ServicesCommandsProvider
public: false
autowire: true

oxid_esales.console.composer.composer:
class: Composer\Composer
public: true
factory: 'oxid_esales.console.composer.factory:create'
arguments: ['@oxid_esales.console.composer.io.null_io']

oxid_esales.console.composer.factory:
class: Composer\Factory
public: false

oxid_esales.console.composer.io.null_io:
class: Composer\IO\NullIO
public: false

oxid_esales.console.composer.repository.manager:
class: Composer\Repository\RepositoryManager
factory: 'oxid_esales.console.composer.composer:getRepositoryManager'
public: false

oxid_esales.console.composer.repository.local_repository:
class: Composer\Repository\FilesystemRepository
factory: 'oxid_esales.console.composer.repository.manager:getLocalRepository'
public: false
49 changes: 49 additions & 0 deletions source/Internal/Utility/FactsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace OxidEsales\EshopCommunity\Internal\Utility;

use OxidEsales\Facts\Edition\EditionSelector;
use OxidEsales\Facts\Facts;
use Webmozart\PathUtil\Path;

Expand All @@ -15,6 +16,14 @@
*/
class FactsContext implements FactsContextInterface
{
const COMMUNITY_EDITION = EditionSelector::COMMUNITY;

const PROFESSIONAL_EDITION = EditionSelector::PROFESSIONAL;

const ENTERPRISE_EDITION = EditionSelector::ENTERPRISE;

const GENERATED_PROJECT_FILE_NAME = 'generated_project.yaml';

/**
* @var Facts
*/
Expand All @@ -29,6 +38,14 @@ public function getContainerCacheFilePath(): string
return Path::join($this->getSourcePath(), 'tmp', 'containercache.php');
}

/**
* @return string
*/
public function getGeneratedProjectFilePath(): string
{
return Path::join($this->getSourcePath() . DIRECTORY_SEPARATOR . static::GENERATED_PROJECT_FILE_NAME);
}

/**
* @return string
*/
Expand All @@ -37,6 +54,38 @@ public function getSourcePath(): string
return $this->getFacts()->getSourcePath();
}

/**
* @return string
*/
public function getEdition(): string
{
return $this->getFacts()->getEdition();
}

/**
* @return string
*/
public function getCommunityEditionSourcePath(): string
{
return $this->getFacts()->getCommunityEditionSourcePath();
}

/**
* @return string
*/
public function getProfessionalEditionRootPath(): string
{
return $this->getFacts()->getProfessionalEditionRootPath();
}

/**
* @return string
*/
public function getEnterpriseEditionRootPath(): string
{
return $this->getFacts()->getEnterpriseEditionRootPath();
}

/**
* @return Facts
*/
Expand Down
Loading

0 comments on commit 4b95f24

Please sign in to comment.