Skip to content

Commit 76f6804

Browse files
committed
improved array to object conversion in ConfigLoader by using json_encode/decode trick
updated CHANGELOG for 1.0.3 release
1 parent fb3695a commit 76f6804

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## 1.0.3 (2019-10-14)
4+
5+
- Fix for PHP setup where extensions are not compiled-in, loaded as modules. Standard php.ini is now loaded.
6+
- Code style: replaced traditional syntax array literals
7+
- Code smells: fixes various minor code smells
8+
- Pushed minimum required PHP version to 7.2
9+
- Improved array to object conversion in ConfigLoader by using json_encode/decode trick.
10+
311
## 1.0.2 (2015-11-04)
412

513
- workaround for duplicate headers that should not appear more than once (@onlime)

app/ConfigLoader.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct()
3939
}
4040
}
4141

42-
$this->_conf = $this->_arrayToObject($config);
42+
$this->_conf = $this->arrayToObject($config);
4343

4444
$this->init();
4545
}
@@ -70,20 +70,10 @@ public function getConfig()
7070
*
7171
* @param array $arr
7272
* @return StdClass
73-
* @link http://onli.me/array2object
73+
* @link https://stackoverflow.com/a/9185337
7474
*/
75-
protected function _arrayToObject(array $arr)
75+
protected function arrayToObject(array $arr)
7676
{
77-
if (is_array($arr)) {
78-
/*
79-
* Return array converted to object
80-
* Using __FUNCTION__ (Magic constant)
81-
* for recursive call
82-
*/
83-
return (object)array_map([$this, __FUNCTION__], $arr);
84-
} else {
85-
// Return object
86-
return $arr;
87-
}
77+
return json_decode(json_encode($arr));
8878
}
8979
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"php": ">=7.2.0",
2020
"ext-mbstring": "*",
2121
"ext-pdo": "*",
22-
"ext-imap": "*"
22+
"ext-imap": "*",
23+
"ext-json": "*"
2324
}
2425
}

0 commit comments

Comments
 (0)