From 9bb04e238ebab3318e48c215f4cd424609f49472 Mon Sep 17 00:00:00 2001 From: Frank Zunderer Date: Mon, 22 Oct 2018 14:20:42 +0200 Subject: [PATCH] version 0.0.3 Add profiling, get rid of notices, add caching --- core/autoregister_namespaces_oxconfig.php | 44 ++++++++++++++--------- metadata.php | 5 ++- views/admin/de/module_options.php | 8 +++++ views/admin/en/module_options.php | 8 +++++ 4 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 views/admin/de/module_options.php create mode 100644 views/admin/en/module_options.php diff --git a/core/autoregister_namespaces_oxconfig.php b/core/autoregister_namespaces_oxconfig.php index 2f4abc8..bf711d9 100644 --- a/core/autoregister_namespaces_oxconfig.php +++ b/core/autoregister_namespaces_oxconfig.php @@ -11,23 +11,30 @@ public function init() parent::init(); //register any module namespaces that are not yet registered + startProfile('autoregister_namespaces'); + $loader = require VENDOR_PATH . 'autoload.php'; - $loadedPrefixes = $loader->getPrefixesPsr4(); - $modulePaths = $this->getConfigParam('aModulePaths'); - if (is_array($modulePaths)){ - foreach ($modulePaths as $modulePath){ - $modulesDir = $this->getModulesDir(true); - $modulePathAbsolute = $modulesDir . $modulePath; - $jsonPath = $modulePathAbsolute . '/composer.json'; - if(file_exists($jsonPath)){ - if ($json = file_get_contents($jsonPath)){ - if ($decoded = json_decode($json, true)){ - if ($prefixes = $decoded['autoload']['psr-4']){ - if (is_array($prefixes)){ - foreach ($prefixes as $prefix => $prefixPath){ - if(!$loadedPrefixes[$prefix]){ - if ($prefixPath == '../../../source/modules/' . $modulePath){ - $loader->addPsr4($prefix, $modulePathAbsolute); + $aPrefixesToLoad = oxRegistry::getUtils()->fromFileCache('zwb_autoload_namespaces'); + if ($aPrefixesToLoad === null || !$this->getConfigParam('blZwarProductionMode')){ + $loadedPrefixes = $loader->getPrefixesPsr4(); + $modulePaths = $this->getConfigParam('aModulePaths'); + $modulesDir = $this->getModulesDir(true); + $aPrefixesToLoad = array(); + if (is_array($modulePaths)){ + foreach ($modulePaths as $modulePath){ + $modulePathAbsolute = $modulesDir . $modulePath; + $jsonPath = $modulePathAbsolute . '/composer.json'; + if(file_exists($jsonPath)){ + if ($json = file_get_contents($jsonPath)){ + if ($decoded = json_decode($json, true)){ + if (isset ($decoded['autoload']) && isset($decoded['autoload']['psr-4'])){ + $prefixes = $decoded['autoload']['psr-4']; + if (is_array($prefixes)){ + foreach ($prefixes as $prefix => $prefixPath){ + if(!isset($loadedPrefixes[$prefix])){ + if ($prefixPath == '../../../source/modules/' . $modulePath){ + $aPrefixesToLoad[$prefix] = $modulePathAbsolute; + } } } } @@ -37,6 +44,11 @@ public function init() } } } + oxRegistry::getUtils()->toFileCache('zwb_autoload_namespaces', $aPrefixesToLoad); + } + foreach ($aPrefixesToLoad as $prefix => $modulePathAbsolute){ + $loader->addPsr4($prefix, $modulePathAbsolute); } + stopProfile('autoregister_namespaces'); } } \ No newline at end of file diff --git a/metadata.php b/metadata.php index 66ca5d7..9e885ba 100644 --- a/metadata.php +++ b/metadata.php @@ -8,11 +8,14 @@ 'de'=>'', 'en'=>'', ), - 'version' => '0.0.1', + 'version' => '0.0.3', 'url' => 'http://zunderweb.de', 'email' => 'info@zunderweb.de', 'author' => 'Zunderweb', 'extend' => array( 'oxconfig' => 'zunderweb/autoregister-namespaces/core/autoregister_namespaces_oxconfig', ), + 'settings' => array( + array('group' => 'zwar_settings', 'name' => 'blZwarProductionMode', 'type' => 'bool', 'value' => '0'), + ), ); diff --git a/views/admin/de/module_options.php b/views/admin/de/module_options.php new file mode 100644 index 0000000..2e382c8 --- /dev/null +++ b/views/admin/de/module_options.php @@ -0,0 +1,8 @@ + 'UTF-8', + +'SHOP_MODULE_GROUP_zwar_settings' => 'Einstellungen', +'SHOP_MODULE_blZwarProductionMode' => 'Production Mode (Caching aktiv)', +); diff --git a/views/admin/en/module_options.php b/views/admin/en/module_options.php new file mode 100644 index 0000000..3a1e751 --- /dev/null +++ b/views/admin/en/module_options.php @@ -0,0 +1,8 @@ + 'UTF-8', + +'SHOP_MODULE_GROUP_zwar_settings' => 'Settings', +'SHOP_MODULE_blZwarProductionMode' => 'Production Mode (Caching enabled)', +); \ No newline at end of file