示例#1
0
 public function testReal()
 {
     $path = new Path(__DIR__ . '/..');
     $real = $path->toReal();
     $this->assertEquals($real->name(), realpath(__DIR__ . '/..'));
     $path = new Path('./');
     $this->setExpectedException('Exception');
     $path->toReal();
 }
示例#2
0
 public function script($path, $group = null)
 {
     $path = new \Coast\Path($path);
     if (isset($this->_active)) {
         if (!isset($group)) {
             $path = $path->isRelative() ? $path->toAbsolute($this->_active->script->path) : $path;
             $group = $this->_active->script->group;
         } else {
             if (!$path->isAbsolute()) {
                 $path = new \Coast\Path("/{$path}");
             }
         }
     } else {
         if (!$path->isAbsolute()) {
             $path = new \Coast\Path("/{$path}");
         }
         if (!isset($group)) {
             $group = 'default';
         }
     }
     if (!isset($this->_dirs[$group])) {
         throw new View\Exception("View group '{$group}' does not exist");
     }
     return (object) ['key' => "{$group}:{$path}", 'group' => $group, 'path' => $path];
 }
示例#3
0
 /**
  * Get relative path from absolute path.
  * @param  Coast\Path $base Base absolute path.
  * @return Coast\Path
  */
 public function toRelative(\Coast\Path $base)
 {
     if (!$this->isAbsolute() || !$base->isAbsolute()) {
         throw new \Exception("Source path '{$this}' is not absolute or base path '{$base}' is not absolute");
     }
     $source = explode('/', (string) $base);
     $target = explode('/', $this->_name);
     $name = $target;
     foreach ($source as $i => $part) {
         if ($part == $target[$i]) {
             array_shift($name);
         } else {
             $name = array_pad($name, (count($name) + (count($source) - $i) - 1) * -1, '..');
             break;
         }
     }
     $name = implode('/', $name);
     $class = get_class($this);
     return new $class($name);
 }