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


PHP Http::getScheme方法代码示例

本文整理汇总了PHP中Zend\Uri\Http::getScheme方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::getScheme方法的具体用法?PHP Http::getScheme怎么用?PHP Http::getScheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Uri\Http的用法示例。


在下文中一共展示了Http::getScheme方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAssembling

 public function testAssembling()
 {
     $uri = new HttpUri();
     $route = new Scheme('https');
     $path = $route->assemble(array(), array('uri' => $uri));
     $this->assertEquals('', $path);
     $this->assertEquals('https', $uri->getScheme());
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:8,代码来源:SchemeTest.php

示例2: check

 /**
  * Check if ssl is forced or not
  *
  * @param EventInterface $event Mvc event
  *
  * @return null|Zend\Http\PhpEnvironment\Response
  */
 public function check(EventInterface $event)
 {
     $coreConfig = $event->getApplication()->getServiceManager()->get('CoreConfig');
     $matchedRouteName = $event->getRouteMatch()->getMatchedRouteName();
     $request = $event->getRequest();
     $uri = $request->getUri();
     if ($matchedRouteName === 'cms') {
         if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_frontend_ssl')) {
             $newUri = new Uri($coreConfig->getValue('secure_frontend_base_path'));
             $newUri->setScheme('https');
         } else {
             $newUri = new Uri($coreConfig->getValue('unsecure_frontend_base_path'));
         }
     } else {
         if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_backend_ssl')) {
             $newUri = new Uri($coreConfig->getValue('secure_backend_base_path'));
             $newUri->setScheme('https');
         } else {
             $newUri = new Uri($coreConfig->getValue('unsecure_backend_base_path'));
         }
     }
     if (!empty($newUri) and $newUri->isValid() and ($newUri->getHost() != '' and $uri->getHost() != $newUri->getHost()) or $newUri->getScheme() != '' and $uri->getScheme() != $newUri->getScheme()) {
         $uri->setPort($newUri->getPort());
         if ($newUri->getHost() != '') {
             $uri->setHost($newUri->getHost());
         }
         if ($newUri->getScheme() != '') {
             $uri->setScheme($newUri->getScheme());
         }
         $response = $event->getResponse();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', $request->getUri());
         $event->stopPropagation();
         return $response;
     }
 }
开发者ID:gotcms,项目名称:gotcms,代码行数:43,代码来源:SslListener.php

示例3: write

 /**
  * Send request to the proxy server with streaming support
  *
  * @param string        $method
  * @param \Zend\Uri\Http $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:rexmac,项目名称:zf2,代码行数:58,代码来源:HttpAdapterStreamingProxy.php

示例4: write

 /**
  * Send request to the remote server with streaming support.
  *
  * @param string        $method
  * @param \Zend\Uri\Http $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 = '')
 {
     // Make sure we're properly connected
     if (!$this->socket) {
         throw new Adapter\Exception('Trying to write but we are not connected');
     }
     $host = $uri->getHost();
     $host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
     if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
         throw new Adapter\Exception('Trying to write but we are connected to the wrong host');
     }
     // Save request method for later
     $this->method = $method;
     // Build request headers
     $path = $uri->getPath();
     if ($uri->getQuery()) {
         $path .= '?' . $uri->getQuery();
     }
     $request = "{$method} {$path} HTTP/{$http_ver}\r\n";
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = ucfirst($k) . ": {$v}";
         }
         $request .= "{$v}\r\n";
     }
     // Send the headers over
     $request .= "\r\n";
     if (!@fwrite($this->socket, $request)) {
         throw new Adapter\Exception('Error writing request to server');
     }
     //read from $body, write to socket
     $chunk = $body->read(self::CHUNK_SIZE);
     while ($chunk !== FALSE) {
         if (!@fwrite($this->socket, $chunk)) {
             throw new Adapter\Exception('Error writing request to server');
         }
         $chunk = $body->read(self::CHUNK_SIZE);
     }
     $body->closeFileHandle();
     return 'Large upload, request is not cached.';
 }
开发者ID:rmarshall-quibids,项目名称:zf2,代码行数:51,代码来源:HttpAdapterStreamingSocket.php

示例5: assemble

 /**
  * assemble(): defined by Route interface.
  *
  * @see    BaseRoute::assemble()
  * @param  array $params
  * @param  array $options
  * @return mixed
  */
 public function assemble(array $params = array(), array $options = array())
 {
     if (!isset($options['name'])) {
         throw new Exception\InvalidArgumentException('Missing "name" option');
     }
     $names = explode('/', $options['name'], 2);
     $route = $this->routes->get($names[0]);
     if (!$route) {
         throw new Exception\RuntimeException(sprintf('Route with name "%s" not found', $names[0]));
     }
     if (isset($names[1])) {
         $options['name'] = $names[1];
     } else {
         unset($options['name']);
     }
     if (!isset($options['uri'])) {
         $uri = new HttpUri();
         if (isset($options['absolute']) && $options['absolute']) {
             if ($this->requestUri === null) {
                 throw new Exception\RuntimeException('Request URI has not been set');
             }
             $uri->setScheme($this->requestUri->getScheme())->setHost($this->requestUri->getHost())->setPort($this->requestUri->getPort());
         }
         $options['uri'] = $uri;
     }
     $path = $this->baseUrl . $route->assemble($params, $options);
     if (isset($uri)) {
         if (isset($options['absolute']) && $options['absolute']) {
             return $uri->setPath($path)->toString();
         } elseif ($uri->getHost() !== null) {
             if ($uri->scheme !== null) {
                 if ($this->requestUri === null) {
                     throw new Exception\RuntimeException('Request URI has not been set');
                 }
                 $uri->setScheme($this->requestUri->getScheme());
             }
             return $uri->setPath($path)->toString();
         }
     }
     return $path;
 }
开发者ID:nsenkevich,项目名称:zf2,代码行数:49,代码来源:TreeRouteStack.php

示例6: testValidScheme

 /**
  * Test that specific schemes are valid for this class
  *
  * @param string $scheme
  * @dataProvider validSchemeProvider
  */
 public function testValidScheme($scheme)
 {
     $uri = new HttpUri;
     $uri->setScheme($scheme);
     $this->assertEquals($scheme, $uri->getScheme());
 }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:12,代码来源:HttpTest.php

示例7: assemble

 /**
  * assemble(): defined by Route interface.
  *
  * @see    Route::assemble()
  *
  * @param  array $params
  * @param  array $options
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @return string
  */
 public function assemble(array $params = array(), array $options = array())
 {
     if (!isset($options['name'])) {
         throw new Exception\InvalidArgumentException('Missing "name" option');
     }
     $names = explode('/', $options['name'], 2);
     $route = $this->routes->get($names[0]);
     /**#@+
      *  Load extra routes if called route not found in current route list
      */
     if (!$route) {
         $route = $this->extraRoute($names[0]);
     }
     /**#@-**/
     if (!$route) {
         throw new Exception\RuntimeException(sprintf('Route with name "%s" not found', $names[0]));
     }
     if (isset($names[1])) {
         if (!$route instanceof TreeRouteStack) {
             throw new Exception\RuntimeException(sprintf('Route with name "%s" does not have child routes', $names[0]));
         }
         $options['name'] = $names[1];
     } else {
         unset($options['name']);
     }
     if (isset($options['only_return_path']) && $options['only_return_path']) {
         return $this->baseUrl . $route->assemble(array_merge($this->defaultParams, $params), $options);
     }
     if (!isset($options['uri'])) {
         $uri = new HttpUri();
         if (isset($options['force_canonical']) && $options['force_canonical']) {
             if ($this->requestUri === null) {
                 throw new Exception\RuntimeException('Request URI has not been set');
             }
             $uri->setScheme($this->requestUri->getScheme())->setHost($this->requestUri->getHost())->setPort($this->requestUri->getPort());
         }
         $options['uri'] = $uri;
     } else {
         $uri = $options['uri'];
     }
     $path = $this->baseUrl . $route->assemble(array_merge($this->defaultParams, $params), $options);
     if (isset($options['query'])) {
         $uri->setQuery($options['query']);
     }
     if (isset($options['fragment'])) {
         $uri->setFragment($options['fragment']);
     }
     if (isset($options['force_canonical']) && $options['force_canonical'] || $uri->getHost() !== null || $uri->getScheme() !== null) {
         if (($uri->getHost() === null || $uri->getScheme() === null) && $this->requestUri === null) {
             throw new Exception\RuntimeException('Request URI has not been set');
         }
         if ($uri->getHost() === null) {
             $uri->setHost($this->requestUri->getHost());
         }
         if ($uri->getScheme() === null) {
             $uri->setScheme($this->requestUri->getScheme());
         }
         return $uri->setPath($path)->normalize()->toString();
     } elseif (!$uri->isAbsolute() && $uri->isValidRelative()) {
         return $uri->setPath($path)->normalize()->toString();
     }
     return $path;
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:75,代码来源:TreeRouteStack.php

示例8: prepareHeaders

 /**
  * Prepare the request headers
  *
  * @param resource|string $body
  * @param Http $uri
  * @throws Exception\RuntimeException
  * @return array
  */
 protected function prepareHeaders($body, $uri)
 {
     $headers = array();
     // Set the host header
     if ($this->config['httpversion'] == Request::VERSION_11) {
         $host = $uri->getHost();
         // If the port is not default, add it
         if (!($uri->getScheme() == 'http' && $uri->getPort() == 80 || $uri->getScheme() == 'https' && $uri->getPort() == 443)) {
             $host .= ':' . $uri->getPort();
         }
         $headers['Host'] = $host;
     }
     // Set the connection header
     if (!$this->getRequest()->getHeaders()->has('Connection')) {
         if (!$this->config['keepalive']) {
             $headers['Connection'] = 'close';
         }
     }
     // Set the Accept-encoding header if not set - depending on whether
     // zlib is available or not.
     if (!$this->getRequest()->getHeaders()->has('Accept-Encoding')) {
         if (function_exists('gzinflate')) {
             $headers['Accept-Encoding'] = 'gzip, deflate';
         } else {
             $headers['Accept-Encoding'] = 'identity';
         }
     }
     // Set the user agent header
     if (!$this->getRequest()->getHeaders()->has('User-Agent') && isset($this->config['useragent'])) {
         $headers['User-Agent'] = $this->config['useragent'];
     }
     // Set HTTP authentication if needed
     if (!empty($this->auth)) {
         switch ($this->auth['type']) {
             case self::AUTH_BASIC:
                 $auth = $this->calcAuthDigest($this->auth['user'], $this->auth['password'], $this->auth['type']);
                 if ($auth !== false) {
                     $headers['Authorization'] = 'Basic ' . $auth;
                 }
                 break;
             case self::AUTH_DIGEST:
                 throw new Exception\RuntimeException("The digest authentication is not implemented yet");
         }
     }
     // Content-type
     $encType = $this->getEncType();
     if (!empty($encType)) {
         $headers['Content-Type'] = $encType;
     }
     if (!empty($body)) {
         if (is_resource($body)) {
             $fstat = fstat($body);
             $headers['Content-Length'] = $fstat['size'];
         } else {
             $headers['Content-Length'] = strlen($body);
         }
     }
     // Merge the headers of the request (if any)
     // here we need right 'http field' and not lowercase letters
     $requestHeaders = $this->getRequest()->getHeaders();
     foreach ($requestHeaders as $requestHeaderElement) {
         $headers[$requestHeaderElement->getFieldName()] = $requestHeaderElement->getFieldValue();
     }
     return $headers;
 }
开发者ID:tillk,项目名称:vufind,代码行数:73,代码来源:Client.php

示例9: send

 /**
  * Send HTTP request
  *
  * @param  Request $request
  * @return Response
  */
 public function send(Request $request = null)
 {
     if ($request !== null) {
         $this->setRequest($request);
     }
     $this->redirectCounter = 0;
     $response = null;
     // Make sure the adapter is loaded
     if ($this->adapter == null) {
         $this->setAdapter($this->config['adapter']);
     }
     // Send the first request. If redirected, continue.
     do {
         // uri
         $uri = $this->getUri();
         // query
         $query = $this->getRequest()->query();
         if (!empty($query)) {
             $queryArray = $query->toArray();
             if (!empty($queryArray)) {
                 $newUri = $uri->toString();
                 $queryString = http_build_query($query);
                 if ($this->config['rfc3986strict']) {
                     $queryString = str_replace('+', '%20', $queryString);
                 }
                 if (strpos($newUri, '?') !== false) {
                     $newUri .= '&' . $queryString;
                 } else {
                     $newUri .= '?' . $queryString;
                 }
                 $uri = new \Zend\Uri\Http($newUri);
             }
         }
         // If we have no ports, set the defaults
         if (!$uri->getPort()) {
             $uri->setPort($uri->getScheme() == 'https' ? 443 : 80);
         }
         // method
         $method = $this->getRequest()->getMethod();
         // body
         $body = $this->prepareBody();
         // headers
         $headers = $this->prepareHeaders($body, $uri);
         $secure = $uri->getScheme() == 'https' ? true : false;
         // cookies
         $cookie = $this->prepareCookies($uri->getHost(), $uri->getPath(), $secure);
         if ($cookie->getFieldValue()) {
             $headers['Cookie'] = $cookie->getFieldValue();
         }
         // check that adapter supports streaming before using it
         if (is_resource($body) && !$this->adapter instanceof Client\Adapter\Stream) {
             throw new Client\Exception\RuntimeException('Adapter does not support streaming');
         }
         // Open the connection, send the request and read the response
         $this->adapter->connect($uri->getHost(), $uri->getPort(), $secure);
         if ($this->config['outputstream']) {
             if ($this->adapter instanceof Client\Adapter\Stream) {
                 $stream = $this->openTempStream();
                 $this->adapter->setOutputStream($stream);
             } else {
                 throw new Exception\RuntimeException('Adapter does not support streaming');
             }
         }
         // HTTP connection
         $this->lastRawRequest = $this->adapter->write($method, $uri, $this->config['httpversion'], $headers, $body);
         $response = $this->adapter->read();
         if (!$response) {
             throw new Exception\RuntimeException('Unable to read response, or response is empty');
         }
         if ($this->config['storeresponse']) {
             $this->lastRawResponse = $response;
         } else {
             $this->lastRawResponse = null;
         }
         if ($this->config['outputstream']) {
             $streamMetaData = stream_get_meta_data($stream);
             if ($streamMetaData['seekable']) {
                 rewind($stream);
             }
             // cleanup the adapter
             $this->adapter->setOutputStream(null);
             $response = Response\Stream::fromStream($response, $stream);
             $response->setStreamName($this->streamName);
             if (!is_string($this->config['outputstream'])) {
                 // we used temp name, will need to clean up
                 $response->setCleanup(true);
             }
         } else {
             $response = Response::fromString($response);
         }
         // Get the cookies from response (if any)
         $setCookie = $response->cookie();
         if (!empty($setCookie)) {
             $this->addCookie($setCookie);
//.........这里部分代码省略.........
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:101,代码来源:Client.php

示例10: send

 /**
  * Send HTTP request
  *
  * @param  Request $request
  * @return Response
  * @throws Exception\RuntimeException
  * @throws Client\Exception\RuntimeException
  */
 public function send(Request $request = null)
 {
     if ($request !== null) {
         $this->setRequest($request);
     }
     $this->redirectCounter = 0;
     $response = null;
     // Make sure the adapter is loaded
     if ($this->adapter == null) {
         $this->setAdapter($this->config['adapter']);
     }
     // if there are no files attach then use the standard sending
     $files = $request->getFiles();
     if (!count($files)) {
         return parent::send($request);
     }
     if (!$this->adapter instanceof Adapter\DirectWriteInterface) {
         throw new ZendClient\Exception\RuntimeException('Adapter must implement DirectWriteInterface');
     }
     // Send the first request. If redirected, continue.
     do {
         // uri
         $uri = $this->getUri();
         // query
         $query = $this->getRequest()->getQuery();
         if (!empty($query)) {
             $queryArray = $query->toArray();
             if (!empty($queryArray)) {
                 $newUri = $uri->toString();
                 $queryString = http_build_query($query, null, $this->getArgSeparator());
                 if ($this->config['rfc3986strict']) {
                     $queryString = str_replace('+', '%20', $queryString);
                 }
                 if (strpos($newUri, '?') !== false) {
                     $newUri .= $this->getArgSeparator() . $queryString;
                 } else {
                     $newUri .= '?' . $queryString;
                 }
                 $uri = new Http($newUri);
             }
         }
         // If we have no ports, set the defaults
         if (!$uri->getPort()) {
             $uri->setPort($uri->getScheme() == 'https' ? 443 : 80);
         }
         // method
         $method = $this->getRequest()->getMethod();
         // headers
         $headers = $this->prepareHeaders(null, $uri);
         $headers['Transfer-Encoding'] = 'chunked';
         $secure = $uri->getScheme() == 'https';
         $debugCookies = "debug_host=127.0.0.1&debug_port=10137&start_debug=1&send_debug_header=1&send_sess_end=1&debug_jit=1&debug_stop=1&use_remote=1&debug_session_id=1212593";
         $cookies = array();
         parse_str($debugCookies, $cookies);
         foreach ($cookies as $name => $value) {
             $this->addCookie($name, $value);
         }
         // cookies
         $cookie = $this->prepareCookies($uri->getHost(), $uri->getPath(), $secure);
         if ($cookie->getFieldValue()) {
             $headers['Cookie'] = $cookie->getFieldValue();
         }
         $body = $this->prepareBody();
         if ($this->boundary) {
             $headers['Content-Type'] .= "; boundary=" . $this->boundary;
         }
         // calling protected method to allow extending classes
         // to wrap the interaction with the adapter
         $response = $this->doRequest($uri, $method, $secure, $headers, $body);
         if (!$response) {
             throw new Exception\RuntimeException('Unable to read response, or response is empty');
         }
         if ($this->config['storeresponse']) {
             $this->lastRawResponse = $response;
         } else {
             $this->lastRawResponse = null;
         }
         if ($this->config['outputstream']) {
             $stream = $this->getStream();
             if (!is_resource($stream) && is_string($stream)) {
                 $stream = fopen($stream, 'r');
             }
             $streamMetaData = stream_get_meta_data($stream);
             if ($streamMetaData['seekable']) {
                 rewind($stream);
             }
             // cleanup the adapter
             $this->adapter->setOutputStream(null);
             $response = Response\Stream::fromStream($response, $stream);
             $response->setStreamName($this->streamName);
             if (!is_string($this->config['outputstream'])) {
                 // we used temp name, will need to clean up
//.........这里部分代码省略.........
开发者ID:Karl-Dawson,项目名称:ZendServerWebApiModule,代码行数:101,代码来源:ChunkedClient.php


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