Skip to content

Commit

Permalink
version 0.0.3
Browse files Browse the repository at this point in the history
Add profiling, get rid of notices, add caching
  • Loading branch information
leofonic committed Oct 22, 2018
1 parent ae2dd5c commit 9bb04e2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
44 changes: 28 additions & 16 deletions core/autoregister_namespaces_oxconfig.php
Expand Up @@ -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;
}
}
}
}
Expand All @@ -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');
}
}
5 changes: 4 additions & 1 deletion metadata.php
Expand Up @@ -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'),
),
);
8 changes: 8 additions & 0 deletions views/admin/de/module_options.php
@@ -0,0 +1,8 @@
<?php
$sLangName = "Deutsch";
$aLang = array(
'charset' => 'UTF-8',

'SHOP_MODULE_GROUP_zwar_settings' => 'Einstellungen',
'SHOP_MODULE_blZwarProductionMode' => 'Production Mode (Caching aktiv)',
);
8 changes: 8 additions & 0 deletions views/admin/en/module_options.php
@@ -0,0 +1,8 @@
<?php
$sLangName = "English";
$aLang = array(
'charset' => 'UTF-8',

'SHOP_MODULE_GROUP_zwar_settings' => 'Settings',
'SHOP_MODULE_blZwarProductionMode' => 'Production Mode (Caching enabled)',
);

0 comments on commit 9bb04e2

Please sign in to comment.