cvs: pear /File_Find Find.php
| From: | Jon Parise | Date: | Sat, 28 Dec 2002 19:55:36 +0000 |
| Subject: | cvs: pear /File_Find Find.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-7978@lists.php.net to get a copy of this message | ||
jon Sat Dec 28 14:55:36 2002 EDT
Modified files:
/pear/File_Find Find.php
Log:
Massive style update.
Index: pear/File_Find/Find.php diff -u pear/File_Find/Find.php:1.3 pear/File_Find/Find.php:1.4 --- pear/File_Find/Find.php:1.3 Sat Dec 28 10:41:29 2002 +++ pear/File_Find/Find.php Sat Dec 28 14:55:36 2002 @@ -16,7 +16,7 @@ // | Author: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Find.php,v 1.3 2002/12/28 15:41:29 cnb Exp $ +// $Id: Find.php,v 1.4 2002/12/28 19:55:36 jon Exp $ // require_once 'PEAR.php'; @@ -25,27 +25,29 @@ * Commonly needed functions searching directory trees * * @access public -* @version $Id: Find.php,v 1.3 2002/12/28 15:41:29 cnb Exp $ +* @version $Id: Find.php,v 1.4 2002/12/28 19:55:36 jon Exp $ * @package File * @author Sterling Hughes <sterling@php.net> */ class File_Find { /** - * internal dir-list - * @var array - */ - var $_dirs = array (); - /** - * founded files - * @var array - */ - var $files = array (); - /** - * founded dirs - * @var array - */ - var $directories = array (); + * internal dir-list + * @var array + */ + var $_dirs = array(); + + /** + * found files + * @var array + */ + var $files = array(); + + /** + * found dirs + * @var array + */ + var $directories = array(); /** * Search the current directory to find matches for the @@ -67,27 +69,27 @@ * @author Sterling Hughes <sterling@php.net> * @access public */ - function &glob ($pattern, $dirpath, $pattern_type='php') + function &glob($pattern, $dirpath, $pattern_type = 'php') { - $dh = @opendir ($dirpath); + $dh = @opendir($dirpath); if (!$dh) { $pe = new FileFindException("Cannot open directory"); - return ($pe); + return $pe; } $match_function = File_Find::_determineRegex($pattern, $pattern_type); $matches = array(); - while (false !== ($entry = @readdir ($dh))) { + while (false !== ($entry = @readdir($dh))) { if ($match_function($pattern, $entry) && - $entry != '.' && - $entry != '..') { + $entry != '.' && $entry != '..') { $matches[] = $entry; } } - @closedir ($dh); - return count($matches) > 0 ? $matches : null; + @closedir($dh); + + return (count($matches) > 0) ? $matches : null; } /** @@ -103,7 +105,7 @@ * @author Sterling Hughes <sterling@php.net> * @access public */ - function &maptree ($directory) + function &maptree($directory) { $this->_dirs = array($directory); @@ -140,18 +142,16 @@ * @author Mika Tuupola <tuupola@appelsiini.net> * @access public */ - - function &mapTreeMultiple($directory, $maxrecursion=0, $count=0) + function &mapTreeMultiple($directory, $maxrecursion = 0, $count = 0) { - $retval = array(); $count++; $directory .= DIRECTORY_SEPARATOR; - $dh=opendir($directory); + $dh = opendir($directory); while (false !== ($entry = @readdir($dh))) { - if ($entry != "." && $entry != "..") { + if ($entry != '.' && $entry != '..') { array_push($retval, $entry); } } @@ -163,22 +163,21 @@ $path = str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path); - if (!(is_array($val))) { - if (is_dir($path)) { - unset($retval[$key]); - if ($maxrecursion == 0 || $count < $maxrecursion) { - $retval[$val] = File_Find::mapTreeMultiple($path, - $maxrecursion, $count); - } + if (!is_array($val) && is_dir($path)) { + unset($retval[$key]); + if ($maxrecursion == 0 || $count < $maxrecursion) { + $retval[$val] = File_Find::mapTreeMultiple($path, + $maxrecursion, $count); } } } - return($retval); + + return $retval; } /** - * Search the specified directory tree with the specified pattern. Return an - * array containing all matching files (no directories included). + * 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. * @@ -187,13 +186,14 @@ * @param string $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 + * @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') { + function &search($pattern, $directory, $type = 'php') + { $matches = array(); list (,$files) = File_Find::maptree($directory); $match_function = File_Find::_determineRegex($pattern, $type); @@ -206,6 +206,7 @@ return ($matches); } + /** * Determine whether or not a variable is a PEAR exception * @@ -215,7 +216,7 @@ * it returns false. * @access public */ - function isError (&$var) + function isError(&$var) { return PEAR::isError($var); } @@ -230,6 +231,7 @@ { return 1.1; } + /** * internal function to build singular directory trees, used by * File_Find::maptree() @@ -237,9 +239,9 @@ * @param string $directory name of the directory to read * @return void */ - function _build ($directory) + function _build($directory) { - $dh = @opendir ($directory); + $dh = @opendir($directory); if (!$dh) { $pe = new FileFindException("Cannot open directory"); @@ -247,18 +249,16 @@ } while (false !== ($entry = @readdir($dh))) { - if ($entry != '.' && - $entry != '..') { + if ($entry != '.' && $entry != '..') { $entry = $directory.DIRECTORY_SEPARATOR.$entry; - if (is_dir($entry)) + if (is_dir($entry)) { array_push($this->_dirs, $entry); - else + } else { array_push($this->files, $entry); - + } } - } @closedir($dh); @@ -272,11 +272,11 @@ * @return string kind of function ( "eregi", "ereg" or "preg_match") ; * */ - function _determineRegex ($pattern, $type) + function _determineRegex($pattern, $type) { - if (! strcasecmp($type, 'perl')) { + if (!strcasecmp($type, 'perl')) { $match_function = 'preg_match'; - } else if (! strcasecmp(substr($pattern, -2), '/i')) { + } else if (!strcasecmp(substr($pattern, -2), '/i')) { $match_function = 'eregi'; } else { $match_function = 'ereg'; @@ -284,9 +284,8 @@ return $match_function; } - -//End Class } + /** * Exception Class for Errorhandling of File_Find * @access public @@ -294,31 +293,33 @@ class FileFindException extends PEAR_Error { /** - * classname - * @var string - */ - var $classname = 'FileFindException'; - /** - * Message in front of the error message - * @var string - */ + * classname + * @var string + */ + var $classname = 'FileFindException'; + + /** + * Message in front of the error message + * @var string + */ var $error_message_prepend = 'Error in File_Find'; + /** - * Creates a PEAR_Error object - * - * @param string $message Error message - * @param int $mode Error mode - * @param int $level Error level - * - * @return object PEAR_Error - * @access public - */ - function FileFindException ($message, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE) + * Creates a PEAR_Error object + * + * @param string $message Error message + * @param int $mode Error mode + * @param int $level Error level + * + * @return object PEAR_Error + * @access public + */ + function FileFindException($message, $mode = PEAR_ERROR_RETURN, + $level = E_USER_NOTICE) { $this->PEAR_Error($message, $mode, $level); } } - /* * Local variables:
Index: pear/File_Find/Find.php diff -u pear/File_Find/Find.php:1.3 pear/File_Find/Find.php:1.4 --- pear/File_Find/Find.php:1.3 Sat Dec 28 10:41:29 2002 +++ pear/File_Find/Find.php Sat Dec 28 14:55:36 2002 @@ -16,7 +16,7 @@ // | Author: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Find.php,v 1.3 2002/12/28 15:41:29 cnb Exp $ +// $Id: Find.php,v 1.4 2002/12/28 19:55:36 jon Exp $ // require_once 'PEAR.php'; @@ -25,27 +25,29 @@ * Commonly needed functions searching directory trees * * @access public -* @version $Id: Find.php,v 1.3 2002/12/28 15:41:29 cnb Exp $ +* @version $Id: Find.php,v 1.4 2002/12/28 19:55:36 jon Exp $ * @package File * @author Sterling Hughes <sterling@php.net> */ class File_Find { /** - * internal dir-list - * @var array - */ - var $_dirs = array (); - /** - * founded files - * @var array - */ - var $files = array (); - /** - * founded dirs - * @var array - */ - var $directories = array (); + * internal dir-list + * @var array + */ + var $_dirs = array(); + + /** + * found files + * @var array + */ + var $files = array(); + + /** + * found dirs + * @var array + */ + var $directories = array(); /** * Search the current directory to find matches for the @@ -67,27 +69,27 @@ * @author Sterling Hughes <sterling@php.net> * @access public */ - function &glob ($pattern, $dirpath, $pattern_type='php') + function &glob($pattern, $dirpath, $pattern_type = 'php') { - $dh = @opendir ($dirpath); + $dh = @opendir($dirpath); if (!$dh) { $pe = new FileFindException("Cannot open directory"); - return ($pe); + return $pe; } $match_function = File_Find::_determineRegex($pattern, $pattern_type); $matches = array(); - while (false !== ($entry = @readdir ($dh))) { + while (false !== ($entry = @readdir($dh))) { if ($match_function($pattern, $entry) && - $entry != '.' && - $entry != '..') { + $entry != '.' && $entry != '..') { $matches[] = $entry; } } - @closedir ($dh); - return count($matches) > 0 ? $matches : null; + @closedir($dh); + + return (count($matches) > 0) ? $matches : null; } /** @@ -103,7 +105,7 @@ * @author Sterling Hughes <sterling@php.net> * @access public */ - function &maptree ($directory) + function &maptree($directory) { $this->_dirs = array($directory); @@ -140,18 +142,16 @@ * @author Mika Tuupola <tuupola@appelsiini.net> * @access public */ - - function &mapTreeMultiple($directory, $maxrecursion=0, $count=0) + function &mapTreeMultiple($directory, $maxrecursion = 0, $count = 0) { - $retval = array(); $count++; $directory .= DIRECTORY_SEPARATOR; - $dh=opendir($directory); + $dh = opendir($directory); while (false !== ($entry = @readdir($dh))) { - if ($entry != "." && $entry != "..") { + if ($entry != '.' && $entry != '..') { array_push($retval, $entry); } } @@ -163,22 +163,21 @@ $path = str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path); - if (!(is_array($val))) { - if (is_dir($path)) { - unset($retval[$key]); - if ($maxrecursion == 0 || $count < $maxrecursion) { - $retval[$val] = File_Find::mapTreeMultiple($path, - $maxrecursion, $count); - } + if (!is_array($val) && is_dir($path)) { + unset($retval[$key]); + if ($maxrecursion == 0 || $count < $maxrecursion) { + $retval[$val] = File_Find::mapTreeMultiple($path, + $maxrecursion, $count); } } } - return($retval); + + return $retval; } /** - * Search the specified directory tree with the specified pattern. Return an - * array containing all matching files (no directories included). + * 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. * @@ -187,13 +186,14 @@ * @param string $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 + * @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') { + function &search($pattern, $directory, $type = 'php') + { $matches = array(); list (,$files) = File_Find::maptree($directory); $match_function = File_Find::_determineRegex($pattern, $type); @@ -206,6 +206,7 @@ return ($matches); } + /** * Determine whether or not a variable is a PEAR exception * @@ -215,7 +216,7 @@ * it returns false. * @access public */ - function isError (&$var) + function isError(&$var) { return PEAR::isError($var); } @@ -230,6 +231,7 @@ { return 1.1; } + /** * internal function to build singular directory trees, used by * File_Find::maptree() @@ -237,9 +239,9 @@ * @param string $directory name of the directory to read * @return void */ - function _build ($directory) + function _build($directory) { - $dh = @opendir ($directory); + $dh = @opendir($directory); if (!$dh) { $pe = new FileFindException("Cannot open directory"); @@ -247,18 +249,16 @@ } while (false !== ($entry = @readdir($dh))) { - if ($entry != '.' && - $entry != '..') { + if ($entry != '.' && $entry != '..') { $entry = $directory.DIRECTORY_SEPARATOR.$entry; - if (is_dir($entry)) + if (is_dir($entry)) { array_push($this->_dirs, $entry); - else + } else { array_push($this->files, $entry); - + } } - } @closedir($dh); @@ -272,11 +272,11 @@ * @return string kind of function ( "eregi", "ereg" or "preg_match") ; * */ - function _determineRegex ($pattern, $type) + function _determineRegex($pattern, $type) { - if (! strcasecmp($type, 'perl')) { + if (!strcasecmp($type, 'perl')) { $match_function = 'preg_match'; - } else if (! strcasecmp(substr($pattern, -2), '/i')) { + } else if (!strcasecmp(substr($pattern, -2), '/i')) { $match_function = 'eregi'; } else { $match_function = 'ereg'; @@ -284,9 +284,8 @@ return $match_function; } - -//End Class } + /** * Exception Class for Errorhandling of File_Find * @access public @@ -294,31 +293,33 @@ class FileFindException extends PEAR_Error { /** - * classname - * @var string - */ - var $classname = 'FileFindException'; - /** - * Message in front of the error message - * @var string - */ + * classname + * @var string + */ + var $classname = 'FileFindException'; + + /** + * Message in front of the error message + * @var string + */ var $error_message_prepend = 'Error in File_Find'; + /** - * Creates a PEAR_Error object - * - * @param string $message Error message - * @param int $mode Error mode - * @param int $level Error level - * - * @return object PEAR_Error - * @access public - */ - function FileFindException ($message, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE) + * Creates a PEAR_Error object + * + * @param string $message Error message + * @param int $mode Error mode + * @param int $level Error level + * + * @return object PEAR_Error + * @access public + */ + function FileFindException($message, $mode = PEAR_ERROR_RETURN, + $level = E_USER_NOTICE) { $this->PEAR_Error($message, $mode, $level); } } - /* * Local variables: