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


PHP Http::setPort方法代码示例

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


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

示例1: testReloadExtractsURIFromEditLink

 public function testReloadExtractsURIFromEditLink()
 {
     $expectedUri = 'http://www.example.com:81';
     $etag = Etag::fromString('Etag: ABCD1234');
     $this->service->setMajorProtocolVersion(2);
     $this->adapter->setResponse($this->httpEntrySample);
     $entry = $this->service->newEntry();
     $entry->link = array(new Extension\Link($expectedUri, 'edit', 'application/atom+xml'));
     $entry->setEtag($etag);
     $newEntry = $entry->reload();
     $requestUri = $this->adapter->popRequest()->uri;
     $expectedUriObject = new Uri\Http($expectedUri);
     $expectedUriObject->setPort('81');
     $this->assertEquals($expectedUriObject, $requestUri);
 }
开发者ID:rcknr,项目名称:ZendGData,代码行数:15,代码来源:EntryTest.php

示例2: setServer

    /**
     * Provide an alternate Parameter Container implementation for server parameters in this object,
     * (this is NOT the primary API for value setting, for that see getServer())
     *
     * @param  ParametersInterface $server
     * @return Request
     */
    public function setServer(ParametersInterface $server)
    {
        $this->serverParams = $server;

        // This seems to be the only way to get the Authorization header on Apache
        if (function_exists('apache_request_headers')) {
            $apacheRequestHeaders = apache_request_headers();
            if (!isset($this->serverParams['HTTP_AUTHORIZATION'])) {
                if (isset($apacheRequestHeaders['Authorization'])) {
                    $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['Authorization']);
                } elseif (isset($apacheRequestHeaders['authorization'])) {
                    $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['authorization']);
                }
            }
        }

        // set headers
        $headers = array();

        foreach ($server as $key => $value) {
            if ($value && strpos($key, 'HTTP_') === 0) {
                if (strpos($key, 'HTTP_COOKIE') === 0) {
                    // Cookies are handled using the $_COOKIE superglobal
                    continue;
                }
                $name = strtr(substr($key, 5), '_', ' ');
                $name = strtr(ucwords(strtolower($name)), ' ', '-');
            } elseif ($value && strpos($key, 'CONTENT_') === 0) {
                $name = substr($key, 8); // Content-
                $name = 'Content-' . (($name == 'MD5') ? $name : ucfirst(strtolower($name)));
            } else {
                continue;
            }

            $headers[$name] = $value;
        }

        $this->getHeaders()->addHeaders($headers);

        // set method
        if (isset($this->serverParams['REQUEST_METHOD'])) {
            $this->setMethod($this->serverParams['REQUEST_METHOD']);
        }

        // set HTTP version
        if (isset($this->serverParams['SERVER_PROTOCOL'])
            && strpos($this->serverParams['SERVER_PROTOCOL'], self::VERSION_10) !== false
        ) {
            $this->setVersion(self::VERSION_10);
        }

        // set URI
        $uri = new HttpUri();

        // URI scheme
        $scheme = (!empty($this->serverParams['HTTPS'])
                   && $this->serverParams['HTTPS'] !== 'off') ? 'https' : 'http';
        $uri->setScheme($scheme);

        // URI host & port
        $host = null;
        $port = null;
        if (isset($this->serverParams['SERVER_NAME'])) {
            $host = $this->serverParams['SERVER_NAME'];
            if (isset($this->serverParams['SERVER_PORT'])) {
                $port = (int) $this->serverParams['SERVER_PORT'];
            }
            // Check for missinterpreted IPv6-Address
            // Reported at least for Safari on Windows
            if (isset($this->serverParams['SERVER_ADDR']) && preg_match('/^\[[0-9a-fA-F\:]+\]$/', $host)) {
                $host = '[' . $this->serverParams['SERVER_ADDR'] . ']';
                if ($port . ']' == substr($host, strrpos($host, ':')+1)) {
                    // The last digit of the IPv6-Address has been taken as port
                    // Unset the port so the default port can be used
                    $port = null;
                }
            }
        } elseif ($this->getHeaders()->get('host')) {
            $host = $this->getHeaders()->get('host')->getFieldValue();
            // works for regname, IPv4 & IPv6
            if (preg_match('|\:(\d+)$|', $host, $matches)) {
                $host = substr($host, 0, -1 * (strlen($matches[1]) + 1));
                $port = (int) $matches[1];
            }
        }
        $uri->setHost($host);
        $uri->setPort($port);

        // URI path
        $requestUri = $this->getRequestUri();
        if (($qpos = strpos($requestUri, '?')) !== false) {
            $requestUri = substr($requestUri, 0, $qpos);
        }
//.........这里部分代码省略.........
开发者ID:Robert-Xie,项目名称:php-framework-benchmark,代码行数:101,代码来源:Request.php

示例3: 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;
     $adapter = $this->getAdapter();
     // 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($queryArray, 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();
         // this is so the correct Encoding Type is set
         $this->setMethod($method);
         // body
         $body = $this->prepareBody();
         // headers
         $headers = $this->prepareHeaders($body, $uri);
         $secure = $uri->getScheme() == 'https';
         // 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) && !$adapter instanceof Client\Adapter\StreamInterface) {
             throw new Client\Exception\RuntimeException('Adapter does not support streaming');
         }
         // 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
             $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 = $this->getResponse()->fromString($response);
         }
         // Get the cookies from response (if any)
         $setCookies = $response->getCookie();
         if (!empty($setCookies)) {
             $this->addCookie($setCookies);
         }
         // If we got redirected, look for the Location header
         if ($response->isRedirect() && $response->getHeaders()->has('Location')) {
             // Avoid problems with buggy servers that add whitespace at the
             // end of some headers
//.........这里部分代码省略.........
开发者ID:tillk,项目名称:vufind,代码行数:101,代码来源:Client.php

示例4: setRequestUri

 /**
  * Sets the Request Uri object
  *
  * @param array $parameters Url construction parameter array
  *
  * @return void
  */
 protected function setRequestUri(array $parameters = array())
 {
     // Getting base uri according to the uri construction method
     $uri = $this->constructActionUrl($parameters);
     // Converting it into a Zend Http Uri object
     $httpUri = new Http($uri);
     $httpUri->setPort($this->port);
     // Setting request uri object
     $this->setUri($httpUri);
 }
开发者ID:mslib,项目名称:remote-host,代码行数:17,代码来源:AbstractActionRequest.php

示例5: setServer

 /**
  * Provide an alternate Parameter Container implementation for server parameters in this object, (this is NOT the
  * primary API for value setting, for that see server())
  *
  * @param \Zend\Stdlib\ParametersDescription $server
  * @return Request
  */
 public function setServer(ParametersDescription $server)
 {
     $this->serverParams = $server;
     $this->headers()->addHeaders($this->serverToHeaders($this->serverParams));
     if (isset($this->serverParams['REQUEST_METHOD'])) {
         $this->setMethod($this->serverParams['REQUEST_METHOD']);
     }
     if (isset($this->serverParams['SERVER_PROTOCOL']) && strpos($this->serverParams['SERVER_PROTOCOL'], '1.0') !== false) {
         $this->setVersion('1.0');
     }
     $this->setUri($uri = new HttpUri());
     if (isset($this->serverParams['HTTPS']) && $this->serverParams['HTTPS'] === 'on') {
         $uri->setScheme('https');
     } else {
         $uri->setScheme('http');
     }
     if (isset($this->serverParams['QUERY_STRING'])) {
         $uri->setQuery($this->serverParams['QUERY_STRING']);
     }
     if ($this->headers()->get('host')) {
         //TODO handle IPv6 with port
         if (preg_match('|^([^:]+):([^:]+)$|', $this->headers()->get('host')->getFieldValue(), $match)) {
             $uri->setHost($match[1]);
             $uri->setPort($match[2]);
         } else {
             $uri->setHost($this->headers()->get('host')->getFieldValue());
         }
     } elseif (isset($this->serverParams['SERVER_NAME'])) {
         $uri->setHost($this->serverParams['SERVER_NAME']);
         if (isset($this->serverParams['SERVER_PORT'])) {
             $uri->setPort($this->serverParams['SERVER_PORT']);
         }
     }
     $requestUri = $this->getRequestUri();
     $uri->setPath(substr($requestUri, 0, strpos($requestUri, '?') ?: strlen($requestUri)));
     return $this;
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:44,代码来源:Request.php

示例6: setServer

 public function setServer(ParametersInterface $server)
 {
     $this->serverParams = $server;
     // This seems to be the only way to get the Authorization header on Apache
     if (function_exists('apache_request_headers')) {
         $apacheRequestHeaders = apache_request_headers();
         if (!isset($this->serverParams['HTTP_AUTHORIZATION'])) {
             if (isset($apacheRequestHeaders['Authorization'])) {
                 $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['Authorization']);
             } elseif (isset($apacheRequestHeaders['authorization'])) {
                 $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['authorization']);
             }
         }
     }
     // set headers
     $headers = array();
     foreach ($server as $key => $value) {
         if ($value && strpos($key, 'HTTP_') === 0) {
             if (strpos($key, 'HTTP_COOKIE') === 0) {
                 // Cookies are handled using the $_COOKIE superglobal
                 continue;
             }
             $name = strtr(substr($key, 5), '_', ' ');
             $name = strtr(ucwords(strtolower($name)), ' ', '-');
         } elseif ($value && strpos($key, 'CONTENT_') === 0) {
             $name = substr($key, 8);
             // Content-
             $name = 'Content-' . ($name == 'MD5' ? $name : ucfirst(strtolower($name)));
         } else {
             continue;
         }
         $headers[$name] = $value;
     }
     $this->getHeaders()->addHeaders($headers);
     // set method
     if (isset($this->serverParams['REQUEST_METHOD'])) {
         $this->setMethod($this->serverParams['REQUEST_METHOD']);
     }
     // set HTTP version
     if (isset($this->serverParams['SERVER_PROTOCOL']) && strpos($this->serverParams['SERVER_PROTOCOL'], self::VERSION_10) !== false) {
         $this->setVersion(self::VERSION_10);
     }
     // set URI
     $uri = new HttpUri();
     // URI scheme
     if (!empty($this->serverParams['HTTPS']) && $this->serverParams['HTTPS'] !== 'off' || !empty($this->serverParams['HTTP_X_FORWARDED_PROTO']) && $this->serverParams['HTTP_X_FORWARDED_PROTO'] == 'https') {
         $scheme = 'https';
     } else {
         $scheme = 'http';
     }
     $uri->setScheme($scheme);
     // URI host & port
     $uri->setHost($this->serverParams['SERVER_NAME']);
     $uri->setPort($this->serverParams['SERVER_PORT']);
     // URI path
     if (isset($this->serverParams['REQUEST_URI'])) {
         $this->setRequestUri($this->serverParams['REQUEST_URI']);
     }
     $requestUri = $this->getRequestUri();
     if (($qpos = strpos($requestUri, '?')) !== false) {
         $requestUri = substr($requestUri, 0, $qpos);
     }
     $uri->setPath($requestUri);
     // URI query
     if (isset($this->serverParams['QUERY_STRING'])) {
         $uri->setQuery($this->serverParams['QUERY_STRING']);
     }
     $this->setUri($uri);
     return $this;
 }
开发者ID:moln,项目名称:gzfextra,代码行数:70,代码来源:Request.php


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