php Zend-Uri-Uri类(方法)实例源码

下面列出了php Zend-Uri-Uri 类(方法)源码代码实例,从而了解它的用法。

作者:poka    项目:medi   
/**
  * @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);
 }

作者:usmanhalali    项目:phpw   
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();
 }

作者:netsensi    项目:zf2-foundatio   
protected function getDomain($uriString = null)
 {
     if ($uriString == null) {
         $uriString = $this->getRequest()->getUri();
     }
     $uri = new Uri($uriString);
     return $uri->getHost();
 }

作者:ivan-novako    项目:zf2-openid-connect-server-modul   
protected function constructRedirectUri($uri = null, array $query = array())
 {
     $uri = new Uri($uri);
     if (!empty($query)) {
         $query = $uri->getQueryAsArray() + $query;
         $uri->setQuery($query);
     }
     return $uri;
 }

作者:milqmedi    项目:mq-local   
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;
 }

作者:matryoshka-mode    项目:rest-wrappe   
/**
  * {@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;
 }

作者:remithoma    项目:rt-extend   
/**
  * 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);
 }

作者:mediacor    项目:mediacore-client-ph   
/**
  * 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;
 }

作者:risingl    项目:UniversiB   
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!');
     }
 }

作者:allansu    项目:docker-cloud-php-ap   
/**
  * @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;
     }
 }

作者:rafalwrzeszc    项目:zf   
/**
  * 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.';
 }

作者:eduardohayash    项目:camel-webspide   
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;
 }

作者:poka    项目:medi   
/**
  * 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;
 }

作者:publicitas-deploymen    项目:php-openid-connect-clien   
/**
  * 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();
 }

作者:poka    项目:medi   
/**
  * 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;
 }

作者:parrotcag    项目:ave   
/**
  * 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;
 }

作者:poka    项目:medi   
/**
  * 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;
     }
     $paths = explode('/', $uri->getPath());
     $pathsCount = count($paths);
     if ($pathsCount < 2) {
         return false;
     }
     $type = $paths[$pathsCount - 2];
     if (!in_array($type, self::$typesAuthorized)) {
         return false;
     }
     $uri->setHost('www.deezer.com');
     // clear
     $uri->setPort(0);
     $uri->setUserInfo('');
     $uri->setQuery('');
     $uri->setFragment('');
     return $uri;
 }

作者:shinesoftwar    项目:GoogleMap   
/**
  * 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;
 }

作者:remithoma    项目:rt-extend   
/**
  * 
  * @param string $uri
  * @return string
  */
 public function getType($uri)
 {
     $validator = new \Zend\Validator\Uri(array('allowRelative' => false));
     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 self::TYPE_VIDEO_YOUTUBE;
                 }
                 break;
                 // Dailymotion.com
             // Dailymotion.com
             case "www.dailymotion.com":
                 if (strpos($parseInfo->path, "/video") !== false) {
                     return self::TYPE_VIDEO_DAILYMOTION;
                 }
                 break;
                 // Vimeo.com
             // Vimeo.com
             case "vimeo.com":
                 if (is_int($parseInfo->path)) {
                     return self::TYPE_VIDEO_VIMEO;
                 }
                 break;
         }
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $uri);
         curl_setopt($ch, CURLOPT_HEADER, TRUE);
         curl_setopt($ch, CURLOPT_NOBODY, TRUE);
         // remove body
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         $head = curl_exec($ch);
         $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
         curl_close($ch);
         if (strpos($contentType, "image") !== false) {
             return self::TYPE_IMAGE;
         } else {
             if ($contentType == "application/x-shockwave-flash") {
                 return self::TYPE_SWF;
             }
         }
         return self::TYPE_WEBPAGE;
     } else {
         return "";
     }
 }

作者:bradley-hol    项目:zf   
/**
  * Validates if a string is valid as a sitemap location
  *
  * @link http://www.sitemaps.org/protocol.php#locdef <loc>
  *
  * @param  string  $value  value to validate
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     $this->_setValue($value);
     $result = \Zend\Uri\Uri::check($value);
     if ($result !== true) {
         $this->_error(self::NOT_VALID);
         return false;
     }
     return true;
 }


问题


面经


文章

微信
公众号

扫码关注公众号