cvs: php4 /pear System.php

From: Date: Fri, 31 May 2002 17:47:20 +0000
Subject: cvs: php4 /pear System.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4321@lists.php.net to get a copy of this message
cox Fri May 31 13:47:20 2002 EDT Modified files: /php4/pear System.php Log: - Make mkTemp() automatically removed temporary created files or dirs at script shutdown time - Remove unnecesarry PEAR inheritance - Some PHPDoc fixes Index: php4/pear/System.php diff -u php4/pear/System.php:1.11 php4/pear/System.php:1.12 --- php4/pear/System.php:1.11 Thu Feb 28 03:27:05 2002 +++ php4/pear/System.php Fri May 31 13:47:19 2002 @@ -16,12 +16,14 @@ // | Authors: Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: System.php,v 1.11 2002/02/28 08:27:05 sebastian Exp $ +// $Id: System.php,v 1.12 2002/05/31 17:47:19 cox Exp $ // require_once 'PEAR.php'; require_once 'Console/Getopt.php'; +$GLOBALS['_System_temp_files'] = array(); + /** * System offers cross plattform compatible system functions * @@ -41,11 +43,11 @@ * * @package System * @author Tomas V.V.Cox <cox@idecnet.com> -* @version $Revision: 1.11 $ +* @version $Revision: 1.12 $ * @access public * @see http://pear.php.net/manual/ */ -class System extends PEAR +class System { /** * returns the commandline arguments of a function @@ -306,7 +308,8 @@ } /** - * Creates temporal files or directories + * Creates temporary files or directories. This function will remove + * the created files when the scripts finish its execution. * * Usage: * 1) $tempfile = System::mktemp("prefix"); @@ -316,8 +319,8 @@ * * prefix -> The string that will be prepended to the temp name * (defaults to "tmp"). - * -d -> A temporal dir will be created instead of a file. - * -t -> The target dir where the temporal (file|dir) will be created. If + * -d -> A temporary dir will be created instead of a file. + * -t -> The target dir where the temporary (file|dir) will be created. If * this param is missing by default the env vars TMP on Windows or * TMPDIR in Unix will be used. If these vars are also missing * c:\windows\temp or /tmp will be used. @@ -329,6 +332,7 @@ */ function mktemp($args = null) { + static $first_time = true; $opts = System::_parseArgs($args, 't:d'); if (PEAR::isError($opts)) { return System::raiseError($opts); @@ -354,7 +358,27 @@ return System::raiseError("Unable to create temporary directory $tmpdir"); } } + $GLOBALS['_System_temp_files'][] = $tmp; + if ($first_time) { + PEAR::registerShutdownFunc(array('System', '_removeTmpFiles')); + $first_time = false; + } return $tmp; + } + + /** + * Remove temporary files created my mkTemp. This function is executed + * at script shutdown time + * + * @access private + */ + function _removeTmpFiles() + { + if (count($GLOBALS['_System_temp_files'])) { + $delete = $GLOBALS['_System_temp_files']; + array_unshift($delete, '-r'); + System::rm($delete); + } } /**

« previous php.pear.cvs (#4321) next »