diff options
Diffstat (limited to 'libs/Zend/Config/Writer/Ini.php')
-rw-r--r-- | libs/Zend/Config/Writer/Ini.php | 137 |
1 files changed, 44 insertions, 93 deletions
diff --git a/libs/Zend/Config/Writer/Ini.php b/libs/Zend/Config/Writer/Ini.php index ea65ca87c3..163c95e216 100644 --- a/libs/Zend/Config/Writer/Ini.php +++ b/libs/Zend/Config/Writer/Ini.php @@ -14,123 +14,81 @@ * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ini.php 16201 2009-06-21 18:51:15Z thomas $ + * @version $Id: Ini.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Config_Writer */ -require_once 'Zend/Config/Writer.php'; +// require_once 'Zend/Config/Writer/FileAbstract.php'; /** * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Config_Writer_Ini extends Zend_Config_Writer +class Zend_Config_Writer_Ini extends Zend_Config_Writer_FileAbstract { /** - * Filename to write to - * - * @var string - */ - protected $_filename = null; - - /** - * Wether to exclusively lock the file or not - * - * @var boolean - */ - protected $_exclusiveLock = false; - - /** * String that separates nesting levels of configuration data identifiers * * @var string */ protected $_nestSeparator = '.'; - + /** - * Set the target filename + * If true the ini string is rendered in the global namespace without sections. * - * @param string $filename - * @return Zend_Config_Writer_Xml + * @var bool */ - public function setFilename($filename) - { - $this->_filename = $filename; - - return $this; - } - + protected $_renderWithoutSections = false; + /** - * Set wether to exclusively lock the file or not + * Set the nest separator * - * @param boolean $exclusiveLock - * @return Zend_Config_Writer_Array + * @param string $filename + * @return Zend_Config_Writer_Ini */ - public function setExclusiveLock($exclusiveLock) + public function setNestSeparator($separator) { - $this->_exclusiveLock = $exclusiveLock; - + $this->_nestSeparator = $separator; + return $this; } - + /** - * Set the nest separator + * Set if rendering should occour without sections or not. * - * @param string $filename + * If set to true, the INI file is rendered without sections completely + * into the global namespace of the INI file. + * + * @param bool $withoutSections * @return Zend_Config_Writer_Ini */ - public function setNestSeparator($separator) + public function setRenderWithoutSections($withoutSections=true) { - $this->_nestSeparator = $separator; - + $this->_renderWithoutSections = (bool)$withoutSections; return $this; } - + /** - * Defined by Zend_Config_Writer + * Render a Zend_Config into a INI config string. * - * @param string $filename - * @param Zend_Config $config - * @param boolean $exclusiveLock - * @throws Zend_Config_Exception When filename was not set - * @throws Zend_Config_Exception When filename is not writable - * @return void + * @since 1.10 + * @return string */ - public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null) + public function render() { - if ($filename !== null) { - $this->setFilename($filename); - } - - if ($config !== null) { - $this->setConfig($config); - } - - if ($exclusiveLock !== null) { - $this->setExclusiveLock($exclusiveLock); - } - - if ($this->_filename === null) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No filename was set'); - } - - if ($this->_config === null) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No config was set'); - } - $iniString = ''; $extends = $this->_config->getExtends(); $sectionName = $this->_config->getSectionName(); - - if (is_string($sectionName)) { + + if($this->_renderWithoutSections == true) { + $iniString .= $this->_addBranch($this->_config); + } else if (is_string($sectionName)) { $iniString .= '[' . $sectionName . ']' . "\n" . $this->_addBranch($this->_config) . "\n"; @@ -145,28 +103,17 @@ class Zend_Config_Writer_Ini extends Zend_Config_Writer if (isset($extends[$sectionName])) { $sectionName .= ' : ' . $extends[$sectionName]; } - + $iniString .= '[' . $sectionName . ']' . "\n" . $this->_addBranch($data) . "\n"; } } } - - $flags = 0; - - if ($this->_exclusiveLock) { - $flags |= LOCK_EX; - } - - $result = @file_put_contents($this->_filename, $iniString, $flags); - if ($result === false) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"'); - } + return $iniString; } - + /** * Add a branch to an INI string recursively * @@ -179,7 +126,7 @@ class Zend_Config_Writer_Ini extends Zend_Config_Writer foreach ($config as $key => $value) { $group = array_merge($parents, array($key)); - + if ($value instanceof Zend_Config) { $iniString .= $this->_addBranch($value, $group); } else { @@ -189,10 +136,10 @@ class Zend_Config_Writer_Ini extends Zend_Config_Writer . "\n"; } } - + return $iniString; } - + /** * Prepare a value for INI * @@ -205,8 +152,12 @@ class Zend_Config_Writer_Ini extends Zend_Config_Writer return $value; } elseif (is_bool($value)) { return ($value ? 'true' : 'false'); + } elseif (strpos($value, '"') === false) { + return '"' . $value . '"'; } else { - return '"' . addslashes($value) . '"'; + /** @see Zend_Config_Exception */ + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Value can not contain double quotes "'); } } } |