/** * Use the new resolving mechanism to call for local services. */ static function call($service, $method, $parameters = array(), $options = array()) { $hostname = System::getHostname('service'); if (!$hostname) { throw new ServiceException('Service hostname undefined.'); } if (is_string($options)) { $options = array('method' => $options); } if (isset($options['type']) && empty($options['method'])) { $options['method'] = $options['type']; } $options = (array) $options + self::$defaultOptions; $prefix = conf::get('web::resolvers.service.prefix', '/service'); $options['uri'] = array('scheme' => (bool) @$options['secure'] ? 'https' : 'http', 'host' => $hostname, 'path' => "{$prefix}/{$service}/{$method}/" . implode('/', array_map('urlencode', (array) $parameters))); unset($prefix); // Customizable Resolver if (@$options['resolver'] instanceof Resolver) { $serviceResolver = $options['resolver']; } else { $serviceResolver = Resolver::getActiveInstance(); } unset($options['resolver']); if (@$options['response'] instanceof Response) { $serviceResponse = $options['response']; } else { $serviceResponse = new Response(); } unset($options['response']); $serviceRequest = new Request($options); // Explicitly force this request to be local. $serviceRequest->__local = true; return $serviceRequest->send($serviceResolver, $serviceResponse); }
function http_build_url($url = null, $parts = array()) { if (is_array($url)) { $parts = $url; $url = null; } if ($url) { $url = parse_url($url); } $url = $parts + (array) $url; if (empty($url['scheme'])) { $url['scheme'] = 'http://'; } else { if (substr($url['scheme'], -3) != '://') { $url['scheme'] .= '://'; } } // Build the url according to parts. if (!empty($url['user'])) { if (!empty($url['pass'])) { $url['user'] = "******"; $url['pass'] = "******"; } else { $url['user'] = "******"; } } if (empty($url['host'])) { $url['host'] = System::getHostname(); } if (!empty($url['port']) && $url['port'] != 80) { $url['port'] = ":{$url['port']}"; } else { unset($url['port']); } if (substr(@$url['path'], 0, 1) != '/') { $url['path'] = @"/{$url['path']}"; } if (isset($url['query'])) { if (is_array($url['query'])) { $url['query'] = http_build_query($url['query']); } if ($url['query'] && $url['query'][0] != '?') { $url['query'] = "?{$url['query']}"; } } if (!empty($url['fragment']) && $url['fragment'][0] != '#') { $url['fragment'] = "#{$url['fragment']}"; } return @"{$url['scheme']}{$url['user']}{$url['pass']}{$url['host']}{$url['port']}{$url['path']}{$url['query']}{$url['fragment']}"; }
/** * Enhanced version of the global redirect(). * * This function normalize the redirection target, make sure secure hostname * is configured and else. * * The main difference is that with the same url we still do redirection. * * @param {string} $target The redirection target, can be either relative * or absolute. If an array of URIs are given, * the first truthy value will be used, this is * handy for a list of fallback URI. * @param {int} $options['status'] The status code used for redirection, defaults to 307 Temporary Redirect. * @param {boolean} $options['secure'] Use secure connection when available. */ public function redirect($target, $options = array()) { // Default values $options += array('status' => 307); // Normalize redirection target if (is_string($target)) { $target = parse_url($target); } // note; Ignore path building on relative redirections, // we don't know where the browser is. if (!preg_match('/^\\.?\\.\\//', $target['path'])) { if (@$options['secure'] && System::getHostname('secure')) { $target['scheme'] = 'https'; if (empty($target['host'])) { $target['host'] = System::getHostname('secure'); } } // Fallback to normal hostname if (empty($target['host'])) { $target['host'] = System::getHostname(); } $target = http_build_url($target); } else { $target = $target['path']; } $this->header('Location', $target)->status($options['status']); }
public function setUri($uri) { if (is_string($uri)) { $uri = parse_url($uri); $uri = parse_url(http_build_url($uri)); } // note; fallback to system default hostname if (empty($uri['host'])) { $uri['host'] = System::getHostname(); } $this->uri = $uri; }