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


PHP RequestContext::getMethod方法代码示例

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


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

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

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

示例3: matchCollection

 /**
  * Tries to match a URL with a set of routes.
  *
  * @param string          $pathinfo The path info to be parsed
  * @param RouteCollection $routes   The set of routes
  *
  * @return array An array of parameters
  *
  * @throws ResourceNotFoundException If the resource could not be found
  * @throws MethodNotAllowedException If the resource was found but the request method is not allowed
  */
 protected function matchCollection($pathinfo, RouteCollection $routes)
 {
     foreach ($routes as $name => $route) {
         if ($route instanceof RouteCollection) {
             if (false === strpos($route->getPrefix(), '{') && $route->getPrefix() !== substr($pathinfo, 0, strlen($route->getPrefix()))) {
                 continue;
             }
             if (!($ret = $this->matchCollection($pathinfo, $route))) {
                 continue;
             }
             return $ret;
         }
         $compiledRoute = $route->compile();
         // check the static prefix of the URL first. Only use the more expensive preg_match when it matches
         if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
             continue;
         }
         if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
             continue;
         }
         $hostnameMatches = array();
         if ($compiledRoute->getHostnameRegex() && !preg_match($compiledRoute->getHostnameRegex(), $this->context->getHost(), $hostnameMatches)) {
             continue;
         }
         // check HTTP method requirement
         if ($req = $route->getRequirement('_method')) {
             // HEAD and GET are equivalent as per RFC
             if ('HEAD' === ($method = $this->context->getMethod())) {
                 $method = 'GET';
             }
             if (!in_array($method, $req = explode('|', strtoupper($req)))) {
                 $this->allow = array_merge($this->allow, $req);
                 continue;
             }
         }
         $status = $this->handleRouteRequirements($pathinfo, $name, $route);
         if (self::ROUTE_MATCH === $status[0]) {
             return $status[1];
         }
         if (self::REQUIREMENT_MISMATCH === $status[0]) {
             continue;
         }
         return $this->mergeDefaults(array_replace($matches, $hostnameMatches, array('_route' => $name)), $route->getDefaults());
     }
 }
开发者ID:netvlies,项目名称:symfony,代码行数:56,代码来源:UrlMatcher.php

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

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

示例6: matchCollection

 /**
  * Tries to match a URL with a set of routes.
  *
  * @param string          $pathinfo The path info to be parsed
  * @param RouteCollection $routes   The set of routes
  *
  * @return array An array of parameters
  *
  * @throws ResourceNotFoundException If the resource could not be found
  * @throws MethodNotAllowedException If the resource was found but the request method is not allowed
  */
 protected function matchCollection($pathinfo, RouteCollection $routes)
 {
     foreach ($routes as $name => $route) {
         $compiledRoute = $route->compile();
         // check the static prefix of the URL first. Only use the more expensive preg_match when it matches
         if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
             continue;
         }
         if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
             continue;
         }
         $hostMatches = array();
         if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
             continue;
         }
         // check HTTP method requirement
         if ($requiredMethods = $route->getMethods()) {
             // HEAD and GET are equivalent as per RFC
             if ('HEAD' === ($method = $this->context->getMethod())) {
                 $method = 'GET';
             }
             if (!in_array($method, $requiredMethods)) {
                 $this->allow = array_merge($this->allow, $requiredMethods);
                 continue;
             }
         }
         $status = $this->handleRouteRequirements($pathinfo, $name, $route);
         if (self::ROUTE_MATCH === $status[0]) {
             return $status[1];
         }
         if (self::REQUIREMENT_MISMATCH === $status[0]) {
             continue;
         }
         return $this->getAttributes($route, $name, array_replace($matches, $hostMatches));
     }
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:47,代码来源:UrlMatcher.php

示例7: testSubRequestWithDifferentMethod

    public function testSubRequestWithDifferentMethod()
    {
        $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
        $request = Request::create('http://localhost/', 'post');
        $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);

        $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
        $requestMatcher->expects($this->any())
                       ->method('matchRequest')
                       ->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
                       ->will($this->returnValue(array()));

        $context = new RequestContext();

        $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext());
        $listener->onKernelRequest($event);

        // sub-request with another HTTP method
        $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
        $request = Request::create('http://localhost/', 'get');
        $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);

        $listener->onKernelRequest($event);

        $this->assertEquals('GET', $context->getMethod());
    }
开发者ID:symfony,项目名称:symfony,代码行数:26,代码来源:RouterListenerTest.php

示例8: testMethod

 public function testMethod()
 {
     $requestContext = new RequestContext();
     $requestContext->setMethod('post');
     $this->assertSame('POST', $requestContext->getMethod());
 }
开发者ID:peintune,项目名称:Ternado,代码行数:6,代码来源:RequestContextTest.php


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