-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mbed67/examples
corrections in specifications, added examples and integration tests
- Loading branch information
Showing
13 changed files
with
285 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
require_once(__DIR__ . '/../vendor/autoload.php'); | ||
|
||
use League\Flysystem\Filesystem; | ||
use League\Flysystem\Memory\MemoryAdapter as Adapter; | ||
use Flyfinder\Finder; | ||
use Flyfinder\Specification\IsHidden; | ||
|
||
/* | ||
* First create a new Filesystem and add the FlySystem plugin | ||
* In this example we are using a filesystem with the memory adapter | ||
*/ | ||
$filesystem = new Filesystem(new Adapter()); | ||
$filesystem->addPlugin(new Finder()); | ||
|
||
// Create some demo files | ||
$filesystem->write('test.txt', 'test'); | ||
$filesystem->write('.hiddendir/.test.txt', 'test'); | ||
|
||
//In order to tell FlyFinder what to find, you need to give it a specification | ||
//In this example the specification will be satisfied by files and directories that are hidden | ||
$specification = new IsHidden(); | ||
|
||
//FlyFinder will yield a generator object with the files that are found | ||
$generator = $filesystem->find($specification); | ||
|
||
$result = []; | ||
|
||
foreach ($generator as $value) { | ||
$result[] = $value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
require_once(__DIR__ . '/../vendor/autoload.php'); | ||
|
||
use League\Flysystem\Filesystem; | ||
use League\Flysystem\Memory\MemoryAdapter as Adapter; | ||
use Flyfinder\Finder; | ||
use Flyfinder\Path; | ||
use Flyfinder\Specification\IsHidden; | ||
use Flyfinder\Specification\HasExtension; | ||
use Flyfinder\Specification\InPath; | ||
|
||
/* | ||
* First create a new Filesystem and add the FlySystem plugin | ||
* In this example we are using a filesystem with the memory adapter | ||
*/ | ||
$filesystem = new Filesystem(new Adapter()); | ||
$filesystem->addPlugin(new Finder()); | ||
|
||
// Create some demo files | ||
$filesystem->write('test.txt', 'test'); | ||
$filesystem->write('.hiddendir/.test.txt', 'test'); | ||
$filesystem->write('.hiddendir/found.txt', 'test'); | ||
$filesystem->write('.hiddendir/normaldir/example.txt', 'test'); | ||
|
||
/* | ||
* In order to tell FlyFinder what to find, you need to give it a specification | ||
* In this example the specification will be satisfied by *.txt files | ||
* within the .hidden directory and its subdirectories that are not hidden | ||
*/ | ||
$isHidden = new IsHidden(); | ||
$hasExtension = new HasExtension(['txt']); | ||
$inPath = new InPath(new Path('.hiddendir')); | ||
$specification = $inPath->andSpecification($hasExtension)->andSpecification($isHidden->notSpecification()); | ||
|
||
//FlyFinder will yield a generator object with the files that are found | ||
$generator = $filesystem->find($specification); | ||
|
||
$result = []; | ||
|
||
foreach ($generator as $value) { | ||
$result[] = $value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org> | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace Flyfinder; | ||
|
||
/** | ||
* Integration test against examples/01-find-hidden-files.php | ||
* @coversNothing | ||
*/ | ||
class FindHiddenFilesTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var string[] $result | ||
*/ | ||
public function testFindingHiddenFiles() | ||
{ | ||
include(__DIR__ . '/../../examples/01-find-hidden-files.php'); | ||
|
||
$this->assertEquals(2, count($result)); | ||
$this->assertEquals(".test.txt", $result[1]['basename']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org> | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace Flyfinder; | ||
|
||
/** | ||
* Integration test against examples/02-find-on-multiple-criteria.php | ||
* @coversNothing | ||
*/ | ||
class FindOnMultipleCriteriaTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var string[] $result | ||
*/ | ||
public function testFindingFilesOnMultipleCriteria() | ||
{ | ||
include(__DIR__ . '/../../examples/02-find-on-multiple-criteria.php'); | ||
|
||
$this->assertEquals(2, count($result)); | ||
$this->assertEquals("found.txt", $result[0]['basename']); | ||
$this->assertEquals("example.txt", $result[1]['basename']); | ||
} | ||
} |
Oops, something went wrong.