本文整理汇总了PHP中Zend\Uri\Uri类的典型用法代码示例。如果您正苦于以下问题:PHP Uri类的具体用法?PHP Uri怎么用?PHP Uri使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Uri类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: open
public function open($timeOut = null)
{
/**
* @var $that self
*/
$that = new FullAccessWrapper($this);
$uri = new Uri($this->url);
$isSecured = 'wss' === $uri->getScheme();
$defaultPort = $isSecured ? 443 : 80;
$connector = new Connector($this->loop, $this->dns, $this->streamOptions);
if ($isSecured) {
$connector = new \React\SocketClient\SecureConnector($connector, $this->loop);
}
$deferred = new Deferred();
$connector->create($uri->getHost(), $uri->getPort() ?: $defaultPort)->then(function (\React\Stream\Stream $stream) use($that, $uri, $deferred, $timeOut) {
if ($timeOut) {
$timeOutTimer = $that->loop->addTimer($timeOut, function () use($promise, $stream, $that) {
$stream->close();
$that->logger->notice("Timeout occured, closing connection");
$that->emit("error");
$promise->reject("Timeout occured");
});
} else {
$timeOutTimer = null;
}
$transport = new WebSocketTransportHybi($stream);
$transport->setLogger($that->logger);
$that->transport = $transport;
$that->stream = $stream;
$stream->on("close", function () use($that) {
$that->isClosing = false;
$that->state = WebSocket::STATE_CLOSED;
});
// Give the chance to change request
$transport->on("request", function (Request $handshake) use($that) {
$that->emit("request", func_get_args());
});
$transport->on("handshake", function (Handshake $handshake) use($that) {
$that->request = $handshake->getRequest();
$that->response = $handshake->getRequest();
$that->emit("handshake", array($handshake));
});
$transport->on("connect", function () use(&$state, $that, $transport, $timeOutTimer, $deferred) {
if ($timeOutTimer) {
$timeOutTimer->cancel();
}
$deferred->resolve($transport);
$that->state = WebSocket::STATE_CONNECTED;
$that->emit("connect");
});
$transport->on('message', function ($message) use($that, $transport) {
$that->emit("message", array("message" => $message));
});
$transport->initiateHandshake($uri);
$that->state = WebSocket::STATE_HANDSHAKE_SENT;
}, function ($reason) use($that) {
$that->logger->err($reason);
});
return $deferred->promise();
}
示例3: getDomain
protected function getDomain($uriString = null)
{
if ($uriString == null) {
$uriString = $this->getRequest()->getUri();
}
$uri = new Uri($uriString);
return $uri->getHost();
}
示例4: constructRedirectUri
protected function constructRedirectUri($uri = null, array $query = array())
{
$uri = new Uri($uri);
if (!empty($query)) {
$query = $uri->getQueryAsArray() + $query;
$uri->setQuery($query);
}
return $uri;
}
示例5: getFirstSegmentInPath
protected function getFirstSegmentInPath(Uri $uri, $base = null)
{
$path = $uri->getPath();
if ($base) {
$path = substr($path, strlen($base));
}
$parts = explode('/', trim($path, '/'));
$locale = array_shift($parts);
return $locale;
}
示例6: configureUri
/**
* {@inheritdoc}
*/
public function configureUri(Uri $baseUri, $name, $id = null)
{
$basePath = $baseUri->getPath();
$resourcePath = rtrim($basePath, '/') . '/' . $name;
if ($id) {
$resourcePath .= '/' . $id;
}
$baseUri->setPath($resourcePath);
return $baseUri;
}
示例7: getThumbs
/**
* Get a list of thumbs from a URI
* @param string $uri
* @param integer $limit
* @return array
*/
public function getThumbs($uri, $limit = 5)
{
$validator = new \Zend\Validator\Uri(array('allowRelative' => false));
$return = array();
if ($validator->isValid($uri)) {
$parseInfo = parent::parse($uri);
switch ($parseInfo->host) {
// Youtube.com
case "www.youtube.com":
$queryArray = array();
parse_str($parseInfo->query, $queryArray);
if (isset($queryArray['v'])) {
$return = array("http://img.youtube.com/vi/" . $queryArray['v'] . "/0.jpg", "http://img.youtube.com/vi/" . $queryArray['v'] . "/1.jpg", "http://img.youtube.com/vi/" . $queryArray['v'] . "/2.jpg", "http://img.youtube.com/vi/" . $queryArray['v'] . "/3.jpg");
}
break;
// Dailymotion.com
// Dailymotion.com
case "www.dailymotion.com":
if (strpos($parseInfo->path, "/video") !== false) {
$return = array('http://www.dailymotion.com/thumbnail' . $parseInfo->path);
}
break;
// Vimeo.com
// Vimeo.com
case "vimeo.com":
$id = str_replace("/", "", $parseInfo->path);
$data = \Zend\Json\Json::decode(file_get_contents("http://vimeo.com/api/v2/video/{$id}.json"));
$return = array($data[0]->thumbnail_medium);
break;
// others webpage
// others webpage
default:
/**
* Credit to http://www.bitrepository.com
* http://www.bitrepository.com/extract-images-from-an-url.html
*/
// Fetch page
$string = $this->fetchPage($uri);
$out = array();
// Regex for SRC Value
$image_regex_src_url = '/<img[^>]*' . 'src=[\\"|\'](.*)[\\"|\']/Ui';
preg_match_all($image_regex_src_url, $string, $out, PREG_PATTERN_ORDER);
$return = $out[1];
for ($i = 0; $i < count($return); $i++) {
$tUri = new Uri();
$parseInfoThumb = $tUri->parse($return[$i]);
if (!$parseInfoThumb->isAbsolute()) {
$return[$i] = $parseInfo->scheme . "://" . $parseInfo->host . "" . $return[$i];
}
}
}
}
// check && return
return array_slice($return, 0, $limit);
}
示例8: __construct
/**
* Constructor
*
* @param OAuth\Consumer $consumer
* @param string $url
* @param string $method
* @param array $params
*/
public function __construct($consumer, $url, $method, $params = array())
{
$this->_consumer = $consumer;
$this->_method = $method;
//normalize the uri: remove the query params
//and store them alonside the oauth and user params
$this->_uri = new \MediaCore\Uri($url);
$this->_unencodedQueryParams = $this->_uri->getQueryAsArray(true);
$this->_uri->setQuery('');
$this->_params = $params;
}
示例9: 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!');
}
}
示例10: request
/**
* @param $method
* @param $uri
* @param array $options
* @param null|bool|\Closure $successCallback
* @param null|bool|\Closure $failCallback
*
* @return bool|null|\StdClass
* @throws Exception
*/
public function request($method, $uri, $options = [], $successCallback = null, $failCallback = null)
{
if (!$successCallback && !$failCallback) {
$json = null;
// If there's no callbacks defined we assume this is a RESTful request
Logger::getInstance()->debug($method . ' ' . $uri . ' ' . json_encode($options));
$options = array_merge($this->defaultOptions, $options);
$guzzle = new GuzzleHttp\Client(['base_uri' => self::BASE_URL_REST]);
$res = $guzzle->request($method, $uri, $options);
if ($res->getHeader('content-type')[0] == 'application/json') {
$contents = $res->getBody()->getContents();
Logger::getInstance()->debug($contents);
$json = json_decode($contents);
} else {
throw new Exception("Server did not send JSON. Response was \"{$res->getBody()->getContents()}\"");
}
return $json;
} else {
// Use the STREAM API end point
$Uri = new Uri(self::BASE_URL_STREAM);
$Uri->setUserInfo($this->defaultOptions['auth'][0] . ':' . $this->defaultOptions['auth'][1]);
$Uri->setPath($uri);
if (isset($options['query'])) {
$Uri->setQuery($options['query']);
}
$WSClient = new WebSocket\Client($Uri);
Logger::getInstance()->debug($Uri);
if (!$successCallback instanceof \Closure) {
$successCallback = function ($response) {
$info = json_decode($response);
if (property_exists($info, 'output')) {
Logger::getInstance()->info(json_decode($response)->output);
} elseif ($info->type == 'error') {
// output error info
Logger::getInstance()->info($info->message);
}
};
}
if (!$failCallback instanceof \Closure) {
$failCallback = function (\Exception $exception) {
Logger::getInstance()->info($exception->getMessage());
};
}
try {
while ($response = $WSClient->receive()) {
$successCallback($response);
}
} catch (\Exception $e) {
$failCallback($e);
}
return true;
}
}
示例11: 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.';
}
示例12: isDocumentHref
public static function isDocumentHref($href)
{
if (empty($href) || stripos($href, 'mail') !== false || stripos($href, '.pdf') !== false || stripos($href, '.ppt') !== false || substr($href, 0, 10) === 'javascript' || substr($href, 0, 1) === '#') {
return false;
}
foreach (['%20', '='] as $c) {
if (stripos($href, $c . 'http://') !== false) {
return false;
}
}
$zendUri = new Uri($href);
if ($zendUri->isValid()) {
return true;
}
return false;
}
示例13: clearUri
/**
* Get clear uri.
*
* @static
*
* @param \Zend\Uri\Uri $uri
*
* @return boolean|\Zend\Uri\Uri False if uri is not auhorized
*/
public static function clearUri(Uri $uri)
{
if ($uri->getScheme() !== 'http') {
return false;
}
$query = $uri->getQueryAsArray();
if (empty($query['v'])) {
return false;
}
$uri->setQuery(array('v' => $query['v']));
$uri->setHost('www.youtube.com');
$uri->setPath('/watch');
// clear
$uri->setPort(0);
$uri->setUserInfo('');
$uri->setFragment('');
return $uri;
}
示例14: 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();
}
示例15: clearUri
/**
* Get clear uri.
*
* @static
*
* @param \Zend\Uri\Uri $uri
*
* @return boolean|\Zend\Uri\Uri False if uri is not auhorized
*/
public static function clearUri(Uri $uri)
{
if ($uri->getScheme() !== 'http') {
return false;
}
$uri->setHost('www.vimeo.com');
// clear
$uri->setPort(0);
$uri->setUserInfo('');
$uri->setQuery('');
$uri->setFragment('');
return $uri;
}