[zzoss-cvs] packages/com.zzoss.file.replace.lib Replace.php,NONE,1.1 package.xml,NONE,1.1
Status: Alpha
Brought to you by:
czonsius
From: Sandro Z. <or...@us...> - 2004-04-13 07:51:56
|
Update of /cvsroot/zzoss/packages/com.zzoss.file.replace.lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26548/com.zzoss.file.replace.lib Added Files: Replace.php package.xml Log Message: renamed 'com.zzoss.filereplace.lib' to 'com.zzoss.file.replace.lib' --- NEW FILE: Replace.php --- <?php /* Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** @version $Id: Replace.php,v 1.1 2004/04/13 07:38:00 ordnas Exp $ @copyright Copyright © 2001-2004 ZZ/OSS GbR, http://www.zzoss.com @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License */ /** * Replaces characters in a file * * @version 1 * @author Sandro Zic <san...@zz...>; | * @author Christian Zonsius <chr...@zz...>; | */ class ZZOSS_FileReplace { var $search = array(); var $replace = array(); var $search_escape = array(); var $replace_escape = array(); var $mode = 'file'; function file($file) { $this->file = $file; $this->mode = 'file'; } function data($data) { $this->data = $data; $this->mode = 'data'; } function replace($values = array()) { if(count($values)){ foreach($values as $key => $val){ array_push($this->search, "'".$key."'si"); array_push($this->replace, $val); } } } function setEscapes($values) { if(is_array($values) && count($values)){ foreach($values as $key => $val){ array_push($this->search_escape, "'".$key."'si"); array_push($this->replace_escape, $val); } } } function writeout($file_writeout, $do_escape = false) { // create the directory if it does not yet exist System::mkdir(array('-p',dirname($file_writeout))); $file_data = $this->parse($do_escape); // write the parsed config file $fp = fopen($file_writeout, "w"); fputs( $fp, $file_data); fclose( $fp ); } function parse($do_escape = false) { // read the file if($this->mode!='data') { $file_data = fread(fopen($this->file, 'r'), filesize($this->file)); } else { $file_data = $this->data; } if( $do_escape && count($this->search_escape) && count($this->replace_escape)){ $search =& $this->search_escape + $this->search; $replace =& $this->replace_escape + $this->replace; } else { $search =& $this->search; $replace =& $this->replace; } $file_data_replaced = preg_replace ($search, $replace, $file_data); return $file_data_replaced; } } ?> --- NEW FILE: package.xml --- <?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0" xmlns="http://www.zzoss.com/NS/installer/package/"> <name>com.zzoss.filereplace.lib</name> <summary>Replace Strings in File</summary> <description>Replaces multiple strings in one file.</description> <maintainers> <maintainer> <user>czonsius</user> <name>Christian Zonsius</name> <email>chr...@zz...</email> <role>developer</role> </maintainer> <maintainer> <user>ordnas</user> <name>Sandro Zic</name> <email>san...@zz...</email> <role>lead</role> </maintainer> </maintainers> <release> <version>1.0.0</version> <date>{zi_release_date}</date> <license url="http://www.gnu.org/licenses/lgpl.txt" version="2">LGPL</license> <state>stable</state> <notes>Initial release.</notes> <copyright> <holder year="{zi_copyright_year}" url="http://www.zzoss.com">ZZ/OSS</holder> </copyright> <filelist> <file role="php" baseinstalldir="ZZOSS_File" name="Replace.php"/> </filelist> </release> </package> |