cvs: php4 /pear/File Find.php

From: Date: Tue, 21 Aug 2001 03:00:44 +0000
Subject: cvs: php4 /pear/File Find.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-607@lists.php.net to get a copy of this message
cox Mon Aug 20 23:00:44 2001 EDT Modified files: /php4/pear/File Find.php Log: the withespaces night

Index: php4/pear/File/Find.php diff -u php4/pear/File/Find.php:1.14 php4/pear/File/Find.php:1.15 --- php4/pear/File/Find.php:1.14 Fri Aug 3 00:52:31 2001 +++ php4/pear/File/Find.php Mon Aug 20 23:00:38 2001 @@ -16,7 +16,7 @@ // | Authors: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Find.php,v 1.14 2001/08/03 04:52:31 alexmerz Exp $ +// $Id: Find.php,v 1.15 2001/08/21 03:00:38 cox Exp $ // require_once 'PEAR.php'; @@ -25,7 +25,7 @@ * Commonly needed functions searching directory trees * * @access public -* @version $Id: Find.php,v 1.14 2001/08/03 04:52:31 alexmerz Exp $ +* @version $Id: Find.php,v 1.15 2001/08/21 03:00:38 cox Exp $ * @package File * @author Sterling Hughes <sterling@php.net> */ @@ -35,199 +35,199 @@ * internal dir-list * @var array */ - var $_dirs = array (); + var $_dirs = array (); /** * founded files * @var array */ - var $files = array (); + var $files = array (); /** * founded dirs * @var array */ - var $directories = array (); + var $directories = array (); - /** - * Search the current directory to find matches for the - * the specified pattern. - * - * @param string $pattern a string containing the pattern to search - * the directory for. - * - * @param string $direct_path a string containing the directory path - * to search. - * - * @param string $pattern_type a string containing the type of - * pattern matching functions to use (can either be 'php' or - * 'perl'). - * - * @return array containing all of the files and directories - * matching the pattern. - * - * @author Sterling Hughes <sterling@php.net> - * @access public - */ - function &glob ($pattern, $dirpath, $pattern_type='php') - { - $dh = @opendir ($dirpath); - - if (!$dh) { - $pe = new FileFindException ("Cannot open directory"); - return ($pe); - } - - $match_function = File_Find::_determineRegex ($pattern, $pattern_type); - - while ($entry = @readdir ($dh)) - { - if ($match_function ($pattern, $entry) && - $entry != '.' && - $entry != '..') { - $matches[] = $entry; - } - } - - @closedir ($dh); - return ($matches); - } - - /** - * Map the directory tree given by the directory_path parameter. - * - * @param string $directory_path contains the directory path that you - * want to map. - * - * @return array a two element array, the first element containing a list - * of all the directories, the second element containing a list of all the - * files. - * - * @author Sterling Hughes <sterling@php.net> - * @access public - */ - function &maptree ($directory) - { - $this->_dirs = array ($directory); - - while (count ($this->_dirs)) - { - $dir = array_pop ($this->_dirs); - File_Find::_build ($dir); - array_push ($this->directories, $dir); - } - - return array ($this->directories, $this->files); - } - - /** - * Search the specified directory tree with the specified pattern. Return an - * array containing all matching files (no directories included). - * - * @param string $pattern the pattern to match every file with. - * - * @param string $directory the directory tree to search in. - * - * @param string $regex_type the type of regular expression support to use, either - * 'php' or 'perl'. - * - * @return array a list of files matching the pattern parameter in the the directory - * path specified by the directory parameter - * - * @author Sterling Hughes <sterling@php.net> - * @access public - */ - function &search ($pattern, $directory, $type='php') { - list (,$files) = File_Find::maptree ($directory); - $match_function = File_Find::_determineRegex ($pattern, $type); - - reset ($files); - while (list (,$entry) = each ($files)) - { - if ($match_function ($pattern, $entry)) - $matches[] = $entry; - } - - return ($matches); - } - /** - * Determine whether or not a variable is a PEAR exception - * - * @param object PEAR_Error $var the variable to test. - * - * @return boolean returns true if the variable is a PEAR error, otherwise - * it returns false. - * @access public - */ - function isError (&$var) - { - return PEAR::isError($var); - } - - /** - * Fetch the current File_Find version - * - * @return string the current File_Find version. - * @access public - */ - function File_Find_version() - { - return (1.1); - } - /** - * internal function to build singular directory trees, used by - * File_Find::maptree() - * - * @param string $directory name of the directory to read - * @return void - */ - function _build ($directory) - { - $dh = @opendir ($directory); - - if (!$dh) { - $pe = new FileFindException ("Cannot open directory"); - return ($pe); - } - - while ($entry = @readdir ($dh)) - { - - if ($entry != '.' && - $entry != '..') { - - $entry = "$directory/$entry"; - - if (is_dir ($entry)) - array_push ($this->_dirs, $entry); - else - array_push ($this->files, $entry); - - } - - } - - @closedir ($dh); - } - - /** - * internal function to determine the type of regular expression to - * use, implemented by File_Find::glob() and File_Find::search() - * - * @param string $type given RegExp type - * @return string kind of function ( "eregi", "ereg" or "preg_match") ; - * - */ - function _determineRegex ($pattern, $type) - { - if (! strcasecmp ($type, 'perl')) { - $match_function = 'preg_match'; - } else if (! strcasecmp (substr ($pattern, -2), '/i')) { - $match_function = 'eregi'; - } else { - $match_function = 'ereg'; - } + /** + * Search the current directory to find matches for the + * the specified pattern. + * + * @param string $pattern a string containing the pattern to search + * the directory for. + * + * @param string $direct_path a string containing the directory path + * to search. + * + * @param string $pattern_type a string containing the type of + * pattern matching functions to use (can either be 'php' or + * 'perl'). + * + * @return array containing all of the files and directories + * matching the pattern. + * + * @author Sterling Hughes <sterling@php.net> + * @access public + */ + function &glob ($pattern, $dirpath, $pattern_type='php') + { + $dh = @opendir ($dirpath); + + if (!$dh) { + $pe = new FileFindException ("Cannot open directory"); + return ($pe); + } + + $match_function = File_Find::_determineRegex ($pattern, $pattern_type); + + while ($entry = @readdir ($dh)) + { + if ($match_function ($pattern, $entry) && + $entry != '.' && + $entry != '..') { + $matches[] = $entry; + } + } + + @closedir ($dh); + return ($matches); + } + + /** + * Map the directory tree given by the directory_path parameter. + * + * @param string $directory_path contains the directory path that you + * want to map. + * + * @return array a two element array, the first element containing a list + * of all the directories, the second element containing a list of all the + * files. + * + * @author Sterling Hughes <sterling@php.net> + * @access public + */ + function &maptree ($directory) + { + $this->_dirs = array ($directory); + + while (count ($this->_dirs)) + { + $dir = array_pop ($this->_dirs); + File_Find::_build ($dir); + array_push ($this->directories, $dir); + } + + return array ($this->directories, $this->files); + } + + /** + * Search the specified directory tree with the specified pattern. Return an + * array containing all matching files (no directories included). + * + * @param string $pattern the pattern to match every file with. + * + * @param string $directory the directory tree to search in. + * + * @param string $regex_type the type of regular expression support to use, either + * 'php' or 'perl'. + * + * @return array a list of files matching the pattern parameter in the the directory + * path specified by the directory parameter + * + * @author Sterling Hughes <sterling@php.net> + * @access public + */ + function &search ($pattern, $directory, $type='php') { + list (,$files) = File_Find::maptree ($directory); + $match_function = File_Find::_determineRegex ($pattern, $type); + + reset ($files); + while (list (,$entry) = each ($files)) + { + if ($match_function ($pattern, $entry)) + $matches[] = $entry; + } + + return ($matches); + } + /** + * Determine whether or not a variable is a PEAR exception + * + * @param object PEAR_Error $var the variable to test. + * + * @return boolean returns true if the variable is a PEAR error, otherwise + * it returns false. + * @access public + */ + function isError (&$var) + { + return PEAR::isError($var); + } + + /** + * Fetch the current File_Find version + * + * @return string the current File_Find version. + * @access public + */ + function File_Find_version() + { + return (1.1); + } + /** + * internal function to build singular directory trees, used by + * File_Find::maptree() + * + * @param string $directory name of the directory to read + * @return void + */ + function _build ($directory) + { + $dh = @opendir ($directory); + + if (!$dh) { + $pe = new FileFindException ("Cannot open directory"); + return ($pe); + } + + while ($entry = @readdir ($dh)) + { + + if ($entry != '.' && + $entry != '..') { + + $entry = "$directory/$entry"; + + if (is_dir ($entry)) + array_push ($this->_dirs, $entry); + else + array_push ($this->files, $entry); + + } + + } + + @closedir ($dh); + } + + /** + * internal function to determine the type of regular expression to + * use, implemented by File_Find::glob() and File_Find::search() + * + * @param string $type given RegExp type + * @return string kind of function ( "eregi", "ereg" or "preg_match") ; + * + */ + function _determineRegex ($pattern, $type) + { + if (! strcasecmp ($type, 'perl')) { + $match_function = 'preg_match'; + } else if (! strcasecmp (substr ($pattern, -2), '/i')) { + $match_function = 'eregi'; + } else { + $match_function = 'ereg'; + } - return ($match_function); - } + return ($match_function); + } //End Class } @@ -241,12 +241,12 @@ * classname * @var string */ - var $classname = 'FileFindException'; + var $classname = 'FileFindException'; /** * Message in front of the error message * @var string */ - var $error_message_prepend = 'Error in File_Find'; + var $error_message_prepend = 'Error in File_Find'; /** * Creates a PEAR_Error object * @@ -257,10 +257,10 @@ * @return object PEAR_Error * @access public */ - function FileFindException ($message, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE) - { - $this->PEAR_Error ($message, $mode, $level); - } + function FileFindException ($message, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE) + { + $this->PEAR_Error ($message, $mode, $level); + } } @@ -271,4 +271,4 @@ * End: */ -?> +?> \ No newline at end of file
« previous php.pear.cvs (#607) next »