本文整理匯總了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));
}
示例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));
}
示例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');
}
示例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/');
}
示例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']);
}
示例6: testMethod
public function testMethod()
{
$requestContext = new RequestContext();
$requestContext->setMethod('post');
$this->assertSame('POST', $requestContext->getMethod());
}
示例7: prepareContext
/**
* Prepare RequestContext.
*
* @param \Symfony\Component\Routing\RequestContext $context Request context.
* @return void
*/
public function prepareContext(RequestContext &$context)
{
$context->setMethod($this->method);
}