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


PHP Http::setScheme方法代码示例

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


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

示例1: testUseRequestBaseUrl

 public function testUseRequestBaseUrl()
 {
     $this->configureRoute();
     $httpUri = new HttpUri();
     $httpUri->setScheme('http');
     $httpUri->setHost('use-request-uri.com');
     $request = $this->serviceManager->get('Request');
     $request->setUri($httpUri);
     $request->setBaseUrl('/another/base/url/');
     $baseUrl = $this->factory->getBaseUrl($this->serviceManager);
     $this->assertEquals('http://use-request-uri.com/another/base/url/scn-social-auth/hauth', $baseUrl);
 }
开发者ID:aapthi,项目名称:video-collections,代码行数:12,代码来源:HybridAuthFactoryTest.php

示例2: __invoke

 public function __invoke()
 {
     $request = $this->getController()->getRequest();
     if ('https' === $request->getUri()->getScheme()) {
         return;
     }
     // Not secure, create full url
     $plugin = $this->getController()->url();
     $url = $plugin->fromRoute(null, array(), array('force_canonical' => true), true);
     $url = new HttpUri($url);
     $url->setScheme('https');
     return $this->getController()->redirect()->toUrl($url);
 }
开发者ID:JonathanConner,项目名称:SocialNet,代码行数:13,代码来源:ForceHttps.php

示例3: 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

示例4: assemble

 /**
  * assemble(): defined by \Zend\Mvc\Router\RouteInterface interface.
  *
  * @see    \Zend\Mvc\Router\RouteInterface::assemble()
  * @param  array $params
  * @param  array $options
  * @return mixed
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 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['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) {
         if ($uri->getScheme() === null) {
             if ($this->requestUri === null) {
                 throw new Exception\RuntimeException('Request URI has not been set');
             }
             $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:razvansividra,项目名称:pnlzf2-1,代码行数:60,代码来源:TreeRouteStack.php

示例5: testAssembleCanonicalUriWithHostnameRouteAndRequestUriWithoutScheme

 public function testAssembleCanonicalUriWithHostnameRouteAndRequestUriWithoutScheme()
 {
     $uri = new HttpUri();
     $uri->setScheme('http');
     $stack = new TreeRouteStack();
     $stack->setRequestUri($uri);
     $stack->addRoute('foo', new Hostname('example.com'));
     $this->assertEquals('http://example.com', $stack->assemble(array(), array('name' => 'foo')));
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:9,代码来源:TreeRouteStackTest.php

示例6: testAssembleWithQueryRoute

 public function testAssembleWithQueryRoute()
 {
     $uri = new HttpUri();
     $uri->setScheme('http');
     $stack = new TreeRouteStack();
     $stack->setRequestUri($uri);
     $stack->addRoute('index', array('type' => 'Literal', 'options' => array('route' => '/'), 'child_routes' => array('query' => array('type' => 'Query'))));
     $this->assertEquals('/?bar=baz', $stack->assemble(array('bar' => 'baz'), array('name' => 'index/query')));
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:9,代码来源:TreeRouteStackTest.php

示例7: 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

示例8: testInvalidScheme

 /**
  * Test that specific schemes are invalid for this class
  *
  * @param string $scheme
  * @dataProvider invalidSchemeProvider
  */
 public function testInvalidScheme($scheme)
 {
     $uri = new HttpUri;
     $this->setExpectedException('Zend\Uri\Exception\InvalidUriPartException');
     $uri->setScheme($scheme);
 }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:12,代码来源:HttpTest.php

示例9: 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

示例10: getWebsiteUri

 /**
  * Return the base website URI
  *
  * Either returns whatever was configured, or works it out from the current request
  * @return HttpUri
  */
 public function getWebsiteUri()
 {
     if ($this->website) {
         return $this->website;
     }
     $uri = $this->getOptions()->getWebsiteUrl();
     if (!empty($uri)) {
         $website = new HttpUri($uri);
     } else {
         $website = new HttpUri();
         if (isset($_SERVER['HTTP_HOST'])) {
             $website->setHost($_SERVER['HTTP_HOST']);
         }
         $website->setScheme('http');
         if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' || isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
             $website->setScheme('https');
         }
     }
     if (!$website->isValid()) {
         throw new Exception\RuntimeException('Cannot determine current host');
     }
     $this->website = $website;
     return $website;
 }
开发者ID:netglue,项目名称:zf2-akismet-module,代码行数:30,代码来源:AkismetService.php

示例11: 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

示例12: testAssembleWithScheme

 public function testAssembleWithScheme()
 {
     $uri   = new HttpUri();
     $uri->setScheme('http');
     $uri->setHost('example.com');
     $stack = new TreeRouteStack();
     $stack->setRequestUri($uri);
     $stack->addRoute(
         'secure',
         array(
             'type' => 'Scheme',
             'options' => array(
                 'scheme' => 'https'
             ),
             'child_routes' => array(
                 'index' => array(
                     'type'    => 'Literal',
                     'options' => array(
                         'route'    => '/',
                     ),
                 ),
             ),
         )
     );
     $this->assertEquals('https://example.com/', $stack->assemble(array(), array('name' => 'secure/index')));
 }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:26,代码来源:TreeRouteStackTest.php

示例13: 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

示例14: assemble

 /**
  * assemble(): defined by \Zend\Mvc\Router\RouteInterface interface.
  *
  * @see    \Zend\Mvc\Router\RouteInterface::assemble()
  * @param  array $params
  * @param  array $options
  * @return mixed
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 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])) {
         if (!$route instanceof TreeRouteStack) {
             //die("DEBUG: route is " . gettype($route));
             throw new Exception\RuntimeException(sprintf('Route with name "%s" does not have child routes', $names[0]));
         }
         $options['name'] = $names[1];
     } else {
         unset($options['name']);
     }
     // Translator options
     if ($this->hasTranslator() && $this->isTranslatorEnabled()) {
         $options['translator'] = isset($options['translator']) ? $options['translator'] : $this->getTranslator();
         $options['text_domain'] = isset($options['text_domain']) ? $options['text_domain'] : $this->getTranslatorTextDomain();
         $options['locale'] = isset($options['locale']) ? $options['locale'] : str_replace('-', '_', $this->localeManager->getLocale());
     }
     if (isset($options['only_return_path']) && $options['only_return_path']) {
         return $this->getBaseUrlWithLocale($options['locale']) . $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->getBaseUrlWithLocale($options['locale']) . $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:JPG-Consulting,项目名称:LocaleManager-OLD,代码行数:73,代码来源:LocaleTreeRouteStack.php


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