fix basic sourcedir
[pharext/pharext] / src / pharext / SourceDir / Basic.php
1 <?php
2
3 namespace pharext\SourceDir;
4
5 use pharext\Cli\Args;
6 use pharext\License;
7 use pharext\SourceDir;
8
9 use FilesystemIterator;
10 use IteratorAggregate;
11 use RecursiveCallbackFilterIterator;
12 use RecursiveDirectoryIterator;
13 use RecursiveIteratorIterator;
14
15
16 class Basic implements IteratorAggregate, SourceDir
17 {
18 use License;
19
20 private $path;
21
22 public function __construct($path) {
23 $this->path = $path;
24 }
25
26 public function getBaseDir() {
27 return $this->path;
28 }
29
30 public function getPackageInfo() {
31 return [];
32 }
33
34 public function getLicense() {
35 if (($file = $this->findLicense($this->getBaseDir()))) {
36 return $this->readLicense($file);
37 }
38 return "UNKNOWN";
39 }
40
41 public function getArgs() {
42 return [];
43 }
44
45 public function setArgs(Args $args) {
46 }
47
48 public function filter($current, $key, $iterator) {
49 $sub = $current->getSubPath();
50 if ($sub === ".git" || $sub === ".hg" || $sub === ".svn") {
51 return false;
52 }
53 return true;
54 }
55
56 public function getIterator() {
57 $rdi = new RecursiveDirectoryIterator($this->path,
58 FilesystemIterator::CURRENT_AS_SELF | // needed for 5.5
59 FilesystemIterator::KEY_AS_PATHNAME |
60 FilesystemIterator::SKIP_DOTS);
61 $rci = new RecursiveCallbackFilterIterator($rdi, [$this, "filter"]);
62 $rii = new RecursiveIteratorIterator($rci);
63 foreach ($rii as $path => $child) {
64 if (!$child->isDir()) {
65 yield realpath($path);
66 }
67 }
68 }
69 }