Example #1
0
 public function testArrayDiffAssocRecursive()
 {
     $users = ['users' => [1 => ['name' => 'Charles', 'role' => 'lead developper'], 2 => ['name' => 'Eric', 'role' => 'developper']]];
     $users2 = ['users' => [1 => ['name' => 'Charles', 'role' => 'lead developper'], 2 => ['name' => 'Eric', 'role' => 'developper'], 3 => ['name' => 'Nicolas', 'role' => 'developper']]];
     $diff1 = [];
     $diff2 = ['users' => [3 => ['name' => 'Nicolas', 'role' => 'developper']]];
     $this->assertSame(Collection::array_diff_assoc_recursive($users, $users2), $diff1);
     $this->assertSame(Collection::array_diff_assoc_recursive($users2, $users), $diff2);
 }
Example #2
0
 /**
  * Add or update 'override_site' section to provided $config with difference between current config settings
  * and config default settings.
  *
  * @param Config $config the config we want to add/update its 'override_site' section
  */
 private function updateConfigOverridedSectionsForSite(Config $config)
 {
     if (false === $this->application->isStarted()) {
         throw new BBException('Application is not started, we are not able to persist multiple site config.');
     }
     $default_sections = $this->configurator->getConfigDefaultSections($config);
     $current_sections = $config->getAllRawSections();
     $sections_to_update = array_keys(Collection::array_diff_assoc_recursive($default_sections, $current_sections));
     $sections_to_update = array_unique(array_merge($sections_to_update, array_keys(Collection::array_diff_assoc_recursive($current_sections, $default_sections))));
     $override_site = $config->getRawSection('override_site') ?: array();
     $site_uid = $this->application->getSite()->getUid();
     if (false === array_key_exists($site_uid, $override_site)) {
         $override_site[$site_uid] = array();
     }
     $override_sections_site =& $override_site[$site_uid];
     foreach ($sections_to_update as $section) {
         if ('override_site' !== $section) {
             $override_sections_site[$section] = $config->getRawSection($section);
         }
     }
     $config->deleteAllSections();
     foreach ($this->configurator->getConfigDefaultSections($config) as $section_name => $section_settings) {
         $config->setSection($section_name, $section_settings);
     }
     $config->setSection('override_site', $override_site, true);
 }