Permalink
Browse files

OXDEV-921 WIP

  • Loading branch information...
gregorhyneck committed Jun 19, 2018
1 parent 6d11ab2 commit deb10eac8db36d6fc335376258d235c6131253ee
@@ -184,6 +184,18 @@ public function getControllers()
return isset($this->_aModule['controllers']) ? array_change_key_case($this->_aModule['controllers']) : [];
}
/**
* @return array
*/
public function getSmartyPluginDirectories()
{
if (isset($this->_aModule['smartyPluginDirectories']) && ! is_array($this->_aModule['smartyPluginDirectories'])) {
throw new \InvalidArgumentException('Value for metadata key "smartyPluginDirectories" must be an array');
}
return $this->_aModule['smartyPluginDirectories'];
}
/**
* Returns array of module PHP files.
*
@@ -26,6 +26,9 @@ class ModuleInstaller extends \OxidEsales\Eshop\Core\Base
/** @var \OxidEsales\Eshop\Core\Module\ModuleExtensionsCleaner */
private $moduleCleaner;
/** @var \OxidEsales\Eshop\Core\ShopIdCalculator */
private $shopIdCalculator;
/**
* Sets dependencies.
*
@@ -104,6 +107,10 @@ public function activate(\OxidEsales\Eshop\Core\Module\Module $module)
}
}
if (version_compare($module->getMetaDataVersion(), '2.1', '>=')) {
$this->addSmartyPluginDirectories($module->getSmartyPluginDirectories(), $moduleId);
}
$this->resetCache();
$this->_callEvent('onActivate', $moduleId);
@@ -114,6 +121,46 @@ public function activate(\OxidEsales\Eshop\Core\Module\Module $module)
return $result;
}
/**
* @param array $smartyPluginDirectories
* @param string $moduleId
*
*/
protected function addSmartyPluginDirectories($smartyPluginDirectories, $moduleId)
{
$smartyPluginDirectoryBridge = $this->getModuleSmartyPluginDirectoryStorage();
$smartyPluginDirectoryBridge->add($smartyPluginDirectories, $moduleId);
}
/**
* @return \OxidEsales\EshopCommunity\Core\Module\ModuleSmartyPluginDirectoryRepository
*/
private function getModuleSmartyPluginDirectoryStorage()
{
$module = oxNew(\OxidEsales\Eshop\Core\Module\Module::class);
$subShopSpecificCache = new \OxidEsales\Eshop\Core\SubShopSpecificFileCache($this->getShopIdCalculator());
$moduleVariablesLocator = new \OxidEsales\Eshop\Core\Module\ModuleVariablesLocator($subShopSpecificCache, $this->getShopIdCalculator());
return new \OxidEsales\EshopCommunity\Core\Module\ModuleSmartyPluginDirectoryRepository(
$this->getConfig(),
$moduleVariablesLocator,
$module
);
}
/**
* @return \OxidEsales\Eshop\Core\ShopIdCalculator
*/
private function getShopIdCalculator()
{
if (is_null($this->shopIdCalculator)) {
$moduleVariablesCache = new \OxidEsales\Eshop\Core\FileCache();
$this->shopIdCalculator = new \OxidEsales\Eshop\Core\ShopIdCalculator($moduleVariablesCache);
}
return $this->shopIdCalculator;
}
/**
* Deactivate extension by adding disable module class information to disabled module array
*
@@ -136,6 +183,8 @@ public function deactivate(\OxidEsales\Eshop\Core\Module\Module $module)
$this->_deleteModuleEvents($moduleId);
$this->_deleteModuleVersions($moduleId);
$this->deleteModuleControllers($moduleId);
$this->deleteSmartyPluginDirectories($moduleId);
$this->resetCache();
@@ -145,6 +194,15 @@ public function deactivate(\OxidEsales\Eshop\Core\Module\Module $module)
return $result;
}
/**
* @param string $moduleId
*/
private function deleteSmartyPluginDirectories($moduleId)
{
$smartyPluginDirectoryBridge = $this->getModuleSmartyPluginDirectoryStorage();
$smartyPluginDirectoryBridge->remove($moduleId);
}
/**
* Get parsed modules
*
@@ -0,0 +1,72 @@
<?php
/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/
namespace OxidEsales\EshopCommunity\Core\Module;
/**
* Class ModuleSmartyPluginDirectoryDao
*
* @internal Do not make a module extension for this class.
* @see https://oxidforge.org/en/core-oxid-eshop-classes-must-not-be-extended.html
*
* @ignore This class will not be included in documentation.
*
*/
class ModuleSmartyPluginDirectoryDao
{
/**
* @var string The key under which the value will be stored.
*/
const STORAGE_KEY = 'aModuleSmartyPluginDirectories';
/** @var \OxidEsales\Eshop\Core\Config */
private $config = null;
/**
* @var \OxidEsales\Eshop\Core\Module\ModuleVariablesLocator
*
* Necessary for caching
*/
private $moduleVariablesLocator;
/**
* ModuleSmartyPluginDirectoryDao constructor.
*
* @param \OxidEsales\Eshop\Core\Config $config For database connection
* @param \OxidEsales\Eshop\Core\Module\ModuleVariablesLocator $moduleVariablesLocator For caching
*/
public function __construct(
\OxidEsales\Eshop\Core\Config $config,
\OxidEsales\Eshop\Core\Module\ModuleVariablesLocator $moduleVariablesLocator
) {
$this->config = $config;
$this->moduleVariablesLocator = $moduleVariablesLocator;
}
/**
* @return array The smarty plugin directories of all modules with absolute path as numeric array
*/
public function get()
{
$smartyPluginDirectories = $this->moduleVariablesLocator->getModuleVariable(self::STORAGE_KEY);
if ($smartyPluginDirectories === false) {
return [];
}
return $smartyPluginDirectories;
}
/**
* @param array $value The smarty plugin directories of all modules separated by module
*/
public function set($value)
{
$this->config->saveShopConfVar('aarr', self::STORAGE_KEY, $value);
$this->moduleVariablesLocator->setModuleVariable(self::STORAGE_KEY, $value);
}
}
@@ -0,0 +1,106 @@
<?php
/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/
namespace OxidEsales\EshopCommunity\Core\Module;
/**
* Class ModuleSmartyPluginDirectoryStorage
*
* @internal Do not make a module extension for this class.
* @see https://oxidforge.org/en/core-oxid-eshop-classes-must-not-be-extended.html
*
* @ignore This class will not be included in documentation.
*
*/
class ModuleSmartyPluginDirectoryRepository
{
/**
* @var \OxidEsales\Eshop\Core\Module\Module
*
* Needed to get the absolute path to a module directory
*/
private $module = null;
/**
* @var \OxidEsales\EshopCommunity\Core\Module\ModuleSmartyPluginDirectoryDao
*
* We want to have an external dependecy for better testability
*/
private $dao = null;
/**
* SmartyPluginDirectoryBridge constructor.
*
* @param \OxidEsales\EshopCommunity\Core\Module\ModuleSmartyPluginDirectoryDao $moduleSmartyPluginDirectoryDao
* @param \OxidEsales\EshopCommunity\Core\Module\Module $module
*/
public function __construct(
\OxidEsales\EshopCommunity\Core\Module\ModuleSmartyPluginDirectoryDao $moduleSmartyPluginDirectoryDao,
\OxidEsales\EshopCommunity\Core\Module\Module $module
) {
$this->dao = $moduleSmartyPluginDirectoryDao;
$this->module = $module;
}
/**
* @param array $moduleSmartyPluginDirectories
* @param string $moduleId
*/
public function add($moduleSmartyPluginDirectories, $moduleId)
{
$smartyPluginDirectories = $this->dao->get();
$smartyPluginDirectories[$moduleId] = $moduleSmartyPluginDirectories;
$this->dao->set($smartyPluginDirectories);
}
/**
* Delete the smarty plugin directories for the module, given by its ID, from the storage.
*
* @param string $moduleId The ID of the module, for which we want to delete the controllers from the storage.
*/
public function remove($moduleId)
{
$smartyPluginDirectories = $this->dao->get();
unset($smartyPluginDirectories[$moduleId]);
$this->dao->set($smartyPluginDirectories);
}
/**
* @return array The smarty plugin directories of all modules with absolute path as numeric array
*/
public function get()
{
$smartyPluginDirectories = $this->dao->get();
if ($smartyPluginDirectories === false) {
return [];
}
return $this->getSmartyPluginDirectoriesWithFullPath($smartyPluginDirectories);
}
/**
* @param array $smartyPluginDirectories
*
* @return array
*/
private function getSmartyPluginDirectoriesWithFullPath(array $smartyPluginDirectories)
{
$smartyPluginDirectoriesWithFullPath = [];
foreach ($smartyPluginDirectories as $moduleId => $smartyDirectoriesOfOneModule) {
foreach ($smartyDirectoriesOfOneModule as $smartyPluginDirectory) {
$smartyPluginDirectoriesWithFullPath[] = $this->module->getModuleFullPath($moduleId) .
DIRECTORY_SEPARATOR .
$smartyPluginDirectory;
}
}
return $smartyPluginDirectoriesWithFullPath;
}
}
@@ -46,6 +46,9 @@ class UtilsView extends \OxidEsales\Eshop\Core\Base
*/
protected $_aActiveModuleInfo = null;
/** @var \OxidEsales\Eshop\Core\ShopIdCalculator */
private $shopIdCalculator;
/**
* returns existing or creates smarty object
* Returns smarty object. If object not yet initiated - creates it. Sets such
@@ -356,6 +359,12 @@ protected function _fillCommonSmartyProperties($smarty)
$coreDirectory = $config->getConfigParam('sCoreDir');
array_unshift($smarty->plugins_dir, $coreDirectory . 'Smarty/Plugin');
$moduleSmartyPluginDirectoryStorage = $this->getSmartyPluginDirectoryRepository();
$moduleSmartyPluginDirectories = $moduleSmartyPluginDirectoryStorage->get();
$smarty->plugins_dir = array_merge($moduleSmartyPluginDirectories, $smarty->plugins_dir);
include_once $coreDirectory . 'Smarty/Plugin/prefilter.oxblock.php';
$smarty->register_prefilter('smarty_prefilter_oxblock');
@@ -389,6 +398,38 @@ protected function _fillCommonSmartyProperties($smarty)
}
}
/**
* @return \OxidEsales\EshopCommunity\Core\Module\ModuleSmartyPluginDirectoryRepository
*/
private function getSmartyPluginDirectoryRepository()
{
$subShopSpecificCache = new \OxidEsales\Eshop\Core\SubShopSpecificFileCache($this->getShopIdCalculator());
$moduleVariablesLocator = new \OxidEsales\Eshop\Core\Module\ModuleVariablesLocator($subShopSpecificCache, $this->getShopIdCalculator());
$moduleSmartyDirectoryDao = new \OxidEsales\EshopCommunity\Core\Module\ModuleSmartyPluginDirectoryDao(
$this->getConfig(),
$moduleVariablesLocator
);
$module = oxNew(\OxidEsales\Eshop\Core\Module\Module::class);
return new \OxidEsales\EshopCommunity\Core\Module\ModuleSmartyPluginDirectoryRepository(
$moduleSmartyDirectoryDao,
$module
);
}
/**
* @return \OxidEsales\Eshop\Core\ShopIdCalculator
*/
private function getShopIdCalculator()
{
if (is_null($this->shopIdCalculator)) {
$moduleVariablesCache = new \OxidEsales\Eshop\Core\FileCache();
$this->shopIdCalculator = new \OxidEsales\Eshop\Core\ShopIdCalculator($moduleVariablesCache);
}
return $this->shopIdCalculator;
}
/**
* Sets compile check property to smarty object.
*
Oops, something went wrong.

0 comments on commit deb10ea

Please sign in to comment.