public function testType() { $abs = new Path('/name'); $rel = new Path('name'); $this->assertTrue($abs->isAbsolute()); $this->assertTrue($rel->isRelative()); }
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]; }
/** * 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); }