/** * Test the setPath method. * * @return void * * @since 1.0 * @covers Joomla\Uri\Uri::setPath */ public function testSetPath() { $this->object->setPath('/this/is/a/path/to/a/file.htm'); $this->assertThat($this->object->getPath(), $this->equalTo('/this/is/a/path/to/a/file.htm')); }
/** * Build route by resource setting. * * @param string $name The route name. * @param array $queries The queries. * @param bool $rootSlash Add root slash or not. * * @return array|string Segments, can be string or array. */ public function build($name, $queries = array(), $rootSlash = false) { $segments = parent::build($name, $queries, $rootSlash); $uri = new Uri($segments); $segments = $uri->getPath(); $this->queries = $uri->getQuery(true); return explode('/', $segments); }
/** * Parse rule hook. * * @param \JRouter $router The router object. * @param Uri $uri The uri object. * * @return array * * @throws \InvalidArgumentException */ public function parseRule(\JRouter $router, Uri $uri) { $path = $uri->getPath(); // No path & method, return 404. if ($this->isRoot($uri)) { throw new \InvalidArgumentException('No method.', 404); } // Direct our URI to component $path = 'component/' . $this->component . '/' . $path; $uri->setPath($path); $uri->setVar('format', 'json'); return array(); }
/** * Give a relative path, return path with host. * * @param string $path A system path. * * @return string Path with host added. */ public static function pathAddHost($path) { if (!$path) { return ''; } // Build path $uri = new Uri($path); if ($uri->getHost()) { return $path; } $uri = new Uri(\JUri::root()); $root_path = $uri->getPath(); if (strpos($path, $root_path) === 0) { $num = Utf8String::strlen($root_path); $path = Utf8String::substr($path, $num); } $uri->setPath($uri->getPath() . $path); $uri->setScheme('http'); $uri->setQuery(null); return $uri->toString(); }