当前位置: 首页>>代码示例>>PHP>>正文


PHP Uri\Uri类代码示例

本文整理汇总了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);
 }
开发者ID:pokap,项目名称:media,代码行数:30,代码来源:Media.php

示例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();
 }
开发者ID:usmanhalalit,项目名称:phpws,代码行数:60,代码来源:WebSocket.php

示例3: getDomain

 protected function getDomain($uriString = null)
 {
     if ($uriString == null) {
         $uriString = $this->getRequest()->getUri();
     }
     $uri = new Uri($uriString);
     return $uri->getHost();
 }
开发者ID:netsensia,项目名称:zf2-foundation,代码行数:8,代码来源:ProvidesHttpUtils.php

示例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;
 }
开发者ID:ivan-novakov,项目名称:zf2-openid-connect-server-module,代码行数:9,代码来源:AbstractAuthorizeResponse.php

示例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;
 }
开发者ID:milqmedia,项目名称:mq-locale,代码行数:10,代码来源:UrlStrategy.php

示例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;
 }
开发者ID:matryoshka-model,项目名称:rest-wrapper,代码行数:13,代码来源:DefaultStrategy.php

示例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);
 }
开发者ID:remithomas,项目名称:rt-extends,代码行数:61,代码来源:Thumb.php

示例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;
 }
开发者ID:mediacore,项目名称:mediacore-client-php,代码行数:19,代码来源:Request.php

示例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!');
     }
 }
开发者ID:risinglf,项目名称:UniversiBO,代码行数:12,代码来源:UniversiboSSOExtension.php

示例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;
     }
 }
开发者ID:allansun,项目名称:docker-cloud-php-api,代码行数:63,代码来源:Client.php

示例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.';
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:58,代码来源:HttpAdapterStreamingProxy.php

示例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;
 }
开发者ID:eduardohayashi,项目名称:camel-webspider,代码行数:16,代码来源:SpiderAsserts.php

示例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;
 }
开发者ID:pokap,项目名称:media,代码行数:27,代码来源:Youtube.php

示例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();
 }
开发者ID:publicitas-deployment,项目名称:php-openid-connect-client,代码行数:26,代码来源:Generator.php

示例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;
 }
开发者ID:pokap,项目名称:media,代码行数:22,代码来源:Vimeo.php


注:本文中的Zend\Uri\Uri类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。