Permalink
Browse files

OXDEV-1580 Introduce services for components

  • Loading branch information...
MantasVaitkunas committed Oct 25, 2018
1 parent 63a8bc1 commit 3d62cc2a0f277980e1dbaa24281f06c24aef7f49
@@ -1,18 +1,15 @@
<?php
declare(strict_types=1);
<?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\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Console\ConsoleCommandPass;
use OxidEsales\EshopCommunity\Internal\Application\Dao\ProjectYamlDao;
use OxidEsales\EshopCommunity\Internal\Application\Service\ProjectYamlImportService;
use OxidEsales\EshopCommunity\Internal\Utility\Context;
use OxidEsales\EshopCommunity\Internal\Utility\FactsContext;
use OxidEsales\Facts\Facts;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Container;
@@ -102,8 +99,7 @@ private function loadProjectServices(SymfonyContainerBuilder $symfonyContainer)
*/
private function cleanupProjectYaml()
{
$context = new Context(Registry::getConfig());
$projectYamlDao = new ProjectYamlDao($context);
$projectYamlDao = new ProjectYamlDao(new FactsContext());
$yamlImportService = new ProjectYamlImportService($projectYamlDao);
$yamlImportService->removeNonExistingImports();
}
@@ -7,9 +7,8 @@
namespace OxidEsales\EshopCommunity\Internal\Application;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Utility\FactsContext;
use OxidEsales\Facts\Facts;
use OxidEsales\EshopCommunity\Internal\Utility\Context;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@@ -103,8 +102,8 @@ private function saveContainerToCache($cachefile)
*/
private static function getCacheFilePath()
{
$context = new Context(Registry::getConfig());
return $context->getContainerCacheFile();
$context = new FactsContext();
return $context->getContainerCacheFilePath();
}
/**
@@ -9,7 +9,7 @@
use OxidEsales\EshopCommunity\Internal\Application\Events\ProjectYamlChangedEvent;
use OxidEsales\EshopCommunity\Internal\Application\DataObject\DIConfigWrapper;
use OxidEsales\EshopCommunity\Internal\Utility\ContextInterface;
use OxidEsales\EshopCommunity\Internal\Utility\FactsContextInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
@@ -25,10 +25,10 @@ class ContainerAwareProjectYamlDao extends ProjectYamlDao
/**
* ProjectYamlDao constructor.
*
* @param ContextInterface $context
* @param FactsContextInterface $context
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(ContextInterface $context, EventDispatcherInterface $eventDispatcher)
public function __construct(FactsContextInterface $context, EventDispatcherInterface $eventDispatcher)
{
parent::__construct($context);
$this->eventDispatcher = $eventDispatcher;
@@ -1,5 +1,4 @@
<?php declare(strict_types=1);
/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
@@ -9,7 +8,7 @@
use OxidEsales\EshopCommunity\Internal\Application\Events\ProjectYamlChangedEvent;
use OxidEsales\EshopCommunity\Internal\Application\DataObject\DIConfigWrapper;
use OxidEsales\EshopCommunity\Internal\Utility\ContextInterface;
use OxidEsales\EshopCommunity\Internal\Utility\FactsContextInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Yaml\Yaml;
@@ -18,20 +17,17 @@
*/
class ProjectYamlDao implements ProjectYamlDaoInterface
{
const PROJECT_FILE_NAME = 'project.yaml';
/**
* @var ContextInterface $context
* @var FactsContextInterface $context
*/
private $context;
/**
* ProjectYamlDao constructor.
*
* @param ContextInterface $context
* @param FactsContextInterface $context
*/
public function __construct(ContextInterface $context)
public function __construct(FactsContextInterface $context)
{
$this->context = $context;
}
@@ -55,7 +51,7 @@ public function saveProjectConfigFile(DIConfigWrapper $config)
/**
* @param string $path
*
* @return array
* @return DIConfigWrapper
*/
public function loadDIConfigFile(string $path): DIConfigWrapper
{
@@ -73,6 +69,6 @@ public function loadDIConfigFile(string $path): DIConfigWrapper
*/
private function getProjectFileName(): string
{
return $this->context->getShopDir() . DIRECTORY_SEPARATOR . self::PROJECT_FILE_NAME;
return $this->context->getSourcePath() . DIRECTORY_SEPARATOR . self::PROJECT_FILE_NAME;
}
}
@@ -8,14 +8,12 @@
namespace OxidEsales\EshopCommunity\Internal\Application\Service;
use OxidEsales\EshopCommunity\Internal\Application\Dao\ProjectYamlDaoInterface;
use OxidEsales\EshopCommunity\Internal\Application\Service\ProjectYamlImportServiceInterface;
/**
* Class ProjectYamlImportService
*/
class ProjectYamlImportService implements ProjectYamlImportServiceInterface
{
/**
* @var ProjectYamlDaoInterface
*/
@@ -24,11 +22,11 @@ class ProjectYamlImportService implements ProjectYamlImportServiceInterface
/**
* ProjectYamlImportService constructor.
*
* @param ProjectYamlDaoInterface $dao
* @param ProjectYamlDaoInterface $projectYamlDao
*/
public function __construct(ProjectYamlDaoInterface $dao)
public function __construct(ProjectYamlDaoInterface $projectYamlDao)
{
$this->projectYamlDao = $dao;
$this->projectYamlDao = $projectYamlDao;
}
/**
@@ -8,7 +8,7 @@
namespace OxidEsales\EshopCommunity\Internal\Application\Service;
/**
* Class ProjectYamlImportService
* @internal
*/
interface ProjectYamlImportServiceInterface
{
@@ -39,7 +39,10 @@ public function __construct(
}
/**
* @inheritdoc
* Executes commands.
*
* @param InputInterface|null $input
* @param OutputInterface|null $output
*/
public function execute(InputInterface $input = null, OutputInterface $output = null)
{
@@ -16,8 +16,6 @@
interface ExecutorInterface
{
/**
* Executes commands.
*
* @param InputInterface|null $input
* @param OutputInterface|null $output
*/
@@ -19,11 +19,6 @@ class Context implements ContextInterface
*/
private $config;
/**
* @var
*/
private $facts;
/**
* Context constructor.
* @param Config $config
@@ -67,22 +62,6 @@ public function getCurrentShopId()
return $this->config->getShopId();
}
/**
* @return string
*/
public function getShopDir()
{
return $this->getFacts()->getSourcePath();
}
/**
* @return string
*/
public function getContainerCacheFile()
{
return $this->getConfigParameter('sCompileDir') . DIRECTORY_SEPARATOR . 'containercache.php';
}
/**
* @param string $name
* @return mixed
@@ -91,15 +70,4 @@ private function getConfigParameter($name)
{
return $this->config->getConfigParam($name);
}
/**
* @return Facts
*/
private function getFacts()
{
if ($this->facts == null) {
$this->facts = new Facts();
}
return $this->facts;
}
}
@@ -30,14 +30,4 @@ public function getRequiredContactFormFields();
* @return int
*/
public function getCurrentShopId();
/**
* @return string
*/
public function getShopDir();
/**
* @return mixed
*/
public function getContainerCacheFile();
}
@@ -0,0 +1,50 @@
<?php declare(strict_types=1);
/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/
namespace OxidEsales\EshopCommunity\Internal\Utility;
use OxidEsales\Facts\Facts;
use Webmozart\PathUtil\Path;
/**
* @inheritdoc
* @internal
*/
class FactsContext implements FactsContextInterface
{
/**
* @var Facts
*/
private $facts;
/**
* @todo change placement of containercache.php file and move logic to Facts.
* @return string
*/
public function getContainerCacheFilePath(): string
{
return Path::join($this->getSourcePath(), 'tmp', 'containercache.php');
}
/**
* @return string
*/
public function getSourcePath(): string
{
return $this->getFacts()->getSourcePath();
}
/**
* @return Facts
*/
private function getFacts(): Facts
{
if ($this->facts === null) {
$this->facts = new Facts();
}
return $this->facts;
}
}
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/
namespace OxidEsales\EshopCommunity\Internal\Utility;
/**
* Contains necessary methods to provide basic information about the application.
* @internal
*/
interface FactsContextInterface
{
/**
* @return string
*/
public function getContainerCacheFilePath(): string;
/**
* @return string
*/
public function getSourcePath(): string;
}
@@ -7,3 +7,6 @@ services:
class: OxidEsales\EshopCommunity\Internal\Utility\Context
autowire: true
public: false
OxidEsales\EshopCommunity\Internal\Utility\FactsContextInterface:
class: OxidEsales\EshopCommunity\Internal\Utility\FactsContext
public: false
Oops, something went wrong.

0 comments on commit 3d62cc2

Please sign in to comment.