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) {
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);
}
}
}