Esempio n. 1
0
/**
 * Compares array1 against array2 (recursively) and returns the difference
 *
 * @param array $array1 The array to compare from
 * @param array $array2 An array to compare against
 * @return array An array containing all the entries from array1 that are not present in $array2.
 */
function utils_arrayDiffRecursive(array $array1, array $array2)
{
    $diff = array();
    foreach ($array1 as $key => $value) {
        if (array_key_exists($key, $array2)) {
            if (is_array($value)) {
                $arrDiff = utils_arrayDiffRecursive($value, $array2[$key]);
                if (count($arrDiff)) {
                    $diff[$key] = $arrDiff;
                }
            } elseif ($value != $array2[$key]) {
                $diff[$key] = $value;
            }
        } else {
            $diff[$key] = $value;
        }
    }
    return $diff;
}
Esempio n. 2
0
 /**
  * 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;
 }