Esempio n. 1
0
 /**
  * Returns the file represented by this instance
  *
  * @return \r8\FileSys
  */
 public function getFile()
 {
     if (!isset($this->file)) {
         $this->file = \r8\FileSys::create($this->base . "/" . $this->path);
         $this->file->resolve();
     }
     return clone $this->file;
 }
Esempio n. 2
0
 public function testAddInput_NonFile()
 {
     $input = new \vc\App\Paths();
     try {
         $input->addInput(\r8\FileSys::create($this->dir . '/NotAFile'));
         $this->fail("An expected exception was not thrown");
     } catch (\r8\Exception\Argument $err) {
     }
 }
Esempio n. 3
0
 /**
  * Builds the configuration
  *
  * @return \vc\App\Config
  */
 public function build(\r8\CLI\Result $cli)
 {
     if ($cli->countArgs() < 2) {
         throw new \r8\Exception\Argument(0, 'CLI Args', 'Less than two arguments given');
     }
     $args = $cli->getArgs();
     $output = new \r8\FileSys\Dir(array_shift($args));
     $paths = new \vc\App\Paths();
     foreach ($args as $path) {
         $paths->addInput(\r8\FileSys::create($path));
     }
     return new \vc\App\Config($output, $paths);
 }
Esempio n. 4
0
 /**
  * Tests the given base/path pairing to determine if it is valid
  *
  * @param String $base The base directory to test
  * @param String $path The sub path to test
  * @return Boolean Returns whether the path is valid
  */
 public function test($base, $path)
 {
     if (empty($path)) {
         return FALSE;
     }
     $path = trim((string) $path, "/");
     $full = rtrim((string) $base, "/") . "/" . $path;
     $full = \r8\FileSys::resolvePath($full);
     if (!in_array($full, $this->tested)) {
         $this->tested[] = $full;
     }
     if (!is_file($full)) {
         return FALSE;
     }
     return TRUE;
 }
Esempio n. 5
0
 /**
  * Sets the directory
  *
  * @param String $directory The directory to set
  * @return \r8\URL Returns a self reference
  */
 public function setDir($directory)
 {
     $directory = (string) $directory;
     if (\r8\isEmpty($directory)) {
         $this->directory = null;
     } else {
         $directory = \r8\FileSys::resolvePath($directory);
         $directory = \r8\str\enclose($directory, "/");
         $this->directory = $directory;
     }
     return $this;
 }
Esempio n. 6
0
 public function testResolvePath()
 {
     $this->assertSame('test.php', \r8\FileSys::resolvePath('test.php'));
     $this->assertSame('dir/test.php', \r8\FileSys::resolvePath('dir/test.php'));
     $this->assertSame('/test.php', \r8\FileSys::resolvePath('/test.php'));
     $this->assertSame('c:/test.php', \r8\FileSys::resolvePath('c:/test.php'));
     $this->assertSame('c:/dir/test.php', \r8\FileSys::resolvePath('c:\\dir\\test.php'));
     $this->assertSame('test.php', \r8\FileSys::resolvePath('../test.php'));
     $this->assertSame('/test.php', \r8\FileSys::resolvePath('///////test.php'));
     $this->assertSame('test.php', \r8\FileSys::resolvePath('./test.php'));
     $this->assertSame('dir/test.php', \r8\FileSys::resolvePath('dir/./test.php'));
     $this->assertSame('dir/test.php', \r8\FileSys::resolvePath('dir/sub/../test.php'));
     $this->assertSame('/test', \r8\FileSys::resolvePath('/../test'));
     $this->assertSame('/test/', \r8\FileSys::resolvePath('/../.././../test/'));
     $this->assertSame('/1/2', \r8\FileSys::resolvePath('/1/2/3/4/5/6/../../../..'));
     $this->assertSame('', \r8\FileSys::resolvePath(''));
     $this->assertSame('/', \r8\FileSys::resolvePath('/'));
     $this->assertSame('c:/', \r8\FileSys::resolvePath('c:/'));
     $this->assertSame('D:/', \r8\FileSys::resolvePath('D:\\'));
 }
Esempio n. 7
0
 /**
  * Attempts to find a file given a relative path
  *
  * @param \r8\Finder\Tracker $tracker $file The tracker to use when determining
  *      if a base/path combination is valid
  * @param String $base The base directory to look for the path in
  * @param String $path The path being looked for
  * @return \r8\Finder\Result|NULL Returns a result, or NULL if the file couldn't be found
  */
 public function find(\r8\Finder\Tracker $tracker, $base, $path)
 {
     $origPath = $path;
     $path = trim((string) $path, "/");
     $path = \r8\FileSys::resolvePath($path);
     // Iterate over each possible mutation and determine if it should be applied
     foreach ($this->mutations as $mutate) {
         $result = NULL;
         // Check for a partial match
         if (\r8\str\startsWith($path, $mutate["from"] . "/")) {
             $result = $this->wrapped->find($tracker, $base, $mutate["to"] . "/" . ltrim(substr($path, strlen($mutate["from"])), "/"));
         } else {
             if (strcasecmp($path, $mutate["from"]) == 0) {
                 $result = $this->wrapped->find($tracker, $base, $mutate["to"]);
             }
         }
         if ($result instanceof \r8\Finder\Result) {
             return $result;
         }
     }
     return $this->wrapped->find($tracker, $base, $origPath);
 }