/** * Test the toString method. * * @return void * * @since 1.0 * @covers Windwalker\Uri\Uri::toString */ public function testToString() { $this->assertThat($this->object->toString(), $this->equalTo('http://*****:*****@www.example.com:80/path/file.html?var=value#fragment')); $this->object->setQuery('somevar=somevalue'); $this->object->setVar('somevar2', 'somevalue2'); $this->object->setScheme('ftp'); $this->object->setUser('root'); $this->object->setPass('secret'); $this->object->setHost('www.example.org'); $this->object->setPort('8888'); $this->object->setFragment('someFragment'); $this->object->setPath('/this/is/a/path/to/a/file'); $this->assertThat($this->object->toString(), $this->equalTo('ftp://*****:*****@www.example.org:8888/this/is/a/path/to/a/file?somevar=somevalue&somevar2=somevalue2#someFragment')); }
/** * doExecute * * @return mixed */ protected function doExecute() { $model['list.search'] = $this->getUserStateFromInput($this->getContext('list.search'), 'search', array(), InputFilter::ARRAY_TYPE); $model['list.filter'] = $this->getUserStateFromInput($this->getContext('list.filter'), 'filter', array(), InputFilter::ARRAY_TYPE); $model['list.ordering'] = $this->getUserStateFromInput($this->getContext('list.ordering'), 'list_ordering'); $model['list.direction'] = $this->getUserStateFromInput($this->getContext('list.direction'), 'list_direction'); $uri = new Uri($this->app->uri->full); $uri->delVar('filter'); $this->setRedirect($uri->toString()); return true; }
/** * url * * @param int $size * @param int $id * @param string $u * * @return string */ public static function url($size = 300, $id = null, $u = null) { $uri = new Uri(static::$host); $size = $size ?: 300; $uri->setPath('/' . $size); if ($id) { $uri->setVar('id', (int) $id); } if ($u) { $uri->setVar('u', $u); } return $uri->toString(); }
/** * Redirect to another URL. * * If the headers have not been sent the redirect will be accomplished using a "301 Moved Permanently" * or "303 See Other" code in the header pointing to the new location. If the headers have already been * sent this will be accomplished using a JavaScript statement. * * @param string $url The URL to redirect to. Can only be http/https URL * @param boolean $moved True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed. * * @return void * * @since 2.0 */ public function redirect($url, $moved = false) { // Check for relative internal links. if (preg_match('#^index\\.php#', $url)) { $url = $this->get('uri.base.full') . $url; } // Perform a basic sanity check to make sure we don't have any CRLF garbage. $url = preg_split("/[\r\n]/", $url); $url = $url[0]; /* * Here we need to check and see if the URL is relative or absolute. Essentially, do we need to * prepend the URL with our base URL for a proper redirect. The rudimentary way we are looking * at this is to simply check whether or not the URL string has a valid scheme or not. */ if (!preg_match('#^[a-z]+\\://#i', $url)) { // Get a URI instance for the requested URI. $uri = new Uri($this->get('uri.current')); // Get a base URL to prepend from the requested URI. $prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); // We just need the prefix since we have a path relative to the root. if ($url[0] == '/') { $url = $prefix . $url; } else { $parts = explode('/', $uri->toString(array('path'))); array_pop($parts); $path = implode('/', $parts) . '/'; $url = $prefix . $path . $url; } } // If the headers have already been sent we need to send the redirect statement via JavaScript. if ($this->response->checkHeadersSent()) { echo "<script>document.location.href='{$url}';</script>\n"; } else { // We have to use a JavaScript redirect here because MSIE doesn't play nice with utf-8 URLs. if ($this->environment->client->getEngine() == WebClient::TRIDENT && !ApplicationHelper::isAscii($url)) { $html = '<html><head>'; $html .= '<meta http-equiv="content-type" content="text/html; charset=' . $this->response->getCharSet() . '" />'; $html .= '<script>document.location.href=\'' . $url . '\';</script>'; $html .= '</head><body></body></html>'; echo $html; } else { // All other cases use the more efficient HTTP header for redirection. $this->response->header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other'); $this->response->header('Location: ' . $url); $this->response->header('Content-Type: text/html; charset=' . $this->response->getCharSet()); } } // Close the application after the redirect. $this->close(); }
/** * getSuccessRedirect * * @param DataInterface|Entity $data * * @return string */ protected function getSuccessRedirect(DataInterface $data = null) { $uri = new Uri($this->app->uri->full); foreach ($this->getRedirectQuery() as $field => $value) { $uri->setVar($field, $value); } return $uri->toString(); }