Skip to content

Commit 42c8251

Browse files
committed
Fixing undefined index #131
Fixing undefined index error if associative config array isn't properly filled #131
1 parent 881c742 commit 42c8251

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
1414
### Affected Classes
1515
- NaN
1616

17+
## [1.2.5] - 2018-07-30
18+
### Fixed
19+
- Fixing undefined index error if associative config array isn't properly filled #131
20+
21+
### Affected Classes
22+
- [LaravelServiceProvider::class](src/IMAP/Providers/LaravelServiceProvider.php)
23+
1724
## [1.2.4] - 2018-07-26
1825
### Fixed
1926
- fetch_flags default set to true on all methods

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Laravel IMAP is an easy way to integrate the native php imap library into your *
4848
1) Install the php-imap library if it isn't already installed:
4949

5050
``` shell
51-
sudo apt-get install php*-imap && sudo apache2ctl graceful
51+
sudo apt-get install php*-imap php*-mbstring php*-mcrypt && sudo apache2ctl graceful
5252
```
5353

5454
You might also want to check `phpinfo()` if the extension is enabled.

src/IMAP/Providers/LaravelServiceProvider.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private function setVendorConfig(){
6666
$vendor_config = require $path;
6767
$config = $this->app['config']->get($config_key, []);
6868

69-
$this->app['config']->set($config_key, array_merge($vendor_config, $config));
69+
$this->app['config']->set($config_key, $this->array_merge_recursive_distinct($vendor_config, $config));
7070

7171
$config = $this->app['config']->get($config_key);
7272

@@ -90,4 +90,56 @@ private function setVendorConfig(){
9090

9191
$this->app['config']->set($config_key, $config);
9292
}
93+
94+
/**
95+
* Marge arrays recursively and distinct
96+
*
97+
* Merges any number of arrays / parameters recursively, replacing
98+
* entries with string keys with values from latter arrays.
99+
* If the entry or the next value to be assigned is an array, then it
100+
* automatically treats both arguments as an array.
101+
* Numeric entries are appended, not replaced, but only if they are
102+
* unique
103+
*
104+
* @param array $array1 Initial array to merge.
105+
* @param array ... Variable list of arrays to recursively merge.
106+
*
107+
* @return array|mixed
108+
*
109+
* @link http://www.php.net/manual/en/function.array-merge-recursive.php#96201
110+
* @author Mark Roduner <[email protected]>
111+
*/
112+
private function array_merge_recursive_distinct() {
113+
114+
$arrays = func_get_args();
115+
$base = array_shift($arrays);
116+
117+
if(!is_array($base)) $base = empty($base) ? array() : array($base);
118+
119+
foreach($arrays as $append) {
120+
121+
if(!is_array($append)) $append = array($append);
122+
123+
foreach($append as $key => $value) {
124+
125+
if(!array_key_exists($key, $base) and !is_numeric($key)) {
126+
$base[$key] = $append[$key];
127+
continue;
128+
}
129+
130+
if(is_array($value) or is_array($base[$key])) {
131+
$base[$key] = $this->array_merge_recursive_distinct($base[$key], $append[$key]);
132+
} else if(is_numeric($key)) {
133+
if(!in_array($value, $base)) $base[] = $value;
134+
} else {
135+
$base[$key] = $value;
136+
}
137+
138+
}
139+
140+
}
141+
142+
return $base;
143+
}
144+
93145
}

0 commit comments

Comments
 (0)