Skip to content

Commit

Permalink
Fixing undefined index #131
Browse files Browse the repository at this point in the history
Fixing undefined index error if associative config array isn't properly filled #131
  • Loading branch information
Webklex committed Jul 30, 2018
1 parent 881c742 commit 42c8251
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
### Affected Classes
- NaN

## [1.2.5] - 2018-07-30
### Fixed
- Fixing undefined index error if associative config array isn't properly filled #131

### Affected Classes
- [LaravelServiceProvider::class](src/IMAP/Providers/LaravelServiceProvider.php)

## [1.2.4] - 2018-07-26
### Fixed
- fetch_flags default set to true on all methods
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Laravel IMAP is an easy way to integrate the native php imap library into your *
1) Install the php-imap library if it isn't already installed:

``` shell
sudo apt-get install php*-imap && sudo apache2ctl graceful
sudo apt-get install php*-imap php*-mbstring php*-mcrypt && sudo apache2ctl graceful
```

You might also want to check `phpinfo()` if the extension is enabled.
Expand Down
54 changes: 53 additions & 1 deletion src/IMAP/Providers/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private function setVendorConfig(){
$vendor_config = require $path;
$config = $this->app['config']->get($config_key, []);

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

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

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

$this->app['config']->set($config_key, $config);
}

/**
* Marge arrays recursively and distinct
*
* Merges any number of arrays / parameters recursively, replacing
* entries with string keys with values from latter arrays.
* If the entry or the next value to be assigned is an array, then it
* automatically treats both arguments as an array.
* Numeric entries are appended, not replaced, but only if they are
* unique
*
* @param array $array1 Initial array to merge.
* @param array ... Variable list of arrays to recursively merge.
*
* @return array|mixed
*
* @link http://www.php.net/manual/en/function.array-merge-recursive.php#96201
* @author Mark Roduner <[email protected]>
*/
private function array_merge_recursive_distinct() {

$arrays = func_get_args();
$base = array_shift($arrays);

if(!is_array($base)) $base = empty($base) ? array() : array($base);

foreach($arrays as $append) {

if(!is_array($append)) $append = array($append);

foreach($append as $key => $value) {

if(!array_key_exists($key, $base) and !is_numeric($key)) {
$base[$key] = $append[$key];
continue;
}

if(is_array($value) or is_array($base[$key])) {
$base[$key] = $this->array_merge_recursive_distinct($base[$key], $append[$key]);
} else if(is_numeric($key)) {
if(!in_array($value, $base)) $base[] = $value;
} else {
$base[$key] = $value;
}

}

}

return $base;
}

}

0 comments on commit 42c8251

Please sign in to comment.