File indexing completed on 2025-03-02 05:29:14
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Config 0017 * @package Writer 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 */ 0021 0022 // require_once "Zend/Config/Writer.php"; 0023 0024 /** 0025 * Abstract File Writer 0026 * 0027 * @category Zend 0028 * @package Zend_package 0029 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0030 * @license http://framework.zend.com/license/new-bsd New BSD License 0031 * @version $Id$ 0032 */ 0033 class Zend_Config_Writer_FileAbstract extends Zend_Config_Writer 0034 { 0035 /** 0036 * Filename to write to 0037 * 0038 * @var string 0039 */ 0040 protected $_filename = null; 0041 0042 /** 0043 * Wether to exclusively lock the file or not 0044 * 0045 * @var boolean 0046 */ 0047 protected $_exclusiveLock = false; 0048 0049 /** 0050 * Set the target filename 0051 * 0052 * @param string $filename 0053 * @return Zend_Config_Writer_Array 0054 */ 0055 public function setFilename($filename) 0056 { 0057 $this->_filename = $filename; 0058 0059 return $this; 0060 } 0061 0062 /** 0063 * Set wether to exclusively lock the file or not 0064 * 0065 * @param boolean $exclusiveLock 0066 * @return Zend_Config_Writer_Array 0067 */ 0068 public function setExclusiveLock($exclusiveLock) 0069 { 0070 $this->_exclusiveLock = $exclusiveLock; 0071 0072 return $this; 0073 } 0074 0075 /** 0076 * Write configuration to file. 0077 * 0078 * @param string $filename 0079 * @param Zend_Config $config 0080 * @param bool $exclusiveLock 0081 * @return void 0082 */ 0083 public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null) 0084 { 0085 if ($filename !== null) { 0086 $this->setFilename($filename); 0087 } 0088 0089 if ($config !== null) { 0090 $this->setConfig($config); 0091 } 0092 0093 if ($exclusiveLock !== null) { 0094 $this->setExclusiveLock($exclusiveLock); 0095 } 0096 0097 if ($this->_filename === null) { 0098 // require_once 'Zend/Config/Exception.php'; 0099 throw new Zend_Config_Exception('No filename was set'); 0100 } 0101 0102 if ($this->_config === null) { 0103 // require_once 'Zend/Config/Exception.php'; 0104 throw new Zend_Config_Exception('No config was set'); 0105 } 0106 0107 $configString = $this->render(); 0108 0109 $flags = 0; 0110 0111 if ($this->_exclusiveLock) { 0112 $flags |= LOCK_EX; 0113 } 0114 0115 $result = @file_put_contents($this->_filename, $configString, $flags); 0116 0117 if ($result === false) { 0118 // require_once 'Zend/Config/Exception.php'; 0119 throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"'); 0120 } 0121 } 0122 0123 /** 0124 * Render a Zend_Config into a config file string. 0125 * 0126 * @since 1.10 0127 * @todo For 2.0 this should be redone into an abstract method. 0128 * @return string 0129 */ 0130 public function render() 0131 { 0132 return ""; 0133 } 0134 }