Exemplo n.º 1
0
 /**
  * Saves the data changes to the data store.
  *
  * @param Enlight_Config $config
  * @param bool $forceWrite
  * @return Enlight_Config_Adapter_File
  */
 public function write(Enlight_Config $config, $forceWrite = false)
 {
     if (!$this->_allowWrites) {
         return $this;
     }
     $section = $config->getSection();
     $filename = $this->getFilename($config->getName());
     if (!$config->isDirty() && !$forceWrite) {
         return $this;
     }
     if (!empty($section)) {
         $base = $this->readBase($filename);
         if (is_array($section)) {
             foreach (array_reverse($section) as $sectionName) {
                 if (!isset($base->{$sectionName})) {
                     $base->{$sectionName} = array();
                 }
             }
             $sectionName = $extendingSection = array_shift($section);
             foreach ($section as $extendedSection) {
                 $base->setExtend($extendingSection, $extendedSection);
                 $extendingSection = $extendedSection;
             }
         } else {
             $sectionName = (string) $section;
         }
         $base->{$sectionName} = $config;
     } else {
         $base = $config;
     }
     $dir = dirname($filename);
     if (!file_exists($dir) || !is_writeable($dir)) {
         $old = umask(0);
         mkdir($dir, 0777, true);
         chmod($dir, 0777);
         umask($old);
     }
     if (!is_writeable($dir)) {
         return $this;
     }
     $writer = 'Enlight_Config_Writer_' . ucfirst($this->_configType);
     /** @var $writer Enlight_Config_Writer_Writer */
     $writer = new $writer(array('config' => $base, 'filename' => $filename));
     $writer->write();
     return $this;
 }