revision display support
[phorkie.git] / src / phorkie / File.php
index 53925eeee131618b8cbb4545a2c54f24d53a9c5f..3c6c56d7e432912d00c47db9546fd7aed9cc62ee 100644 (file)
@@ -4,7 +4,7 @@ namespace phorkie;
 class File
 {
     /**
 class File
 {
     /**
-     * Full path to the file
+     * Path to the file, relative to repository work directory
      *
      * @var string
      */
      *
      * @var string
      */
@@ -17,6 +17,11 @@ class File
      */
     public $repo;
 
      */
     public $repo;
 
+    /**
+     * Commit revision this file is at
+     */
+    public $hash;
+
     public function __construct($path, Repository $repo = null)
     {
         $this->path = $path;
     public function __construct($path, Repository $repo = null)
     {
         $this->path = $path;
@@ -30,7 +35,7 @@ class File
      */
     public function getFilename()
     {
      */
     public function getFilename()
     {
-        return basename($this->path);
+        return $this->path;
     }
 
     /**
     }
 
     /**
@@ -38,9 +43,9 @@ class File
      *
      * @return string
      */
      *
      * @return string
      */
-    public function getPath()
+    public function getFullPath()
     {
     {
-        return $this->path;
+        return $this->repo->workDir . '/' . $this->path;
     }
 
     /**
     }
 
     /**
@@ -55,7 +60,13 @@ class File
 
     public function getContent()
     {
 
     public function getContent()
     {
-        return file_get_contents($this->path);
+        if ($this->repo->hash) {
+            return $this->repo->getVc()->getCommand('show')
+                ->addArgument($this->repo->hash . ':' . $this->path)
+                ->execute();
+        }
+
+        return file_get_contents($this->getFullPath());
     }
 
     public function getRenderedContent(Tool_Result $res = null)
     }
 
     public function getRenderedContent(Tool_Result $res = null)