Skip to content

Commit 24b61ed

Browse files
author
Alex Dong
committed
Imporove Helper
1 parent 948305c commit 24b61ed

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Helper/Data.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
/**
33
* @Author: nguyen
44
* @Date: 2020-02-12 14:01:01
5-
* @Last Modified by: Alex Dong
6-
* @Last Modified time: 2020-03-15 15:38:55
5+
* @Last Modified by: nguyen
6+
* @Last Modified time: 2020-03-15 18:51:36
77
*/
88

99
namespace Magepow\Lazyload\Helper;
1010

1111
class Data extends \Magento\Framework\App\Helper\AbstractHelper
1212
{
13-
const CONFIG_MODULE = 'magepow_lazyload';
14-
1513
/**
1614
* @var string
1715
*/
@@ -28,8 +26,8 @@ public function __construct(
2826
)
2927
{
3028
parent::__construct($context);
31-
$this->pageConfig = $pageConfig;
32-
$this->configModule = $this->getConfig(self::CONFIG_MODULE);
29+
$this->pageConfig = $pageConfig;
30+
$this->configModule = $this->getConfig(strtolower($this->_getModuleName()));
3331
}
3432

3533
public function getConfig($cfg='')
@@ -40,10 +38,19 @@ public function getConfig($cfg='')
4038

4139
public function getConfigModule($cfg='', $value=null)
4240
{
43-
$config = explode('/', $cfg);
44-
if( !$cfg ) $value = $this->configModule;
45-
foreach ($config as $key) {
46-
if(isset($value[$key])) $value = $value[$key];
41+
$values = $this->configModule;
42+
if( !$cfg ) return $values;
43+
$config = explode('/', $cfg);
44+
$end = count($config) - 1;
45+
foreach ($config as $key => $vl) {
46+
if( isset($values[$vl]) ){
47+
if( $key == $end ) {
48+
$value = $values[$vl];
49+
}else {
50+
$values = $values[$vl];
51+
}
52+
}
53+
4754
}
4855
return $value;
4956
}

0 commit comments

Comments
 (0)