package.xml0000664000076400007640000000475611703122652011012 0ustar sbsb File_Iterator pear.phpunit.de FilterIterator implementation that filters files based on a list of suffixes. FilterIterator implementation that filters files based on a list of suffixes. Sebastian Bergmann sb sb@sebastian-bergmann.de yes 2012-01-10 1.3.1 1.3.0 stable stable BSD License http://github.com/sebastianbergmann/php-file-iterator/tree 5.2.7 1.9.2 File_Iterator-1.3.1/File/Iterator/Autoload.php0000664000076400007640000000517211703122652017005 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package File * @author Sebastian Bergmann * @copyright 2009-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @since File available since Release 1.3.0 */ function file_iterator_autoload($class = NULL) { static $classes = NULL; static $path = NULL; if ($classes === NULL) { $classes = array( 'file_iterator' => '/Iterator.php', 'file_iterator_facade' => '/Iterator/Facade.php', 'file_iterator_factory' => '/Iterator/Factory.php' ); $path = dirname(dirname(__FILE__)); } if ($class === NULL) { $result = array(__FILE__); foreach ($classes as $file) { $result[] = $path . $file; } return $result; } $cn = strtolower($class); if (isset($classes[$cn])) { require $path . $classes[$cn]; } } spl_autoload_register('file_iterator_autoload'); File_Iterator-1.3.1/File/Iterator/Facade.php0000664000076400007640000001160311703122652016374 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package File * @author Sebastian Bergmann * @copyright 2009-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @since File available since Release 1.3.0 */ /** * Façade implementation that uses File_Iterator_Factory to create a * File_Iterator that operates on an AppendIterator that contains an * RecursiveDirectoryIterator for each given path. The list of unique * files is returned as an array. * * @author Sebastian Bergmann * @copyright 2009-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.3.1 * @link http://github.com/sebastianbergmann/php-file-iterator/tree * @since Class available since Release 1.3.0 */ class File_Iterator_Facade { /** * @param array|string $paths * @param array|string $suffixes * @param array|string $prefixes * @param array $exclude * @param boolean $commonPath * @return array */ public function getFilesAsArray($paths, $suffixes = '', $prefixes = '', array $exclude = array(), $commonPath = FALSE) { if (is_string($paths)) { $paths = array($paths); } $factory = new File_Iterator_Factory; $iterator = $factory->getFileIterator( $paths, $suffixes, $prefixes, $exclude ); $files = array(); foreach ($iterator as $file) { $file = $file->getRealPath(); if ($file) { $files[] = $file; } } foreach ($paths as $path) { if (is_file($path)) { $files[] = realpath($path); } } $files = array_unique($files); sort($files); if ($commonPath) { return array( 'commonPath' => $this->getCommonPath($files), 'files' => $files ); } else { return $files; } } /** * Returns the common path of a set of files. * * @param array $files * @return string */ protected function getCommonPath(array $files) { $count = count($files); if ($count == 0) { return ''; } if ($count == 1) { return dirname($files[0]) . DIRECTORY_SEPARATOR; } $_files = array(); foreach ($files as $file) { $_files[] = $_fileParts = explode(DIRECTORY_SEPARATOR, $file); if (empty($_fileParts[0])) { $_fileParts[0] = DIRECTORY_SEPARATOR; } } $common = ''; $done = FALSE; $j = 0; $count--; while (!$done) { for ($i = 0; $i < $count; $i++) { if ($_files[$i][$j] != $_files[$i+1][$j]) { $done = TRUE; break; } } if (!$done) { $common .= $_files[0][$j]; if ($j > 0) { $common .= DIRECTORY_SEPARATOR; } } $j++; } return $common; } } File_Iterator-1.3.1/File/Iterator/Factory.php0000664000076400007640000001005711703122652016642 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package File * @author Sebastian Bergmann * @copyright 2009-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @since File available since Release 1.1.0 */ /** * Factory Method implementation that creates a File_Iterator that operates on * an AppendIterator that contains an RecursiveDirectoryIterator for each given * path. * * @author Sebastian Bergmann * @copyright 2009-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.3.1 * @link http://github.com/sebastianbergmann/php-file-iterator/tree * @since Class available since Release 1.1.0 */ class File_Iterator_Factory { /** * @param array|string $paths * @param array|string $suffixes * @param array|string $prefixes * @param array $exclude * @return AppendIterator */ public function getFileIterator($paths, $suffixes = '', $prefixes = '', array $exclude = array()) { if (is_string($paths)) { $paths = array($paths); } $_paths = array(); foreach ($paths as $path) { if ($locals = glob($path, GLOB_ONLYDIR)) { $_paths = array_merge($_paths, $locals); } else { $_paths[] = $path; } } $paths = $_paths; unset($_paths); if (is_string($prefixes)) { if ($prefixes != '') { $prefixes = array($prefixes); } else { $prefixes = array(); } } if (is_string($suffixes)) { if ($suffixes != '') { $suffixes = array($suffixes); } else { $suffixes = array(); } } $iterator = new AppendIterator; foreach ($paths as $path) { if (is_dir($path)) { $iterator->append( new File_Iterator( new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path) ), $suffixes, $prefixes, $exclude, $path ) ); } } return $iterator; } } File_Iterator-1.3.1/File/Iterator.php0000664000076400007640000001352711703122652015240 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package File * @author Sebastian Bergmann * @copyright 2009-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @since File available since Release 1.0.0 */ /** * FilterIterator implementation that filters files based on prefix(es) and/or * suffix(es). Hidden files and files from hidden directories are also filtered. * * @author Sebastian Bergmann * @copyright 2009-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.3.1 * @link http://github.com/sebastianbergmann/php-file-iterator/tree * @since Class available since Release 1.0.0 */ class File_Iterator extends FilterIterator { const PREFIX = 0; const SUFFIX = 1; /** * @var array */ protected $suffixes = array(); /** * @var array */ protected $prefixes = array(); /** * @var array */ protected $exclude = array(); /** * @var string */ protected $basepath; /** * @param Iterator $iterator * @param array $suffixes * @param array $prefixes * @param array $exclude * @param string $basepath */ public function __construct(Iterator $iterator, array $suffixes = array(), array $prefixes = array(), array $exclude = array(), $basepath = NULL) { $exclude = array_filter(array_map('realpath', $exclude)); if ($basepath !== NULL) { $basepath = realpath($basepath); } if ($basepath === FALSE) { $basepath = NULL; } else { foreach ($exclude as &$_exclude) { $_exclude = str_replace($basepath, '', $_exclude); } } $this->prefixes = $prefixes; $this->suffixes = $suffixes; $this->exclude = $exclude; $this->basepath = $basepath; parent::__construct($iterator); } /** * @return boolean */ public function accept() { $current = $this->getInnerIterator()->current(); $filename = $current->getFilename(); $realpath = $current->getRealPath(); if ($this->basepath !== NULL) { $realpath = str_replace($this->basepath, '', $realpath); } // Filter files in hidden directories. if (preg_match('=/\.[^/]*/=', $realpath)) { return FALSE; } return $this->acceptPath($realpath) && $this->acceptPrefix($filename) && $this->acceptSuffix($filename); } /** * @param string $path * @return boolean * @since Method available since Release 1.1.0 */ protected function acceptPath($path) { foreach ($this->exclude as $exclude) { if (strpos($path, $exclude) === 0) { return FALSE; } } return TRUE; } /** * @param string $filename * @return boolean * @since Method available since Release 1.1.0 */ protected function acceptPrefix($filename) { return $this->acceptSubString($filename, $this->prefixes, self::PREFIX); } /** * @param string $filename * @return boolean * @since Method available since Release 1.1.0 */ protected function acceptSuffix($filename) { return $this->acceptSubString($filename, $this->suffixes, self::SUFFIX); } /** * @param string $filename * @param array $subString * @param integer $type * @return boolean * @since Method available since Release 1.1.0 */ protected function acceptSubString($filename, array $subStrings, $type) { if (empty($subStrings)) { return TRUE; } $matched = FALSE; foreach ($subStrings as $string) { if (($type == self::PREFIX && strpos($filename, $string) === 0) || ($type == self::SUFFIX && substr($filename, -1 * strlen($string)) == $string)) { $matched = TRUE; break; } } return $matched; } } File_Iterator-1.3.1/ChangeLog.markdown0000664000076400007640000000074411703122652015447 0ustar sbsbFile_Iterator 1.3 ================= This is the list of changes for the File_Iterator 1.3 release series. File_Iterator 1.3.1 ------------------- * Fixed infinite loop in `File_Iterator_Facade::getCommonPath()` for empty directories. File_Iterator 1.3.0 ------------------- * Added `File_Iterator_Facade` for the most common use case. * Moved `File_Iterator_Factory::getFilesAsArray()` to `File_Iterator_Facade::getFilesAsArray()`. * `File_Iterator_Factory` is no longer static. File_Iterator-1.3.1/LICENSE0000664000076400007640000000301411703122652013052 0ustar sbsbFile_Iterator Copyright (c) 2009-2012, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. File_Iterator-1.3.1/README.markdown0000664000076400007640000000210611703122652014547 0ustar sbsbFile_Iterator ============= Installation ------------ File_Iterator should be installed using the [PEAR Installer](http://pear.php.net/). This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0. The PEAR channel (`pear.phpunit.de`) that is used to distribute File_Iterator needs to be registered with the local PEAR environment: sb@ubuntu ~ % pear channel-discover pear.phpunit.de Adding Channel "pear.phpunit.de" succeeded Discovery of channel "pear.phpunit.de" succeeded This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel: sb@vmware ~ % pear install phpunit/File_Iterator downloading File_Iterator-1.1.1.tgz ... Starting to download File_Iterator-1.1.1.tgz (3,173 bytes) ....done: 3,173 bytes install ok: channel://pear.phpunit.de/File_Iterator-1.1.1 After the installation you can find the File_Iterator source files inside your local PEAR directory; the path is usually `/usr/lib/php/File`. package.sig0000664000076400007640000000030611703122661010757 0ustar sbsb-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEABECAAYFAk8MpbEACgkQaGfFFLhbXWka7gCfUbSSK3rmfNIJzw5G1aWDiepK 7J4AnjihrR3AbB03sOMJl5VHvcR+6iA0 =NAJJ -----END PGP SIGNATURE-----