當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RequestContext::setMethod方法代碼示例

本文整理匯總了PHP中Symfony\Component\Routing\RequestContext::setMethod方法的典型用法代碼示例。如果您正苦於以下問題:PHP RequestContext::setMethod方法的具體用法?PHP RequestContext::setMethod怎麽用?PHP RequestContext::setMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Routing\RequestContext的用法示例。


在下文中一共展示了RequestContext::setMethod方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: test

 public function test()
 {
     $coll = new RouteCollection();
     $coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('POST')));
     $coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\\d+')));
     $coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\\w+'), array(), '', array(), array('POST')));
     $coll->add('bar2', new Route('/foo', array(), array(), array(), 'baz'));
     $coll->add('bar3', new Route('/foo1', array(), array(), array(), 'baz'));
     $coll->add('bar4', new Route('/foo2', array(), array(), array(), 'baz', array(), array(), 'context.getMethod() == "GET"'));
     $context = new RequestContext();
     $context->setHost('baz');
     $matcher = new TraceableUrlMatcher($coll, $context);
     $traces = $matcher->getTraces('/babar');
     $this->assertSame(array(0, 0, 0, 0, 0, 0), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo');
     $this->assertSame(array(1, 0, 0, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/12');
     $this->assertSame(array(0, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/dd');
     $this->assertSame(array(0, 1, 1, 0, 0, 0), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo1');
     $this->assertSame(array(0, 0, 0, 0, 2), $this->getLevels($traces));
     $context->setMethod('POST');
     $traces = $matcher->getTraces('/foo');
     $this->assertSame(array(2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/dd');
     $this->assertSame(array(0, 1, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo2');
     $this->assertSame(array(0, 0, 0, 0, 0, 1), $this->getLevels($traces));
 }
開發者ID:BusinessCookies,項目名稱:CoffeeMachineProject,代碼行數:30,代碼來源:TraceableUrlMatcherTest.php

示例2: test

    public function test()
    {
        $coll = new RouteCollection();
        $coll->add('foo', new Route('/foo', array(), array('_method' => 'POST')));
        $coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\d+')));
        $coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\w+', '_method' => 'POST')));

        $context = new RequestContext();

        $matcher = new TraceableUrlMatcher($coll, $context);
        $traces = $matcher->getTraces('/babar');
        $this->assertEquals(array(0, 0, 0), $this->getLevels($traces));

        $traces = $matcher->getTraces('/foo');
        $this->assertEquals(array(1, 0, 0), $this->getLevels($traces));

        $traces = $matcher->getTraces('/bar/12');
        $this->assertEquals(array(0, 2), $this->getLevels($traces));

        $traces = $matcher->getTraces('/bar/dd');
        $this->assertEquals(array(0, 1, 1), $this->getLevels($traces));

        $context->setMethod('POST');
        $traces = $matcher->getTraces('/foo');
        $this->assertEquals(array(2), $this->getLevels($traces));

        $traces = $matcher->getTraces('/bar/dd');
        $this->assertEquals(array(0, 1, 2), $this->getLevels($traces));
    }
開發者ID:usefulthink,項目名稱:symfony,代碼行數:29,代碼來源:TraceableUrlMatcherTest.php

示例3: testRedirectWhenNoSlashForNonSafeMethod

 /**
  * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
  */
 public function testRedirectWhenNoSlashForNonSafeMethod()
 {
     $coll = new RouteCollection();
     $coll->add('foo', new Route('/foo/'));
     $context = new RequestContext();
     $context->setMethod('POST');
     $matcher = $this->getMockForAbstractClass('Symfony\\Component\\Routing\\Matcher\\RedirectableUrlMatcher', array($coll, $context));
     $matcher->match('/foo');
 }
開發者ID:TheTypoMaster,項目名稱:SPHERE-Framework,代碼行數:12,代碼來源:RedirectableUrlMatcherTest.php

示例4: testHttpRoutes

 public function testHttpRoutes()
 {
     $client = self::createClient();
     $router = $client->getContainer()->get('router');
     $context = new RequestContext();
     $context->setMethod('POST');
     $router->setContext($context);
     $router->match('/test/');
 }
開發者ID:bankiru,項目名稱:jsonrpc-server-bundle,代碼行數:9,代碼來源:RouterTest.php

示例5: testRouting

 public function testRouting()
 {
     $client = self::createClient();
     $router = $client->getContainer()->get('router');
     $context = new RequestContext();
     $context->setMethod('POST');
     $router->setContext($context);
     $match = $router->match('/test/');
     self::assertArrayHasKey('_controller', $match);
     self::assertSame(TestController::class . '::rpcAction', $match['_controller']);
     self::assertSame('test', $match['_route']);
 }
開發者ID:bankiru,項目名稱:rpc-server-bundle,代碼行數:12,代碼來源:RoutingTest.php

示例6: testMethod

 public function testMethod()
 {
     $requestContext = new RequestContext();
     $requestContext->setMethod('post');
     $this->assertSame('POST', $requestContext->getMethod());
 }
開發者ID:peintune,項目名稱:Ternado,代碼行數:6,代碼來源:RequestContextTest.php

示例7: prepareContext

 /**
  * Prepare RequestContext.
  *
  * @param \Symfony\Component\Routing\RequestContext $context Request context.
  * @return void
  */
 public function prepareContext(RequestContext &$context)
 {
     $context->setMethod($this->method);
 }
開發者ID:eozgilik,項目名稱:basalt,代碼行數:10,代碼來源:Request.php


注:本文中的Symfony\Component\Routing\RequestContext::setMethod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。