X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fpharext%2FSourceDir%2FBasic.php;h=e5b2d230c36ea071dc4e28133a09895df2abd7f1;hb=d5207a43143f6c41520d024ba682cd5d69517416;hp=5d44941edefc81cc8def3fe6441c2631cd346117;hpb=10c6f10181e75139992ba92b7185fe9a50b889b2;p=pharext%2Fpharext diff --git a/src/pharext/SourceDir/Basic.php b/src/pharext/SourceDir/Basic.php index 5d44941..e5b2d23 100644 --- a/src/pharext/SourceDir/Basic.php +++ b/src/pharext/SourceDir/Basic.php @@ -3,48 +3,72 @@ namespace pharext\SourceDir; use pharext\Cli\Args; +use pharext\License; +use pharext\PackageInfo; use pharext\SourceDir; use FilesystemIterator; use IteratorAggregate; +use RecursiveCallbackFilterIterator; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; class Basic implements IteratorAggregate, SourceDir { + use License; + use PackageInfo; + private $path; - + public function __construct($path) { - $this->path = $path; + $this->path = realpath($path); } - + public function getBaseDir() { return $this->path; } - + + /** + * @inheritdoc + * @return array + */ public function getPackageInfo() { - return []; + return $this->findPackageInfo($this->getBaseDir()); } - + + public function getLicense() { + if (($file = $this->findLicense($this->getBaseDir()))) { + return $this->readLicense($file); + } + return "UNKNOWN"; + } + public function getArgs() { return []; } - + public function setArgs(Args $args) { } + + public function filter($current, $key, $iterator) { + $sub = $current->getSubPath(); + if ($sub === ".git" || $sub === ".hg" || $sub === ".svn") { + return false; + } + return true; + } public function getIterator() { $rdi = new RecursiveDirectoryIterator($this->path, FilesystemIterator::CURRENT_AS_SELF | // needed for 5.5 FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::SKIP_DOTS); - $rii = new RecursiveIteratorIterator($rdi, - RecursiveIteratorIterator::CHILD_FIRST); - return $rii; + $rci = new RecursiveCallbackFilterIterator($rdi, [$this, "filter"]); + $rii = new RecursiveIteratorIterator($rci); foreach ($rii as $path => $child) { if (!$child->isDir()) { - #yield $path; + yield realpath($path); } } }