-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate more helpers: 'script.php', 'run.php' and 'run.sh'
If want to open up a generated-project in an IDE (eg for debugging), then it helps for the project to have some references for running the original script. Before: Generated project-dir contains *only* downloaded dependencies After: Generated project-dir contains downloaded dependencies as well as: - A symlink to the script ('script.php') - A helper to run the script ('run.php' or 'run.sh')
- Loading branch information
Showing
4 changed files
with
107 additions
and
1 deletion.
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
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,33 @@ | ||
<?php | ||
namespace Pogo; | ||
|
||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
class FilteredDirectoryIterator extends \FilterIterator { | ||
|
||
protected $basedir; | ||
|
||
/** | ||
* @var callable | ||
* function(string $relPath, SplFileInfo $file): bool; | ||
*/ | ||
protected $filter; | ||
|
||
public function __construct(string $basedir, callable $filter) { | ||
$this->basedir = $basedir; | ||
$this->filter = $filter; | ||
$dirIter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($basedir, | ||
\FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS | ||
)); | ||
parent::__construct($dirIter); | ||
} | ||
|
||
public function accept(): bool { | ||
$fs = new Filesystem(); | ||
$current = $this->current(); | ||
$fullPath = $current->getPath() . DIRECTORY_SEPARATOR . $current->getFilename(); | ||
$relPath = rtrim($fs->makePathRelative($fullPath, $this->basedir), DIRECTORY_SEPARATOR); | ||
return call_user_func($this->filter, $relPath, $current); | ||
} | ||
|
||
} |
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