pax_global_header00006660000000000000000000000064125340041160014506gustar00rootroot0000000000000052 comment=a520dcc3dd39160eea480daa3426f4fd419a327b finder-facade-1.2.0/000077500000000000000000000000001253400411600141565ustar00rootroot00000000000000finder-facade-1.2.0/.gitattributes000066400000000000000000000000171253400411600170470ustar00rootroot00000000000000*.php diff=php finder-facade-1.2.0/.gitignore000066400000000000000000000000551253400411600161460ustar00rootroot00000000000000/.idea /composer.lock /composer.phar /vendor finder-facade-1.2.0/LICENSE000066400000000000000000000030131253400411600151600ustar00rootroot00000000000000FinderFacade Copyright (c) 2012-2015, 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. finder-facade-1.2.0/README.md000066400000000000000000000010101253400411600154250ustar00rootroot00000000000000# FinderFacade **FinderFacade** is a convenience wrapper for Symfony's [Finder](http://symfony.com/doc/2.2/components/finder.html) component. ## Installation To add this package as a local, per-project dependency to your project, simply add a dependency on `sebastian/finder-facade` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on FinderFacade 1.1: { "require": { "sebastian/finder-facade": "~1.1" } } finder-facade-1.2.0/build.xml000066400000000000000000000014561253400411600160050ustar00rootroot00000000000000 finder-facade-1.2.0/composer.json000066400000000000000000000012341253400411600167000ustar00rootroot00000000000000{ "name": "sebastian/finder-facade", "description": "FinderFacade is a convenience wrapper for Symfony's Finder component.", "homepage": "https://github.com/sebastianbergmann/finder-facade", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de", "role": "lead" } ], "support": { "issues": "https://github.com/sebastianbergmann/finder-facade/issues" }, "require": { "theseer/fdomdocument": "~1.3", "symfony/finder": "~2.3" }, "autoload": { "classmap": [ "src/" ] } } finder-facade-1.2.0/src/000077500000000000000000000000001253400411600147455ustar00rootroot00000000000000finder-facade-1.2.0/src/Configuration.php000066400000000000000000000063041253400411600202700ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\FinderFacade; use TheSeer\fDOM\fDOMDocument; /** * * * * /path/to/directory * /path/to/file * * /path/to/directory * *.php * * * * @author Sebastian Bergmann * @copyright Sebastian Bergmann * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License * @link http://github.com/sebastianbergmann/finder-facade/tree * @since Class available since Release 1.0.0 */ class Configuration { /** * @var string */ protected $basePath; /** * @var fDOMDocument */ protected $xml; /** * @param string $file */ public function __construct($file) { $this->basePath = dirname($file); $this->xml = new fDOMDocument; $this->xml->load($file); } /** * @param string $xpath * @return array */ public function parse($xpath = '') { $result = array( 'items' => array(), 'excludes' => array(), 'names' => array(), 'notNames' => array(), 'regularExpressionExcludes' => array() ); foreach ($this->xml->getDOMXPath()->query($xpath . 'include/directory') as $item) { $result['items'][] = $this->toAbsolutePath($item->nodeValue); } foreach ($this->xml->getDOMXPath()->query($xpath . 'include/file') as $item) { $result['items'][] = $this->toAbsolutePath($item->nodeValue); } foreach ($this->xml->getDOMXPath()->query($xpath . 'exclude') as $exclude) { $result['excludes'][] = $exclude->nodeValue; } foreach ($this->xml->getDOMXPath()->query($xpath . 'name') as $name) { $result['names'][] = $name->nodeValue; } foreach ($this->xml->getDOMXPath()->query($xpath . 'notName') as $notName) { $result['notNames'][] = $notName->nodeValue; } foreach ($this->xml->getDOMXPath()->query($xpath . 'regularExpressionExcludes') as $regularExpressionExclude) { $result['regularExpressionExcludes'][] = $regularExpressionExclude->nodeValue; } return $result; } /** * @param string $path * @return string */ protected function toAbsolutePath($path) { // Check whether the path is already absolute. if ($path[0] === '/' || $path[0] === '\\' || (strlen($path) > 3 && ctype_alpha($path[0]) && $path[1] === ':' && ($path[2] === '\\' || $path[2] === '/'))) { return $path; } // Check whether a stream is used. if (strpos($path, '://') !== false) { return $path; } return $this->basePath . DIRECTORY_SEPARATOR . $path; } } finder-facade-1.2.0/src/FinderFacade.php000066400000000000000000000064441253400411600177610ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\FinderFacade; use Symfony\Component\Finder\Finder; /** * Convenience wrapper for Symfony's Finder component. * * @author Sebastian Bergmann * @copyright Sebastian Bergmann * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License * @link http://github.com/sebastianbergmann/finder-facade/tree * @since Class available since Release 1.0.0 */ class FinderFacade { /** * @var array */ protected $items = array(); /** * @var array */ protected $excludes = array(); /** * @var array */ protected $names = array(); /** * @var array */ protected $notNames = array(); /** * @var array */ protected $regularExpressionsExcludes = array(); /** * @param array $items * @param array $excludes * @param array $names * @param array $notNames * @param array $regularExpressionsExcludes */ public function __construct(array $items = array(), array $excludes = array(), array $names = array(), array $notNames = array(), $regularExpressionsExcludes = array()) { $this->items = $items; $this->excludes = $excludes; $this->names = $names; $this->notNames = $notNames; $this->regularExpressionsExcludes = $regularExpressionsExcludes; } /** * @return array */ public function findFiles() { $files = array(); $finder = new Finder; $iterate = false; $finder->ignoreUnreadableDirs(); foreach ($this->items as $item) { if (!is_file($item)) { $finder->in($item); $iterate = true; } else { $files[] = realpath($item); } } foreach ($this->excludes as $exclude) { $finder->exclude($exclude); } foreach ($this->names as $name) { $finder->name($name); } foreach ($this->notNames as $notName) { $finder->notName($notName); } foreach ($this->regularExpressionsExcludes as $regularExpressionExclude) { $finder->notPath($regularExpressionExclude); } if ($iterate) { foreach ($finder as $file) { $files[] = $file->getRealpath(); } } return $files; } /** * @param string $file */ public function loadConfiguration($file) { $configuration = new Configuration($file); $configuration = $configuration->parse(); $this->items = $configuration['items']; $this->excludes = $configuration['excludes']; $this->names = $configuration['names']; $this->notNames = $configuration['notNames']; $this->regularExpressionsExcludes = $configuration['regularExpressionExcludes']; } } finder-facade-1.2.0/tests/000077500000000000000000000000001253400411600153205ustar00rootroot00000000000000finder-facade-1.2.0/tests/ConfigurationTest.php000066400000000000000000000024741253400411600215070ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\FinderFacade; class ConfigurationTest extends \PHPUnit_Framework_TestCase { protected $fixtureDir; protected function setUp() { $this->fixtureDir = __DIR__ . DIRECTORY_SEPARATOR . 'fixture' . DIRECTORY_SEPARATOR; } /** * @covers SebastianBergmann\FinderFacade\Configuration::__construct * @covers SebastianBergmann\FinderFacade\Configuration::parse * @covers SebastianBergmann\FinderFacade\Configuration::toAbsolutePath */ public function testXmlFileCanBeParsed() { $configuration = new Configuration($this->fixtureDir . 'test.xml'); $this->assertEquals( array( 'items' => array( $this->fixtureDir . 'foo', $this->fixtureDir . 'bar.phtml' ), 'excludes' => array('bar'), 'names' => array('*.php'), 'notNames' => array('*.fail.php'), 'regularExpressionExcludes' => array() ), $configuration->parse() ); } } finder-facade-1.2.0/tests/FinderFacadeTest.php000066400000000000000000000032441253400411600211670ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\FinderFacade; class FinderFacadeTest extends \PHPUnit_Framework_TestCase { protected $fixtureDir; protected function setUp() { $this->fixtureDir = __DIR__ . DIRECTORY_SEPARATOR . 'fixture' . DIRECTORY_SEPARATOR; } /** * @covers SebastianBergmann\FinderFacade\FinderFacade::__construct * @covers SebastianBergmann\FinderFacade\FinderFacade::findFiles */ public function testFilesCanBeFoundBasedOnConstructorArguments() { $facade = new FinderFacade( array($this->fixtureDir, $this->fixtureDir . 'bar.phtml'), array('bar'), array('*.php'), array('*.fail.php') ); $this->assertEquals( array( $this->fixtureDir . 'bar.phtml', $this->fixtureDir . 'foo' . DIRECTORY_SEPARATOR . 'bar.php' ), $facade->findFiles() ); } /** * @covers SebastianBergmann\FinderFacade\FinderFacade::loadConfiguration */ public function testFilesCanBeFoundBasedOnXmlConfiguration() { $facade = new FinderFacade; $facade->loadConfiguration($this->fixtureDir . 'test.xml'); $this->assertEquals( array( $this->fixtureDir . 'bar.phtml', $this->fixtureDir . 'foo' . DIRECTORY_SEPARATOR . 'bar.php' ), $facade->findFiles() ); } } finder-facade-1.2.0/tests/fixture/000077500000000000000000000000001253400411600170065ustar00rootroot00000000000000finder-facade-1.2.0/tests/fixture/bar.phtml000066400000000000000000000000001253400411600206060ustar00rootroot00000000000000finder-facade-1.2.0/tests/fixture/foo/000077500000000000000000000000001253400411600175715ustar00rootroot00000000000000finder-facade-1.2.0/tests/fixture/foo/bar.php000066400000000000000000000000001253400411600210340ustar00rootroot00000000000000finder-facade-1.2.0/tests/fixture/foo/bar/000077500000000000000000000000001253400411600203355ustar00rootroot00000000000000finder-facade-1.2.0/tests/fixture/foo/bar/baz.php000066400000000000000000000000001253400411600216100ustar00rootroot00000000000000finder-facade-1.2.0/tests/fixture/foo/foo.fail.php000066400000000000000000000000001253400411600217650ustar00rootroot00000000000000finder-facade-1.2.0/tests/fixture/test.xml000066400000000000000000000002551253400411600205110ustar00rootroot00000000000000 foo bar.phtml bar *.php *.fail.php