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


PHP RequestContext::getScheme方法代码示例

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


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

示例1: handleRouteRequirements

 /**
  * Handles specific route requirements.
  *
  * @param string $pathinfo The path
  * @param string $name     The route name
  * @param Route  $route    The route
  *
  * @return array The first element represents the status, the second contains additional information
  */
 protected function handleRouteRequirements($pathinfo, $name, Route $route)
 {
     // check HTTP scheme requirement
     $scheme = $route->getRequirement('_scheme');
     $status = $scheme && $scheme !== $this->context->getScheme() ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
     return array($status, null);
 }
开发者ID:ronnylt,项目名称:symfony,代码行数:16,代码来源:UrlMatcher.php

示例2: decorateUrl

 /**
  * Decorates an URL with url context and query.
  *
  * @param string      $url           Relative URL
  * @param array       $parameters    An array of parameters
  * @param bool|string $referenceType The type of reference to be generated (one of the constants)
  *
  * @return string
  *
  * @throws \RuntimeException
  */
 protected function decorateUrl($url, array $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
 {
     if (!$this->context) {
         throw new \RuntimeException('No context associated to the CmsPageRouter');
     }
     $schemeAuthority = '';
     if ($this->context->getHost() && (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType)) {
         $port = '';
         if ('http' === $this->context->getScheme() && 80 != $this->context->getHttpPort()) {
             $port = sprintf(':%s', $this->context->getHttpPort());
         } elseif ('https' === $this->context->getScheme() && 443 != $this->context->getHttpsPort()) {
             $port = sprintf(':%s', $this->context->getHttpsPort());
         }
         $schemeAuthority = self::NETWORK_PATH === $referenceType ? '//' : sprintf('%s://', $this->context->getScheme());
         $schemeAuthority = sprintf('%s%s%s', $schemeAuthority, $this->context->getHost(), $port);
     }
     if (self::RELATIVE_PATH === $referenceType) {
         $url = $this->getRelativePath($this->context->getPathInfo(), $url);
     } else {
         $url = sprintf('%s%s%s', $schemeAuthority, $this->context->getBaseUrl(), $url);
     }
     if (count($parameters) > 0) {
         return sprintf('%s?%s', $url, http_build_query($parameters, '', '&'));
     }
     return $url;
 }
开发者ID:Neodork,项目名称:SonataPageBundle,代码行数:37,代码来源:CmsPageRouter.php

示例3: rebuildRequest

 /**
  * Rebuild the request object from a URL with the help of the RequestContext.
  *
  * If the request context is not set, this simply returns the request object built from $uri.
  *
  * @param string $uri
  *
  * @return Request
  */
 private function rebuildRequest($uri)
 {
     if (!$this->context) {
         return Request::create($uri);
     }
     $server = array();
     if ($this->context->getHost()) {
         $server['SERVER_NAME'] = $this->context->getHost();
         $server['HTTP_HOST'] = $this->context->getHost();
     }
     if ($this->context->getBaseUrl()) {
         $uri = $this->context->getBaseUrl() . $uri;
         $server['SCRIPT_FILENAME'] = $this->context->getBaseUrl();
         $server['PHP_SELF'] = $this->context->getBaseUrl();
     }
     if ('https' === $this->context->getScheme()) {
         $server['HTTPS'] = 'on';
         $server['SERVER_PORT'] = $this->context->getHttpsPort();
         if (443 !== $this->context->getHttpsPort()) {
             // this is parsed from the host by symfony request
             // https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L971
             $server['HTTP_HOST'] .= ':' . $this->context->getHttpsPort();
         }
     } else {
         $server['SERVER_PORT'] = $this->context->getHttpPort();
         if (80 !== $this->context->getHttpPort()) {
             // this is parsed from the host by symfony request
             // https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L971
             $server['HTTP_HOST'] .= ':' . $this->context->getHttpPort();
         }
     }
     return Request::create($uri, $this->context->getMethod(), $this->context->getParameters(), array(), array(), $server);
 }
开发者ID:hacfi,项目名称:Routing,代码行数:42,代码来源:ChainRouter.php

示例4: getScheme

 /**
  * @return string
  */
 private function getScheme()
 {
     $scheme = $this->context->getScheme();
     if (is_bool($this->sslEnabled)) {
         $scheme = $this->sslEnabled ? 'https' : 'http';
     }
     return $scheme;
 }
开发者ID:spryker,项目名称:Application,代码行数:11,代码来源:AbstractRouter.php

示例5: getBaseUrl

 /**
  * Return the base URL, either the base_url defined in Config, or the URL
  * of the current language, if 'one_domain_foreach_lang' is enabled.
  *
  * @param bool $scheme_only if true, only the scheme will be returned. If false, the complete base URL, including path, is returned.
  *
  * @return string the base URL, with a trailing '/'
  */
 public function getBaseUrl($scheme_only = false)
 {
     if (null === $this->baseUrlScheme) {
         $scheme = "http";
         $port = 80;
         if ($host = $this->requestContext->getHost()) {
             $scheme = $this->requestContext->getScheme();
             $port = '';
             if ('http' === $scheme && 80 != $this->requestContext->getHttpPort()) {
                 $port = ':' . $this->requestContext->getHttpPort();
             } elseif ('https' === $scheme && 443 != $this->requestContext->getHttpsPort()) {
                 $port = ':' . $this->requestContext->getHttpsPort();
             }
         }
         $this->baseUrlScheme = "{$scheme}://{$host}" . "{$port}";
     }
     return $scheme_only ? $this->baseUrlScheme : $this->baseUrlScheme . $this->requestContext->getBaseUrl();
 }
开发者ID:alex63530,项目名称:thelia,代码行数:26,代码来源:URL.php

示例6: getHostUrl

 /**
  * Get host url (scheme, host, port)
  *
  * @return string Host url
  */
 private function getHostUrl()
 {
     $url = $this->requestContext->getScheme() . '://' . $this->requestContext->getHost();
     if ($this->requestContext->getScheme() == 'http' && $this->requestContext->getHttpPort() && $this->requestContext->getHttpPort() != 80) {
         $url .= ':' . $this->requestContext->getHttpPort();
     } elseif ($this->requestContext->getScheme() == 'https' && $this->requestContext->getHttpsPort() && $this->requestContext->getHttpsPort() != 443) {
         $url .= ':' . $this->requestContext->getHttpsPort();
     }
     return $url;
 }
开发者ID:Bukashk0zzz,项目名称:VichUploaderSerializationBundle,代码行数:15,代码来源:JmsPreSerializeListener.php

示例7: handleRouteRequirements

 /**
  * Handles specific route requirements.
  *
  * @param string $pathinfo The path
  * @param string $name     The route name
  * @param Route  $route    The route
  *
  * @return array The first element represents the status, the second contains additional information
  */
 protected function handleRouteRequirements($pathinfo, $name, Route $route)
 {
     // expression condition
     if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), array('context' => $this->context, 'request' => $this->request))) {
         return array(self::REQUIREMENT_MISMATCH, null);
     }
     // check HTTP scheme requirement
     $scheme = $this->context->getScheme();
     $status = $route->getSchemes() && !$route->hasScheme($scheme) ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
     return array($status, null);
 }
开发者ID:GeorgeBroadley,项目名称:caffeine-vendor,代码行数:20,代码来源:UrlMatcher.php

示例8: generateI18nRouteFromCurrentRequest

 public function generateI18nRouteFromCurrentRequest($culture, $referenceType = self::ABSOLUTE_PATH, $scheme = null)
 {
     $result = $this->match($this->context->getPathInfo(), $this->context->getHost(), $this->context->getScheme(), $this->context->getMethod());
     $route = $result['_route'];
     if (strpos($route, ':i18n:') != false) {
         list(, , $route) = explode(':', $route, 3);
     }
     $result['_culture'] = $culture;
     unset($result['_route']);
     $parameters = new ArrayObject($result);
     $this->eventDispatcher->dispatch('Routing.preGenrateI18nRouteFromCurrentRequest', $this, compact('culture', 'referenceType', 'scheme', 'parameters'));
     return $this->generate($route, $parameters->getArrayCopy(), $referenceType, $scheme);
 }
开发者ID:mpoiriert,项目名称:nucleus,代码行数:13,代码来源:Router.php

示例9: getBaseUrl

 /**
  * Returns base URL, with scheme, host and port, for current request context.
  * If no delivery URL is configured for current SiteAccess, will return base URL from current RequestContext.
  *
  * @return string
  */
 protected function getBaseUrl()
 {
     $port = '';
     if ($this->requestContext->getScheme() === 'https' && $this->requestContext->getHttpsPort() != 443) {
         $port = ":{$this->requestContext->getHttpsPort()}";
     }
     if ($this->requestContext->getScheme() === 'http' && $this->requestContext->getHttpPort() != 80) {
         $port = ":{$this->requestContext->getHttpPort()}";
     }
     $baseUrl = $this->requestContext->getBaseUrl();
     if (substr($this->requestContext->getBaseUrl(), -4) === '.php') {
         $baseUrl = pathinfo($this->requestContext->getBaseurl(), PATHINFO_DIRNAME);
     }
     $baseUrl = rtrim($baseUrl, '/\\');
     return sprintf('%s://%s%s%s', $this->requestContext->getScheme(), $this->requestContext->getHost(), $port, $baseUrl);
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:22,代码来源:IORepositoryResolver.php

示例10: getAbsoluteUrlPic

 /**
  * Get absolute path of a given pic url
  *
  * @param string $picUrl
  * @return string
  */
 private function getAbsoluteUrlPic($picUrl = '')
 {
     if ($picUrl) {
         if ("/" == $picUrl[0]) {
             $scheme = $this->context->getScheme();
             $host = $this->context->getHost();
             $port = '';
             if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
                 $port = ':' . $this->context->getHttpPort();
             } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
                 $port = ':' . $this->context->getHttpsPort();
             }
             return $scheme . "://" . $host . $port . $picUrl;
         }
     }
     return $picUrl;
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:23,代码来源:PicService.php

示例11: testFromRequest

 public function testFromRequest()
 {
     $request = Request::create('https://test.com:444/foo?bar=baz');
     $requestContext = new RequestContext();
     $requestContext->setHttpPort(123);
     $requestContext->fromRequest($request);
     $this->assertEquals('', $requestContext->getBaseUrl());
     $this->assertEquals('GET', $requestContext->getMethod());
     $this->assertEquals('test.com', $requestContext->getHost());
     $this->assertEquals('https', $requestContext->getScheme());
     $this->assertEquals('/foo', $requestContext->getPathInfo());
     $this->assertEquals('bar=baz', $requestContext->getQueryString());
     $this->assertSame(123, $requestContext->getHttpPort());
     $this->assertSame(444, $requestContext->getHttpsPort());
     $request = Request::create('http://test.com:8080/foo?bar=baz');
     $requestContext = new RequestContext();
     $requestContext->setHttpsPort(567);
     $requestContext->fromRequest($request);
     $this->assertSame(8080, $requestContext->getHttpPort());
     $this->assertSame(567, $requestContext->getHttpsPort());
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:21,代码来源:RequestContextTest.php

示例12: decorateUrl

 /**
  * Decorates an URL with url context and query
  *
  * @param string  $url        Relative URL
  * @param array   $parameters An array of parameters
  * @param boolean $absolute   Whether to generate an absolute path or not
  *
  * @return string
  *
  * @throws \RuntimeException
  */
 protected function decorateUrl($url, array $parameters = array(), $absolute = false)
 {
     if (!$this->context) {
         throw new \RuntimeException('No context associated to the CmsPageRouter');
     }
     $url = sprintf('%s%s', $this->context->getBaseUrl(), $url);
     if ($absolute && $this->context->getHost()) {
         $scheme = $this->context->getScheme();
         $port = '';
         if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
             $port = ':' . $this->context->getHttpPort();
         } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
             $port = ':' . $this->context->getHttpsPort();
         }
         $url = $scheme . '://' . $this->context->getHost() . $port . $url;
     }
     if (count($parameters) > 0) {
         return sprintf('%s?%s', $url, http_build_query($parameters, '', '&'));
     }
     return $url;
 }
开发者ID:LamaDelRay,项目名称:test_symf,代码行数:32,代码来源:CmsPageRouter.php

示例13: rebuildRequest

 /**
  * Rebuild the request object from a URL with the help of the RequestContext.
  *
  * If the request context is not set, this simply returns the request object built from $uri.
  *
  * @param string $pathinfo
  *
  * @return Request
  */
 private function rebuildRequest($pathinfo)
 {
     if (!$this->context) {
         return Request::create('http://localhost' . $pathinfo);
     }
     $uri = $pathinfo;
     $server = array();
     if ($this->context->getBaseUrl()) {
         $uri = $this->context->getBaseUrl() . $pathinfo;
         $server['SCRIPT_FILENAME'] = $this->context->getBaseUrl();
         $server['PHP_SELF'] = $this->context->getBaseUrl();
     }
     $host = $this->context->getHost() ?: 'localhost';
     if ('https' === $this->context->getScheme() && 443 !== $this->context->getHttpsPort()) {
         $host .= ':' . $this->context->getHttpsPort();
     }
     if ('http' === $this->context->getScheme() && 80 !== $this->context->getHttpPort()) {
         $host .= ':' . $this->context->getHttpPort();
     }
     $uri = $this->context->getScheme() . '://' . $host . $uri . '?' . $this->context->getQueryString();
     return Request::create($uri, $this->context->getMethod(), $this->context->getParameters(), array(), array(), $server);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:31,代码来源:ChainRouter.php

示例14: doGenerate

 /**
  * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
  * @throws InvalidParameterException           When a parameter value for a placeholder is not correct because
  *                                             it does not match the requirement
  */
 protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array())
 {
     $variables = array_flip($variables);
     $mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
     // all params must be given
     if ($diff = array_diff_key($variables, $mergedParams)) {
         throw new MissingMandatoryParametersException(sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', array_keys($diff)), $name));
     }
     $url = '';
     $optional = true;
     foreach ($tokens as $token) {
         if ('variable' === $token[0]) {
             if (!$optional || !array_key_exists($token[3], $defaults) || null !== $mergedParams[$token[3]] && (string) $mergedParams[$token[3]] !== (string) $defaults[$token[3]]) {
                 // check requirement
                 if (null !== $this->strictRequirements && !preg_match('#^' . $token[2] . '$#', $mergedParams[$token[3]])) {
                     $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
                     if ($this->strictRequirements) {
                         throw new InvalidParameterException($message);
                     }
                     if ($this->logger) {
                         $this->logger->error($message);
                     }
                     return;
                 }
                 $url = $token[1] . $mergedParams[$token[3]] . $url;
                 $optional = false;
             }
         } else {
             // static text
             $url = $token[1] . $url;
             $optional = false;
         }
     }
     if ('' === $url) {
         $url = '/';
     }
     // the contexts base URL is already encoded (see Symfony\Component\HttpFoundation\Request)
     $url = strtr(rawurlencode($url), $this->decodedChars);
     // the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
     // so we need to encode them as they are not used for this purpose here
     // otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
     $url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/'));
     if ('/..' === substr($url, -3)) {
         $url = substr($url, 0, -2) . '%2E%2E';
     } elseif ('/.' === substr($url, -2)) {
         $url = substr($url, 0, -1) . '%2E';
     }
     $schemeAuthority = '';
     if ($host = $this->context->getHost()) {
         $scheme = $this->context->getScheme();
         if ($requiredSchemes) {
             $schemeMatched = false;
             foreach ($requiredSchemes as $requiredScheme) {
                 if ($scheme === $requiredScheme) {
                     $schemeMatched = true;
                     break;
                 }
             }
             if (!$schemeMatched) {
                 $referenceType = self::ABSOLUTE_URL;
                 $scheme = current($requiredSchemes);
             }
         } elseif (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) {
             // We do this for BC; to be removed if _scheme is not supported anymore
             $referenceType = self::ABSOLUTE_URL;
             $scheme = $req;
         }
         if ($hostTokens) {
             $routeHost = '';
             foreach ($hostTokens as $token) {
                 if ('variable' === $token[0]) {
                     if (null !== $this->strictRequirements && !preg_match('#^' . $token[2] . '$#i', $mergedParams[$token[3]])) {
                         $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
                         if ($this->strictRequirements) {
                             throw new InvalidParameterException($message);
                         }
                         if ($this->logger) {
                             $this->logger->error($message);
                         }
                         return;
                     }
                     $routeHost = $token[1] . $mergedParams[$token[3]] . $routeHost;
                 } else {
                     $routeHost = $token[1] . $routeHost;
                 }
             }
             if ($routeHost !== $host) {
                 $host = $routeHost;
                 if (self::ABSOLUTE_URL !== $referenceType) {
                     $referenceType = self::NETWORK_PATH;
                 }
             }
         }
         if (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType) {
             $port = '';
//.........这里部分代码省略.........
开发者ID:qasem2rubik,项目名称:laravel,代码行数:101,代码来源:UrlGenerator.php

示例15: testScheme

 public function testScheme()
 {
     $requestContext = new RequestContext();
     $requestContext->setScheme('HTTPS');
     $this->assertSame('https', $requestContext->getScheme());
 }
开发者ID:peintune,项目名称:Ternado,代码行数:6,代码来源:RequestContextTest.php


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