/** * Merge two arrays * * For duplicate keys, the following is done: * - Nested arrays are recursively merged * - Items in $array2 with INTEGER keys are appended * - Items in $array2 with STRING keys overwrite current values * * @param array $array1 * @param array $array2 * @return array */ function utils_arrayMergeRecursive(array $array1, array $array2) { foreach ($array2 as $key => $value) { if (array_key_exists($key, $array1)) { if (is_int($key)) { $array1[] = $value; } elseif (is_array($value) && is_array($array1[$key])) { $array1[$key] = utils_arrayMergeRecursive($array1[$key], $value); } else { $array1[$key] = $value; } } else { $array1[$key] = $value; } } return $array1; }
/** * Return plugin configuration from file * * @throws iMSCP_Plugin_Exception in case plugin configuration file is not readable * @return array */ public final function getConfigFromFile() { $this->isLoadedConfig = false; $pluginName = $this->getName(); $file = $this->getPluginManager()->pluginGetDirectory() . "/{$pluginName}/config.php"; $config = array(); if (@file_exists($file)) { if (@is_readable($file)) { $config = (include $file); iMSCP_Utility_OpcodeCache::clearAllActive($file); // Be sure to load newest version on next call $file = PERSISTENT_PATH . "/plugins/{$pluginName}.php"; if (@is_readable($file)) { $localConfig = (include $file); iMSCP_Utility_OpcodeCache::clearAllActive($file); // Be sure to load newest version on next call if (array_key_exists('__REMOVE__', $localConfig) && is_array($localConfig['__REMOVE__'])) { $config = utils_arrayDiffRecursive($config, $localConfig['__REMOVE__']); if (array_key_exists('__OVERRIDE__', $localConfig) && is_array($localConfig['__OVERRIDE__'])) { $config = utils_arrayMergeRecursive($config, $localConfig['__OVERRIDE__']); } } } } else { throw new iMSCP_Plugin_Exception(tr('Unable to read the plugin %s file. Please check file permissions', $file)); } } return $config; }