本文整理汇总了PHP中Zend\Uri\Uri::toString方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::toString方法的具体用法?PHP Uri::toString怎么用?PHP Uri::toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Uri\Uri
的用法示例。
在下文中一共展示了Uri::toString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* @param \Zend\Uri\Uri $uri
*/
public function parse(Uri $uri)
{
$this->url = $uri->toString();
$html = \OpenGraph::fetch($uri->toString());
// open graph
$this->id = basename($uri->getPath());
$this->title = $html->title;
$this->description = $html->description;
$this->image = urlencode($html->image);
}
示例2: analyse
/**
* @param \Zend\Uri\Uri $uri
*
* @return mixed False if service or namespace nofound
*/
public function analyse(Uri $uri)
{
$service = $this->serviceManager->searchService($uri->toString());
if (false === $service) {
return false;
}
$namespace = $this->serviceManager->getServiceNamespace($service);
if (null === $namespace || $namespace === '') {
return false;
}
$clear = $namespace::clearUri($uri);
if (false === $clear) {
return false;
}
$keyCache = $uri->toString();
// cache because the analyse process requires a lot of resources
$analyser = $this->cache->get($keyCache);
if (null !== $analyser) {
return $analyser;
}
// analyse process
$analyser = new $namespace();
$analyser->parse($uri);
return $this->cache->set($keyCache, $analyser);
}
示例3: parse
/**
* @param \Zend\Uri\Uri $uri
*/
public function parse(Uri $uri)
{
$this->url = $uri->toString();
$html = \OpenGraph::fetch($this->url);
$query = $uri->getQueryAsArray();
// open graph
$this->id = $query['v'];
$this->title = $html->title;
$this->description = $html->description;
$this->image = urlencode($html->image);
}
示例4: getUrl
/**
* Get Url
*
* @return string
*/
public function getUrl()
{
if ($this->uri instanceof Uri) {
$url = array('href' => $this->uri->toString());
$query = $this->uri->getQueryAsArray();
if (sizeof($query) > 0) {
$url['query'] = $query;
}
return $url;
}
return;
}
示例5: validateUrl
private function validateUrl($config, $name, $base = '')
{
if (!isset($config['idp_url'][$name])) {
throw new \InvalidArgumentException('universibo_sso.idp_url.' . $name . ' is not set!');
}
try {
$uri = new Uri($base . $config['idp_url'][$name]);
return $uri->toString();
} catch (\Exception $e) {
throw new \InvalidArgumentException('universibo_sso.idp_url.' . $name . ' is not valid!');
}
}
示例6: write
/**
* Send request to the proxy server with streaming support
*
* @param string $method
* @param \Zend\Uri\Uri $uri
* @param string $http_ver
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
{
// If no proxy is set, throw an error
if (!$this->config['proxy_host']) {
throw new Adapter\Exception('No proxy host set!');
}
// Make sure we're properly connected
if (!$this->socket) {
throw new Adapter\Exception('Trying to write but we are not connected');
}
$host = $this->config['proxy_host'];
$port = $this->config['proxy_port'];
if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) {
throw new Adapter\Exception('Trying to write but we are connected to the wrong proxy ' . 'server');
}
// Add Proxy-Authorization header
if ($this->config['proxy_user'] && !isset($headers['proxy-authorization'])) {
$headers['proxy-authorization'] = \Zend\Http\Client::encodeAuthHeader($this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']);
}
// if we are proxying HTTPS, preform CONNECT handshake with the proxy
if ($uri->getScheme() == 'https' && !$this->negotiated) {
$this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
$this->negotiated = true;
}
// Save request method for later
$this->method = $method;
// Build request headers
$request = "{$method} {$uri->toString()} HTTP/{$http_ver}\r\n";
// Add all headers to the request string
foreach ($headers as $k => $v) {
if (is_string($k)) {
$v = "{$k}: {$v}";
}
$request .= "{$v}\r\n";
}
$request .= "\r\n";
// Send the request headers
if (!@fwrite($this->socket, $request)) {
throw new Adapter\Exception('Error writing request to proxy server');
}
//read from $body, write to socket
while ($body->hasData()) {
if (!@fwrite($this->socket, $body->read(self::CHUNK_SIZE))) {
throw new Adapter\Exception('Error writing request to server');
}
}
return 'Large upload, request is not cached.';
}
示例7: parse
/**
* @param \Zend\Uri\Uri $uri
*/
public function parse(Uri $uri)
{
$this->url = $uri->toString();
$paths = explode('/', $uri->getPath());
$pathsCount = count($paths);
$id = $paths[$pathsCount - 1];
$type = $paths[$pathsCount - 2];
$data = json_encode(file_get_contents('http://api.deezer.com/2.0/' . $type . '/' . $id));
if (!isset($data['id'])) {
return;
}
$this->id = $data['id'];
$this->title = $data['title'];
$this->description = $data['album']['link'];
$this->image = $data['album']['cover'];
}
示例8: _prepareRest
/**
* Call a remote REST web service URI and return the Zend_Http_Response object
*
* @param string $path The path to append to the URI
* @throws Zend\Rest\Client\Exception\UnexpectedValueException
* @return void
*/
private final function _prepareRest($path)
{
// Get the URI object and configure it
if (!$this->_uri instanceof Uri\Uri) {
throw new Exception\UnexpectedValueException('URI object must be set before performing call');
}
$uri = $this->_uri->toString();
if ($path[0] != '/' && $uri[strlen($uri) - 1] != '/') {
$path = '/' . $path;
}
$this->_uri->setPath($path);
/**
* Get the HTTP client and configure it for the endpoint URI. Do this
* each time as the Zend\Http\Client instance may be shared with other
* Zend\Service\AbstractService subclasses.
*/
$this->getHttpClient()->resetParameters()->setUri($this->_uri);
}
示例9: createAuthorizationRequestUri
/**
* Generates an URI representing the authorization request.
*
* @param Request $request
* @return string
*/
public function createAuthorizationRequestUri(Request $request)
{
/* @var $clientInfo \InoOicClient\Client\ClientInfo */
$clientInfo = $request->getClientInfo();
if (!$clientInfo) {
throw new \RuntimeException('Missing client info in request');
}
if (($endpointUri = $clientInfo->getAuthorizationEndpoint()) === null) {
throw new Exception\MissingEndpointException('No endpoint specified');
}
$uri = new Uri($endpointUri);
$params = array(Param::CLIENT_ID => $clientInfo->getClientId(), Param::REDIRECT_URI => $clientInfo->getRedirectUri(), Param::RESPONSE_TYPE => $this->arrayToSpaceDelimited($request->getResponseType()), Param::SCOPE => $this->arrayToSpaceDelimited($request->getScope()), Param::STATE => $request->getState());
foreach ($params as $name => $value) {
if (in_array($name, $this->requiredParams) && empty($value)) {
throw new Exception\MissingFieldException($name);
}
}
$uri->setQuery($params);
return $uri->toString();
}
示例10: testMakeRelative
/**
* Test that makeRelative() works as expected
*
* @dataProvider commonBaseUriProvider
*/
public function testMakeRelative($base, $url, $expected)
{
$url = new Uri($url);
$url->makeRelative($base);
$this->assertEquals($expected, $url->toString());
}
示例11: geocode
/**
* Execute geocoding
*
* @param Request $request
* @return Response
*/
public function geocode(Request $request)
{
if (null === $request) {
throw new Exception\InvalidArgumentException('request');
}
$uri = new Uri();
$uri->setHost(self::GOOGLE_MAPS_APIS_URL);
$uri->setPath(self::GOOGLE_GEOCODING_API_PATH);
$urlParameters = $request->getUrlParameters();
if (null === $urlParameters) {
throw new Exception\RuntimeException('Invalid URL parameters');
}
$uri->setQuery($urlParameters);
$client = $this->getHttpClient();
$client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
$client->resetParameters();
$uri->setScheme("https");
$client->setUri($uri->toString());
$stream = $client->send();
$body = Json::decode($stream->getBody(), Json::TYPE_ARRAY);
$hydrator = new ArraySerializable();
$response = new Response();
$response->setRawBody($body);
if (!isset($body['status'])) {
throw new Exception\RuntimeException('Invalid status');
}
$response->setStatus($body['status']);
if (!isset($body['results'])) {
throw new Exception\RuntimeException('Invalid results');
}
$resultSet = new ResultSet();
foreach ($body['results'] as $data) {
$result = new Result();
$hydrator->hydrate($data, $result);
$resultSet->addElement($result);
}
$response->setResults($resultSet);
return $response;
}
示例12: toString
public function toString()
{
if ($this->host && !$this->scheme) {
$this->setScheme('http');
}
$url = parent::toString();
if (true === $this->htmlEncode) {
$url = htmlentities($url, ENT_QUOTES, 'UTF-8');
}
if (true === $this->urlEncode) {
$url = urldecode($url);
}
return $url;
}
示例13: toString
/**
* Compose the URI into a string
*
* @return string
* @throws Exception\InvalidUriException
*/
public function toString()
{
return $this->uri->toString();
}
示例14: bind
/**
* Start the server
*/
public function bind()
{
$err = $errno = 0;
$this->flashPolicyFile = str_replace('to-ports="*', 'to-ports="' . $this->uri->getPort() ?: 80, $this->flashPolicyFile);
$serverSocket = stream_socket_server($this->uri->toString(), $errno, $err, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $this->context);
$this->logger->notice(sprintf("phpws listening on %s", $this->uri->toString()));
if ($serverSocket == false) {
$this->logger->err("Error: {$err}");
return;
}
$timeOut =& $this->purgeUserTimeOut;
$sockets = $this->streams;
$that = $this;
$logger = $this->logger;
$this->loop->addReadStream($serverSocket, function ($serverSocket) use($that, $logger, $sockets) {
$newSocket = stream_socket_accept($serverSocket);
if (false === $newSocket) {
return;
}
stream_set_blocking($newSocket, 0);
$client = new WebSocketConnection($newSocket, $that->loop, $logger);
$sockets->attach($client);
$client->on("handshake", function (Handshake $request) use($that, $client) {
$that->emit("handshake", [$client->getTransport(), $request]);
});
$client->on("connect", function () use($that, $client, $logger) {
$con = $client->getTransport();
$that->getConnections()->attach($con);
$that->emit("connect", ["client" => $con]);
});
$client->on("message", function ($message) use($that, $client, $logger) {
$connection = $client->getTransport();
$that->emit("message", ["client" => $connection, "message" => $message]);
});
$client->on("close", function () use($that, $client, $logger, &$sockets, $client) {
$sockets->detach($client);
$connection = $client->getTransport();
if ($connection) {
$that->getConnections()->detach($connection);
$that->emit("disconnect", ["client" => $connection]);
}
});
$client->on("flashXmlRequest", function () use($that, $client) {
$client->getTransport()->sendString($that->flashPolicyFile);
$client->close();
});
});
$this->loop->addPeriodicTimer(5, function () use($timeOut, $sockets, $that) {
# Lets send some pings
foreach ($that->getConnections() as $c) {
if ($c instanceof WebSocketTransportHybi) {
$c->sendFrame(WebSocketFrame::create(WebSocketOpcode::PING_FRAME));
}
}
$currentTime = time();
if ($timeOut == null) {
return;
}
foreach ($sockets as $s) {
if ($currentTime - $s->getLastChanged() > $timeOut) {
$s->close();
}
}
});
}