/** * Test case */ public function testConfigReadBase() { $this->setExpectedException('Enlight_Config_Exception'); $adapter = new Enlight_Config_Adapter_File(array('configDir' => '/fail', 'namePrefix' => 's_', 'skipExtends' => false, 'configType' => 'ini')); $config = new Enlight_Config('test', array('adapter' => $adapter)); $config->setData(array('test' => true)); $config->write(); }
/** * Saves the Form using an Enlight_Config_Adapter to do so. * This is a rudimentary implementation and should be considered as beta * * @return Enlight_Components_Form */ public function write() { $this->_adapter->setData($this->toArray()); $this->_adapter->write(); return $this; }
/** * Reads a section from the data store. * * @param Enlight_Config $config * @return Enlight_Config_Adapter_DbTable */ public function read(Enlight_Config $config) { $name = $this->_namePrefix . $config->getName() . $this->_nameSuffix; $section = $config->getSection(); $dbTable = new Enlight_Components_Table(array('name' => $name, 'db' => $this->_db)); $select = $dbTable->select()->from($dbTable->info('name'), array($this->_nameColumn, $this->_valueColumn)); if ($section !== null && $this->_sectionColumn !== null) { if (is_array($this->_sectionColumn)) { foreach ($this->_sectionColumn as $key => $sectionColumn) { if (isset($section[$key])) { $select->where($sectionColumn . '=?', $section[$key]); } } } elseif ($this->_sectionColumn !== null) { $select->where($this->_sectionColumn . '=?', $section); } } if ($this->_valueColumn !== '*') { $data = $dbTable->getAdapter()->fetchPairs($select); } else { $data = $dbTable->getAdapter()->fetchAssoc($select); } if ($this->_automaticSerialization) { foreach ($data as $key => $value) { $data[$key] = unserialize($value); } } $config->setData($data); return $this; }
/** * Reads a section from the data store. * * @param Enlight_Config $config * @return Enlight_Config_Adapter_File */ public function read(Enlight_Config $config) { $section = $config->getSection(); $name = $this->getFilename($config->getName()); if (file_exists($name)) { $reader = 'Enlight_Config_Format_' . ucfirst($this->_configType); while (true) { try { /** @var $reader Enlight_Config_Format_Ini */ $reader = new $reader($name, $section, array('skipExtends' => $this->_skipExtends)); $config->setData($reader->toArray()); break; // Section is defect } catch (Exception $e) { if (!empty($section) && is_array($section)) { // Try next section array_shift($section); } else { $config->setData(array()); break; } } } } else { $config->setData(array()); } return $this; }
/** * Reads a section from the data store. * * @param Enlight_Config $config * @return Enlight_Config_Adapter_File */ public function read(Enlight_Config $config) { $section = $config->getSection(); $name = $this->getFilename($config->getName()); if (file_exists($name)) { $reader = 'Zend_Config_' . ucfirst($this->_configType); /** @var $reader Zend_Config */ $reader = new $reader($name, $section, array('skipExtends' => $this->_skipExtends)); $config->setData($reader->toArray()); } else { $config->setData(array()); } return $this; }
/** * Reads a section from the data store. * * @param Enlight_Config $config * @return Enlight_Config_Adapter_DbTable */ public function read(Enlight_Config $config) { $name = $this->_namePrefix . $config->getName() . $this->_nameSuffix; $section = $config->getSection(); $data = array(); $extends = $config->getExtends(); $currentSection = is_array($section) ? implode(':', $section) : $section; while ($currentSection !== null) { $data = array_merge($this->readSection($name, $currentSection), $data); $currentSection = isset($extends[$currentSection]) ? $extends[$currentSection] : null; } $config->setData($data); return $this; }
/** * Test case */ public function testConfigNamePrefix() { $dir = Enlight_TestHelper::Instance()->TestPath('TempFiles'); $adapter = new Enlight_Config_Adapter_File(array('configDir' => $dir, 'namePrefix' => 's_', 'skipExtends' => false, 'configType' => 'ini')); $config = new Enlight_Config('test', array('adapter' => $adapter)); $config->setData(array('test' => true)); $config->write(); $this->assertFileExists($dir . 's_test' . '.ini'); }