Example #1
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);
 }
 public function getRelativeUrl($uri)
 {
     $url = $uri;
     if ($this->application->isStarted() && null !== $this->application->getRequest()) {
         $request = $this->application->getRequest();
         $baseurl = str_replace('\\', '/', $request->getSchemeAndHttpHost() . dirname($request->getBaseUrl()));
         $url = str_replace($baseurl, '', $uri);
         if (false !== ($ext = strrpos($url, '.'))) {
             $url = substr($url, 0, $ext);
         }
         if ('/' != substr($url, 0, 1)) {
             $url = '/' . $url;
         }
     }
     return $url;
 }