Esempio n. 1
0
 public function setSectionVars($sectionVars, $area, $type, $opts = 0)
 {
     if ($type instanceof Module) {
         $key = $type->getConfigModule() . '-' . $area;
     } else {
         $key = $type . '-' . $area;
     }
     if ($config = $this->getConfig($area, $type, $opts)) {
         $config->setSectionVars($sectionVars);
         $config->saveConfig();
         unset($this->configs[$key]);
         Kurogo::deleteCache('config-' . $key);
     }
 }
 public function saveConfig(Config $config)
 {
     $key = sprintf("%s-%s", $config->getType(), $config->getArea());
     if (!($file = $config->getFile('base'))) {
         throw new KurogoConfigurationException("Unable to load base file for " . $config->getType() . '-' . $config->getArea());
     }
     if (count($config->getFiles()) > 1) {
         KurogoDebug::Debug($config, true);
         throw new KurogoConfigurationException("Safety net. File will not be saved because it was loaded with extra files. The code is probably wrong");
     }
     $data = $config->getSaveData();
     if (!is_writable($file)) {
         throw new KurogoConfigurationException("Cannot save config file: {$file} Check permissions");
     }
     file_put_contents($file, $data);
     unset($this->configs[$key]);
     Kurogo::deleteCache('config-' . $key);
     return true;
 }
Esempio n. 3
0
 public function saveFile()
 {
     if (!is_writable($this->filepath)) {
         throw new KurogoConfigurationException("Cannot save config file: {$this->filepath} Check permissions");
     } elseif ($this->localFile) {
         throw new KurogoConfigurationException("Safety net. File will not be saved because it was loaded and has local overrides. The code is probably wrong");
     }
     $string = array();
     foreach ($this->sectionVars as $section => $sectionData) {
         if (is_array($sectionData)) {
             if (count($string) > 0) {
                 $string[] = '';
             }
             if (isset($sectionData[0])) {
                 foreach ($sectionData as $value) {
                     $string[] = sprintf("%s[] = %s", $section, $this->saveValue($value));
                 }
                 $sectionData = array();
             } elseif ($section !== 'No Section') {
                 $string[] = sprintf("[%s]", $section);
             }
             foreach ($sectionData as $var => $value) {
                 if (is_scalar($value)) {
                     $string[] = sprintf('%s = %s', $var, $this->saveValue($value));
                 } elseif (isset($value[0])) {
                     foreach ($value as $_value) {
                         $string[] = sprintf("%s[] = %s", $var, $this->saveValue($_value));
                     }
                 } else {
                     Kurogo::log(LOG_WARNING, "Error parsing non scalar value for {$var} in " . $this->filepath, 'config');
                 }
             }
         } else {
             $string[] = sprintf('%s = %s', $section, $this->saveValue($sectionData));
         }
     }
     file_put_contents($this->filepath, implode(PHP_EOL, $string));
     $cacheKey = $this->cacheKeyForFile($this->filepath);
     Kurogo::deleteCache($cacheKey);
     return true;
 }