fix builds of relative paths
[pharext/pharext] / src / pharext / SourceDir / Basic.php
index 7decdc6781f764f29ea8b3548edb6d4c2631360b..e5b2d230c36ea071dc4e28133a09895df2abd7f1 100644 (file)
@@ -3,47 +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);
+               $rci = new RecursiveCallbackFilterIterator($rdi, [$this, "filter"]);
+               $rii = new RecursiveIteratorIterator($rci);
                foreach ($rii as $path => $child) {
                        if (!$child->isDir()) {
-                               yield $path;
+                               yield realpath($path);
                        }
                }
        }