Commit 76adcfd4 authored by Tino Goratsch's avatar Tino Goratsch

extracted the duplicated code for fetching the various module vendors into one class "Vendors"

parent f972146e
......@@ -149,11 +149,11 @@ class Application extends AbstractApplication
/** @var Modules $modules */
$modules = $containerBuilder->get('core.modules');
$activeModules = $modules->getActiveModules();
$moduleNamespaces = $modules->getModuleNamespaces();
$vendors = $containerBuilder->get('core.modules.vendors')->getVendors();
foreach ($activeModules as $module) {
foreach ($moduleNamespaces as $namespace) {
$path = MODULES_DIR . $namespace . '/' . $module['dir'] . '/config/services.yml';
foreach ($vendors as $vendor) {
$path = MODULES_DIR . $vendor . '/' . $module['dir'] . '/config/services.yml';
if (is_file($path)) {
$loader->load($path);
......
......@@ -17,6 +17,10 @@ class ThemeResolver
* @var \ACP3\Core\Assets\Cache
*/
protected $resourcesCache;
/**
* @var \ACP3\Core\Modules\Vendors
*/
protected $vendors;
/**
* @var array
*/
......@@ -33,22 +37,21 @@ class ThemeResolver
* @var string
*/
protected $designAssetsPath = DESIGN_PATH_INTERNAL;
/**
* @var array
*/
protected $moduleNamespaces = [];
/**
* @param \ACP3\Core\XML $xml
* @param \ACP3\Core\Assets\Cache $resourcesCache
* @param \ACP3\Core\XML $xml
* @param \ACP3\Core\Assets\Cache $resourcesCache
* @param \ACP3\Core\Modules\Vendors $vendors
*/
public function __construct(
Core\XML $xml,
Core\Assets\Cache $resourcesCache
Core\Assets\Cache $resourcesCache,
Core\Modules\Vendors $vendors
)
{
$this->xml = $xml;
$this->resourcesCache = $resourcesCache;
$this->vendors = $vendors;
$this->cachedPaths = $resourcesCache->getCache();
}
......@@ -62,22 +65,6 @@ class ThemeResolver
}
}
/**
* @return array
*/
protected function _getModuleNamespaces()
{
if ($this->moduleNamespaces === []) {
$this->moduleNamespaces = array_merge(
['ACP3'],
array_diff(scandir(MODULES_DIR), ['.', '..', 'ACP3', 'Custom']),
['Custom']
);
}
return $this->moduleNamespaces;
}
/**
* @param $modulePath
* @param $designPath
......@@ -135,8 +122,8 @@ class ThemeResolver
}
// No overrides have been found -> iterate over all possible module namespaces
foreach (array_reverse($this->_getModuleNamespaces()) as $namespace) {
$moduleAssetPath = $this->modulesAssetsPath . $namespace . '/' . $modulePath . $dir . $file;
foreach (array_reverse($this->vendors->getVendors()) as $vendor) {
$moduleAssetPath = $this->modulesAssetsPath . $vendor . '/' . $modulePath . $dir . $file;
if (is_file($moduleAssetPath) === true) {
$assetPath = $moduleAssetPath;
break;
......
......@@ -39,10 +39,6 @@ class Lang
* @var array
*/
protected $buffer = [];
/**
* @var array
*/
protected $moduleNamespaces = [];
/**
* @param \ACP3\Core\Auth $auth
......@@ -375,7 +371,7 @@ class Lang
{
if ($this->lang === '') {
$lang = $this->auth->getUserLanguage();
$this->lang = $this->languagePackExists($lang) === true ? $lang : $this->config->getSettings('system')['lang'];
$this->lang = self::languagePackExists($lang) === true ? $lang : $this->config->getSettings('system')['lang'];
}
return $this->lang;
......
<?php
namespace ACP3\Core\Lang;
use ACP3\Core\Modules\Vendors;
/**
* Class Cache
......@@ -12,18 +13,21 @@ class Cache
*/
protected $cache;
/**
* @var array
* @var \ACP3\Core\Modules\Vendors
*/
protected $moduleNamespaces = [];
protected $vendors;
/**
* @param \ACP3\Core\Cache $langCache
* @param \ACP3\Core\Cache $cache
* @param \ACP3\Core\Modules\Vendors $vendors
*/
public function __construct(
\ACP3\Core\Cache $langCache
\ACP3\Core\Cache $cache,
Vendors $vendors
)
{
$this->cache = $langCache;
$this->cache = $cache;
$this->vendors = $vendors;
}
/**
......@@ -53,7 +57,7 @@ class Cache
{
$data = [];
foreach ($this->_getModuleNamespaces() as $namespace) {
foreach ($this->vendors->getVendors() as $namespace) {
$languageFiles = glob(MODULES_DIR . $namespace . '/*/Languages/' . $language . '.xml');
if ($languageFiles !== false) {
......@@ -76,22 +80,6 @@ class Cache
return $this->cache->save($language, $data);
}
/**
* @return array
*/
protected function _getModuleNamespaces()
{
if ($this->moduleNamespaces === []) {
$this->moduleNamespaces = array_merge(
['ACP3'],
array_diff(scandir(MODULES_DIR), ['.', '..', 'ACP3', 'Custom']),
['Custom']
);
}
return $this->moduleNamespaces;
}
/**
* @param $path
*
......@@ -127,7 +115,7 @@ class Cache
{
$languagePacks = [];
foreach ($this->_getModuleNamespaces() as $namespace) {
foreach ($this->vendors->getVendors() as $namespace) {
$languageFiles = glob(MODULES_DIR . $namespace . '/*/Languages/*.xml');
if ($languageFiles !== false) {
......
<?php
namespace ACP3\Core;
use ACP3\Core\Modules\Vendors;
use ACP3\Modules\ACP3\System;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -31,37 +32,40 @@ class Modules
*/
protected $systemModel;
/**
* @var array
* @var \ACP3\Core\Modules\Vendors
*/
private $parseModules = [];
protected $vendors;
/**
* @var array
*/
private $allModules = [];
private $parseModules = [];
/**
* @var array
*/
private $moduleNamespaces = [];
private $allModules = [];
/**
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\XML $xml
* @param \ACP3\Core\Cache $modulesCache
* @param \ACP3\Core\Cache $cache
* @param \ACP3\Core\Modules\Vendors $vendors
* @param \ACP3\Modules\ACP3\System\Model $systemModel
*/
public function __construct(
ContainerInterface $container,
Lang $lang,
XML $xml,
Cache $modulesCache,
Cache $cache,
Vendors $vendors,
System\Model $systemModel
)
{
$this->container = $container;
$this->lang = $lang;
$this->xml = $xml;
$this->modulesCache = $modulesCache;
$this->modulesCache = $cache;
$this->vendors = $vendors;
$this->systemModel = $systemModel;
}
......@@ -147,22 +151,6 @@ class Modules
return 'infos_' . $this->lang->getLanguage();
}
/**
* @return array
*/
public function getModuleNamespaces()
{
if ($this->moduleNamespaces === []) {
$this->moduleNamespaces = array_merge(
['ACP3'],
array_diff(scandir(MODULES_DIR), ['.', '..', 'ACP3', 'Custom']),
['Custom']
);
}
return $this->moduleNamespaces;
}
/**
* Saves a modules info cache
*/
......@@ -173,23 +161,23 @@ class Modules
// 1. fetch all core modules
// 2. Fetch all 3rd party modules
// 3. Fetch all local module customizations
foreach ($this->getModuleNamespaces() as $namespace) {
$infos += $this->_fetchModulesInNamespaces($namespace);
foreach ($this->vendors->getVendors() as $namespace) {
$infos += $this->_fetchModulesInVendors($namespace);
}
$this->modulesCache->save($this->_getCacheKey(), $infos);
}
/**
* @param string $namespace
* @param string $vendor
*
* @return array
*/
protected function _fetchModulesInNamespaces($namespace)
protected function _fetchModulesInVendors($vendor)
{
$infos = [];
$modules = array_diff(scandir(MODULES_DIR . $namespace . '/'), ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd']);
$modules = array_diff(scandir(MODULES_DIR . $vendor . '/'), ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd']);
if (!empty($modules)) {
foreach ($modules as $module) {
......@@ -211,7 +199,7 @@ class Modules
*/
protected function _fetchModuleInfo($moduleDirectory)
{
$namespaces = array_reverse($this->getModuleNamespaces()); // Reverse the order of the array -> search module customizations first, then 3rd party modules, then core modules
$namespaces = array_reverse($this->vendors->getVendors()); // Reverse the order of the array -> search module customizations first, then 3rd party modules, then core modules
foreach ($namespaces as $namespace) {
$path = MODULES_DIR . $namespace . '/' . $moduleDirectory . '/config/module.xml';
if (is_file($path) === true) {
......@@ -299,7 +287,7 @@ class Modules
public function getAllModules()
{
if (empty($this->allModules)) {
foreach ($this->getModuleNamespaces() as $namespace) {
foreach ($this->vendors->getVendors() as $namespace) {
$modules = array_diff(scandir(MODULES_DIR . $namespace . '/'), ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd']);
foreach ($modules as $module) {
$info = $this->getModuleInfo($module);
......
<?php
namespace ACP3\Core\Modules;
/**
* Class Vendors
* @package ACP3\Core\Modules
*/
class Vendors
{
/**
* @var array
*/
protected $vendors = [];
/**
* @return array
*/
public function getVendors()
{
if ($this->vendors === []) {
$this->vendors = array_merge(
['ACP3'],
array_diff(scandir(MODULES_DIR), ['.', '..', 'ACP3', 'Custom']),
['Custom']
);
}
return $this->vendors;
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ services:
core.assets.themeResolver:
class: ACP3\Core\Assets\ThemeResolver
arguments: ['@core.xml', '@core.assets.cache']
arguments: ['@core.xml', '@core.assets.cache', @core.modules.vendors]
core.assets.pageCssClasses:
class: ACP3\Core\Assets\PageCssClasses
......
......@@ -16,7 +16,10 @@ services:
core.modules:
class: ACP3\Core\Modules
arguments: ['@service_container', '@core.lang', '@core.xml', '@core.cache.system', '@system.model']
arguments: ['@service_container', '@core.lang', '@core.xml', '@core.cache.system', @core.modules.vendors, '@system.model']
core.modules.vendors:
class: ACP3\Core\Modules\Vendors
core.modules.schemaHelper:
class: ACP3\Core\Modules\SchemaHelper
......
......@@ -50,7 +50,7 @@ services:
core.lang.cache:
class: ACP3\Core\Lang\Cache
arguments: ['@core.cache.system']
arguments: ['@core.cache.system', @core.modules.vendors]
core.mailer:
class: ACP3\Core\Mailer
......
......@@ -25,20 +25,27 @@ class Helpers
* @var \ACP3\Core\Modules\SchemaInstaller
*/
protected $schemaInstaller;
/**
* @var \ACP3\Core\Modules\Vendors
*/
protected $vendors;
/**
* @param Core\DB $db
* @param Core\Modules $modules
* @param \ACP3\Core\Modules\Vendors $vendors
* @param \ACP3\Core\Modules\SchemaInstaller $schemaInstaller
*/
public function __construct(
Core\DB $db,
Core\Modules $modules,
Core\Modules\Vendors $vendors,
Core\Modules\SchemaInstaller $schemaInstaller
)
{
$this->db = $db;
$this->modules = $modules;
$this->vendors = $vendors;
$this->schemaInstaller = $schemaInstaller;
}
......@@ -105,11 +112,11 @@ class Helpers
// Try to get all available services
$modules = ($allModules === true) ? $this->modules->getAllModules() : $this->modules->getInstalledModules();
$moduleNamespaces = $this->modules->getModuleNamespaces();
$vendors = $this->vendors->getVendors();
foreach ($modules as $module) {
foreach ($moduleNamespaces as $namespace) {
$path = MODULES_DIR . $namespace . '/' . $module['dir'] . '/config/services.yml';
foreach ($vendors as $vendor) {
$path = MODULES_DIR . $vendor . '/' . $module['dir'] . '/config/services.yml';
if (is_file($path)) {
$loader->load($path);
}
......
......@@ -27,7 +27,7 @@ services:
system.helpers:
class: %system.helpers.fqdn%
arguments: ['@core.db', '@core.modules', @core.modules.schemaInstaller]
arguments: ['@core.db', '@core.modules', @core.modules.vendors, @core.modules.schemaInstaller]
system.validator:
class: %system.validator.fqdn%
......
......@@ -85,12 +85,12 @@ class Application extends Core\AbstractApplication
// When in updater context, also include "normal" module services
if (defined('IN_UPDATER') === true) {
$moduleNamespaces = $this->container->get('core.modules')->getModuleNamespaces();
$vendors = $this->container->get('core.modules.vendors')->getVendors();
foreach ($moduleNamespaces as $namespace) {
$namespaceModules = array_diff(scandir(MODULES_DIR . $namespace . '/'), ['.', '..']);
foreach ($vendors as $vendor) {
$namespaceModules = array_diff(scandir(MODULES_DIR . $vendor . '/'), ['.', '..']);
foreach ($namespaceModules as $module) {
$path = MODULES_DIR . $namespace . '/' . $module . '/config/services.yml';
$path = MODULES_DIR . $vendor . '/' . $module . '/config/services.yml';
if (is_file($path) === true) {
$loader->load($path);
}
......
......@@ -20,21 +20,28 @@ class Index extends Core\Modules\Controller
* @var \ACP3\Core\Modules\SchemaUpdater
*/
protected $schemaUpdater;
/**
* @var \ACP3\Core\Modules\Vendors
*/
protected $vendors;
/**
* @param \ACP3\Installer\Core\Modules\Controller\Context $context
* @param \ACP3\Core\Modules $modules
* @param \ACP3\Core\Modules\Vendors $vendors
* @param \ACP3\Core\Modules\SchemaUpdater $schemaUpdater
*/
public function __construct(
Core\Modules\Controller\Context $context,
Modules $modules,
Modules\Vendors $vendors,
Modules\SchemaUpdater $schemaUpdater
)
{
parent::__construct($context);
$this->modules = $modules;
$this->vendors = $vendors;
$this->schemaUpdater = $schemaUpdater;
}
......@@ -56,8 +63,8 @@ class Index extends Core\Modules\Controller
}
// ...danach die Restlichen
foreach ($this->modules->getModuleNamespaces() as $namespace) {
$modules = array_diff(scandir(MODULES_DIR . $namespace . '/'), ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd']);
foreach ($this->vendors->getVendors() as $vendor) {
$modules = array_diff(scandir(MODULES_DIR . $vendor . '/'), ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd']);
foreach ($modules as $module) {
if (in_array(strtolower($module), $coreModules) === false) {
$results[$module] = $this->_returnModuleUpdateResult($module);
......
services:
update.controller.install.index:
class: ACP3\Installer\Modules\Update\Controller\Index
arguments: ['@core.context.install', '@core.modules', @core.modules.schemaUpdater]
arguments: ['@core.context.install', '@core.modules', @core.modules.vendors, @core.modules.schemaUpdater]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment