mergeRecursiveDistinct() public static method

Use that instead or the smarter {@see \replaceRecursive}.
Deprecation: since 3.3, to be removed in 4.0.
public static mergeRecursiveDistinct ( array &$array1, array &$array2 ) : array
$array1 array
$array2 array
return array
Exemplo n.º 1
0
 /**
  * Update packages.
  *
  * @param  $packages array Indexed array of package names to update
  * @param  $options  array [Optional] changed option set
  *
  * @throws \Bolt\Exception\PackageManagerException
  *
  * @return int 0 on success or a positive error code on failure
  */
 public function execute(array $packages = [], array $options = [])
 {
     /** @var $composer \Composer\Composer */
     $composer = $this->getComposer();
     $io = $this->getIO();
     $packageManagerOptions = $this->app['extend.action.options'];
     // Handle passed in options
     if (!empty($options)) {
         $options = Arr::mergeRecursiveDistinct($packageManagerOptions, $options);
     } else {
         $options = $packageManagerOptions;
     }
     $install = Installer::create($io, $composer);
     $config = $composer->getConfig();
     $optimize = $config->get('optimize-autoloader');
     // Set preferred install method
     $prefer = $this->getPreferedTarget($config->get('preferred-install'));
     try {
         $install->setDryRun($options['dryrun'])->setVerbose($options['verbose'])->setPreferSource($prefer['source'])->setPreferDist($prefer['dist'])->setDevMode(!$options['nodev'])->setDumpAutoloader(!$options['noautoloader'])->setRunScripts(!$options['noscripts'])->setOptimizeAutoloader($optimize)->setUpdate(true)->setUpdateWhitelist($packages)->setWhitelistDependencies($options['withdependencies'])->setIgnorePlatformRequirements($options['ignoreplatformreqs'])->setPreferStable($options['preferstable'])->setPreferLowest($options['preferlowest'])->disablePlugins();
         return $install->run();
     } catch (\Exception $e) {
         $msg = __CLASS__ . '::' . __FUNCTION__ . ' recieved an error from Composer: ' . $e->getMessage() . ' in ' . $e->getFile() . '::' . $e->getLine();
         $this->app['logger.system']->critical($msg, ['event' => 'exception', 'exception' => $e]);
         throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
     }
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @param array $config
  */
 public function __construct(array $config, $rooturl)
 {
     $this->rooturl = $rooturl;
     $default = $this->getDefaultConfig();
     $this->config = Arr::mergeRecursiveDistinct($default, $config);
     $this->setupProviderConfig();
 }
Exemplo n.º 3
0
 private function loadThemeConfig(Config $config, $theme, $childTheme)
 {
     $themePath = $this->app['resources']->getPath('themebase') . '/' . $theme;
     if (file_exists($themePath)) {
         $configFile = $themePath . '/config.yml';
         // insert parent path right after child path.
         $twigPath = $config->get('twigpath');
         if ($twigPath) {
             $childThemePath = $this->app['resources']->getPath('themebase') . '/' . $childTheme;
             $key = array_search($childThemePath, $twigPath);
             if ($key !== false) {
                 array_splice($twigPath, $key, 1, array($childThemePath, $themePath));
             }
             $config->set('twigpath', $twigPath);
         }
         if (file_exists($configFile)) {
             $themeConfig = self::mergeConfigFile($configFile);
             if ($themeConfig) {
                 // load parent theme config, but without overwriting, because child prevails
                 $config->set('theme', Arr::mergeRecursiveDistinct($themeConfig, $config->get('theme')));
                 // multiple levels allowed
                 if (!empty($themeConfig['parent'])) {
                     $this->loadThemeConfig($config, $themeConfig['parent'], $theme);
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Merge in a yaml file to the config.
  *
  * @param YamlFile $file
  */
 private function addConfig(YamlFile $file)
 {
     $app = $this->getContainer();
     try {
         $newConfig = $file->parse();
     } catch (RuntimeException $e) {
         $app['logger.flash']->error($e->getMessage());
         $app['logger.system']->error($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
         throw $e;
     }
     if (is_array($newConfig)) {
         $this->config = Arr::mergeRecursiveDistinct($this->config, $newConfig);
     }
 }
Exemplo n.º 5
0
 public function testMergeRecusrsiveDistinct()
 {
     $arr1 = array('key' => 'orig value');
     $arr2 = array('key' => 'new value');
     $this->assertEquals(array('key' => 'new value'), Arr::mergeRecursiveDistinct($arr1, $arr2));
     // Needs an exclusion for accept_file_types
     $arr1 = array('accept_file_types' => 'jpg');
     $arr2 = array('accept_file_types' => 'jpg,png');
     Arr::mergeRecursiveDistinct($arr1, $arr2);
     $this->assertEquals(array('accept_file_types' => 'jpg'), $arr1);
     // Test Recusrsion
     $arr1 = array('key' => array('test' => 'new value'));
     $arr2 = array('key' => array('test' => 'nested new value'));
     $this->assertEquals(array('key' => array('test' => 'nested new value')), Arr::mergeRecursiveDistinct($arr1, $arr2));
 }
Exemplo n.º 6
0
 public function testLegacyMergeRecursiveDistinct()
 {
     $arr1 = ['key' => 'orig value'];
     $arr2 = ['key' => 'new value'];
     $this->assertEquals(['key' => 'new value'], Arr::mergeRecursiveDistinct($arr1, $arr2));
     // Needs an exclusion for accept_file_types
     $arr1 = ['accept_file_types' => ['jpg']];
     $arr2 = ['accept_file_types' => ['jpg', 'png']];
     $actual = Arr::mergeRecursiveDistinct($arr1, $arr2);
     $this->assertEquals(['accept_file_types' => ['jpg', 'png']], $actual);
     // Test Recursion
     $arr1 = ['key' => ['test' => 'new value']];
     $arr2 = ['key' => ['test' => 'nested new value']];
     $this->assertEquals(['key' => ['test' => 'nested new value']], Arr::mergeRecursiveDistinct($arr1, $arr2));
     // This is why this method is deprecated:
     $arr1 = ['key' => ['foo', 'bar']];
     $arr2 = ['key' => ['baz']];
     $actual = Arr::mergeRecursiveDistinct($arr1, $arr2);
     $this->assertEquals(['key' => ['baz', 'bar']], $actual);
 }
Exemplo n.º 7
0
 /**
  * Read and parse the config.yml and config_local.yml configuration files.
  *
  * @return array
  */
 protected function parseGeneral()
 {
     // Read the config and merge it. (note: We use temp variables to prevent
     // "Only variables should be passed by reference")
     $tempconfig = $this->parseConfigYaml('config.yml');
     $tempconfiglocal = $this->parseConfigYaml('config_local.yml');
     $general = Arr::mergeRecursiveDistinct($tempconfig, $tempconfiglocal);
     // Make sure old settings for 'contentsCss' are still picked up correctly
     if (isset($general['wysiwyg']['ck']['contentsCss'])) {
         $general['wysiwyg']['ck']['contentsCss'] = [1 => $general['wysiwyg']['ck']['contentsCss']];
     }
     // Make sure old settings for 'accept_file_types' are not still picked up. Before 1.5.4 we used to store them
     // as a regex-like string, and we switched to an array. If we find the old style, fall back to the defaults.
     if (isset($general['accept_file_types']) && !is_array($general['accept_file_types'])) {
         unset($general['accept_file_types']);
     }
     // Merge the array with the defaults. Setting the required values that aren't already set.
     $general = Arr::mergeRecursiveDistinct($this->defaultConfig, $general);
     // Make sure the cookie_domain for the sessions is set properly.
     if (empty($general['cookies_domain'])) {
         if (isset($_SERVER['HTTP_HOST'])) {
             $hostname = $_SERVER['HTTP_HOST'];
         } elseif (isset($_SERVER['SERVER_NAME'])) {
             $hostname = $_SERVER['SERVER_NAME'];
         } else {
             $hostname = '';
         }
         // Don't set the domain for a cookie on a "TLD" - like 'localhost', or if the server_name is an IP-address
         if (strpos($hostname, '.') > 0 && preg_match('/[a-z0-9]/i', $hostname)) {
             if (preg_match('/^www[0-9]*./', $hostname)) {
                 $general['cookies_domain'] = '.' . preg_replace('/^www[0-9]*./', '', $hostname);
             } else {
                 $general['cookies_domain'] = '.' . $hostname;
             }
             // Make sure we don't have consecutive '.'-s in the cookies_domain.
             $general['cookies_domain'] = str_replace('..', '.', $general['cookies_domain']);
         } else {
             $general['cookies_domain'] = '';
         }
     }
     // Make sure Bolt's mount point is OK:
     $general['branding']['path'] = '/' . Str::makeSafe($general['branding']['path']);
     $general['database'] = $this->parseDatabase($general['database']);
     return $general;
 }
Exemplo n.º 8
0
 /**
  * Load and process a give config file.
  *
  * @param string $configfile Fully qualified file path
  */
 private function loadConfigFile($configfile)
 {
     $yamlparser = new Yaml\Parser();
     $newConfig = $yamlparser->parse(file_get_contents($configfile) . "\n");
     // Don't error on empty config files
     if (is_array($newConfig)) {
         $this->config = Arr::mergeRecursiveDistinct($this->config, $newConfig);
     }
 }
Exemplo n.º 9
0
 /**
  * Insert an individual Contenttype record into the database
  *
  * @param string $filename
  * @param string $contenttypeslug
  * @param array  $values
  *
  * @return boolean
  */
 private function insertRecord($filename, $contenttypeslug, array $values)
 {
     // Determine a/the slug
     $slug = isset($values['slug']) ? $values['slug'] : substr($this->app['slugify']->slugify($values['title']), 0, 127);
     if (!$this->isRecordUnique($contenttypeslug, $slug)) {
         $this->setWarning(true)->setWarningMessage("File '{$filename}' has an exiting Contenttype '{$contenttypeslug}' with the slug '{$slug}'! Skipping record.");
         return false;
     }
     // Get a status
     if (isset($values['status'])) {
         $status = $values['status'];
     } else {
         $status = $this->contenttypes[$contenttypeslug]['default_status'];
     }
     // Transform the 'publish' action to a 'published' status
     $status = $status === 'publish' ? 'published' : $status;
     // Insist on a title field
     if (!isset($values['title'])) {
         $this->setWarning(true)->setWarningMessage("File '{$filename}' has a '{$contenttypeslug}' with a missing title field! Skipping record.");
         return false;
     }
     // Set up default meta
     $meta = ['slug' => $slug, 'datecreated' => date('Y-m-d H:i:s'), 'datepublish' => $status == 'published' ? date('Y-m-d H:i:s') : null, 'ownerid' => 1];
     $values = Arr::mergeRecursiveDistinct($values, $meta);
     $record = $this->app['storage']->getEmptyContent($contenttypeslug);
     $record->setValues($values);
     if ($this->app['storage']->saveContent($record) === false) {
         $this->setWarning(true)->setWarningMessage("Failed to imported record with title: {$values['title']} from '{$filename}'! Skipping record.");
         return false;
     } else {
         $this->setNotice(true)->setNoticeMessage("Imported record with title: {$values['title']}.");
         return true;
     }
 }
Exemplo n.º 10
0
 /**
  * Make a new querystring while preserving current query parameters with the
  * option to override values.
  *
  * @param array $overrides A (key,value)-array with elements to override in
  *                         the current query string.
  * @param bool $buildQuery Returns a querystring if set to true, otherwise
  *                          returns the array with (key,value)-pairs.
  * @return mixed query parameters in either array or string form.
  *
  * @see \Bolt\Helpers\Arr::mergeRecursiveDistinct()
  */
 private function makeQueryParameters($overrides = [], $buildQuery = true)
 {
     $queryParameters = $this->request->query->all();
     // todo: (optional) cleanup. There is a default set of fields we can
     //       expect using this Extension and jsonapi. Or we could ignore
     //       them like we already do.
     // Using Bolt's Helper Arr class for merging and overriding values.
     $queryParameters = Arr::mergeRecursiveDistinct($queryParameters, $overrides);
     $queryParameters = $this->unfixBoltStorageRequest($queryParameters);
     if ($buildQuery) {
         // No need to urlencode these, afaik.
         $querystring = urldecode(http_build_query($queryParameters));
         if (!empty($querystring)) {
             $querystring = '?' . $querystring;
         }
         return $querystring;
     }
     return $queryParameters;
 }
Exemplo n.º 11
0
 /**
  * @param array $providerConfig
  *
  * @return array
  */
 private function setDefaultConfig(array $providerConfig)
 {
     $default = ['label' => ['sign_in' => null, 'associate' => null], 'keys' => ['client_id' => null, 'client_secret' => null], 'scopes' => null, 'enabled' => false];
     return Arr::mergeRecursiveDistinct($default, $providerConfig);
 }
Exemplo n.º 12
0
 /**
  * If we're using local extensions, install/require the merge plugin.
  *
  * @param array $composerJson
  *
  * @return array
  */
 private function setJsonLocal(array $composerJson)
 {
     $local = $this->app['filesystem']->getFilesystem('extensions')->getDir('local')->exists();
     if ($local === false) {
         return $composerJson;
     }
     $defaults = ['extra' => ['merge-plugin' => ['include' => ['local/*/*/composer.json']]], 'require' => ['wikimedia/composer-merge-plugin' => '^1.3']];
     $composerJson = Arr::mergeRecursiveDistinct($composerJson, $defaults);
     ksort($composerJson);
     return $composerJson;
 }
Exemplo n.º 13
0
 /**
  * merge_with_meta_yml
  */
 private function merge_with_meta_yml()
 {
     $this->metas = Arr::mergeRecursiveDistinct($this->default_settings, $this->parseConfigYaml('meta.yml'));
 }