Completed
Push — master ( d72f2e...c51cfd )
by
unknown
02:08
created
assets/lib/Helpers/Config.php 1 patch
Braces   +29 added lines, -28 removed lines patch added patch discarded remove patch
@@ -4,15 +4,15 @@  discard block
 block discarded – undo
4 4
 include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php');
5 5
 require_once(MODX_BASE_PATH . "assets/snippets/DocLister/lib/jsonHelper.class.php");
6 6
 
7
-class Config
8
-{
7
+class Config
8
+{
9 9
     private $_cfg = array();
10 10
     protected $fs = null;
11 11
     protected $path = '';
12 12
 
13
-    public function __construct($cfg = array())
14
-    {
15
-        if ($cfg) {
13
+    public function __construct($cfg = array())
14
+    {
15
+        if ($cfg) {
16 16
             $this->setConfig($cfg);
17 17
         }
18 18
         $this->fs = \Helpers\FS::getInstance();
@@ -22,7 +22,8 @@  discard block
 block discarded – undo
22 22
      * @param $path
23 23
      * @return $this
24 24
      */
25
-    public function setPath($path) {
25
+    public function setPath($path)
26
+    {
26 27
         $this->path = $path;
27 28
 
28 29
         return $this;
@@ -34,21 +35,21 @@  discard block
 block discarded – undo
34 35
      * @param $name string имя конфига
35 36
      * @return array массив с настройками
36 37
      */
37
-    public function loadConfig($name)
38
-    {
38
+    public function loadConfig($name)
39
+    {
39 40
         //$this->debug->debug('Load json config: ' . $this->debug->dumpData($name), 'loadconfig', 2);
40
-        if (!is_scalar($name)) {
41
+        if (!is_scalar($name)) {
41 42
             $name = '';
42 43
         }
43 44
         $config = array();
44 45
         $name = explode(";", $name);
45
-        foreach ($name as $cfgName) {
46
+        foreach ($name as $cfgName) {
46 47
             $cfgName = explode(":", $cfgName, 2);
47
-            if (empty($cfgName[1])) {
48
+            if (empty($cfgName[1])) {
48 49
                 $cfgName[1] = 'custom';
49 50
             }
50 51
             $cfgName[1] = rtrim($cfgName[1], '/');
51
-            switch ($cfgName[1]) {
52
+            switch ($cfgName[1]) {
52 53
                 case 'custom':
53 54
                 case 'core':
54 55
                     $configFile = $this->fs->relativePath($this->path) . "/config/{$cfgName[1]}/{$cfgName[0]}.json";
@@ -58,7 +59,7 @@  discard block
 block discarded – undo
58 59
                     break;
59 60
             }
60 61
 
61
-            if ($this->fs->checkFile($configFile)) {
62
+            if ($this->fs->checkFile($configFile)) {
62 63
                 $json = file_get_contents(MODX_BASE_PATH . $configFile);
63 64
                 $config = array_merge($config, \jsonHelper::jsonDecode($json, array('assoc' => true), true));
64 65
             }
@@ -73,8 +74,8 @@  discard block
 block discarded – undo
73 74
      * Получение всего списка настроек
74 75
      * @return array
75 76
      */
76
-    public function getConfig()
77
-    {
77
+    public function getConfig()
78
+    {
78 79
         return $this->_cfg;
79 80
     }
80 81
 
@@ -83,12 +84,12 @@  discard block
 block discarded – undo
83 84
      * @param array $cfg массив настроек
84 85
      * @return int результат сохранения настроек
85 86
      */
86
-    public function setConfig($cfg, $overwrite = false)
87
-    {
88
-        if (is_array($cfg)) {
87
+    public function setConfig($cfg, $overwrite = false)
88
+    {
89
+        if (is_array($cfg)) {
89 90
             $this->_cfg = $overwrite ? $cfg : array_merge($this->_cfg, $cfg);
90 91
             $ret = count($this->_cfg);
91
-        } else {
92
+        } else {
92 93
             $ret = false;
93 94
         }
94 95
 
@@ -100,8 +101,8 @@  discard block
 block discarded – undo
100 101
      * @param null $def
101 102
      * @return mixed
102 103
      */
103
-    public function getCFGDef($name, $def = null)
104
-    {
104
+    public function getCFGDef($name, $def = null)
105
+    {
105 106
         return \APIhelpers::getkey($this->_cfg, $name, $def);
106 107
     }
107 108
 
@@ -112,21 +113,21 @@  discard block
 block discarded – undo
112 113
      * @param string $sep
113 114
      * @return array|mixed|\xNop
114 115
      */
115
-    public function loadArray($arr, $sep = ',')
116
-    {
116
+    public function loadArray($arr, $sep = ',')
117
+    {
117 118
 
118
-        if (is_scalar($arr)) {
119
+        if (is_scalar($arr)) {
119 120
             $out = \jsonHelper::jsonDecode($arr, array('assoc' => true));
120
-            if (is_null($out) && $sep) {
121
+            if (is_null($out) && $sep) {
121 122
                 $out = array_filter(explode($sep, $arr));
122
-            } else {
123
+            } else {
123 124
                 $out = array();
124 125
             }
125 126
 
126 127
             return $out;
127
-        } elseif (is_array($arr)) {
128
+        } elseif (is_array($arr)) {
128 129
             return $arr;
129
-        } else {
130
+        } else {
130 131
             return array();
131 132
         }
132 133
     }
Please login to merge, or discard this patch.