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


PHP ParamFetcher::setController方法代碼示例

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


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

示例1: testCustomErrorMessage

 public function testCustomErrorMessage()
 {
     $param = new QueryParam();
     $param->name = 'fero';
     $errorMessage = "variable must be an integer";
     $param->requirements = array('rule' => '\\d+', 'error_message' => $errorMessage);
     $param->description = 'integer value';
     $param->strict = true;
     $request = new Request(array('fero' => 'foobar'), array(), array('_controller' => __CLASS__ . '::stubAction'));
     $reader = $this->getMockBuilder('FOS\\RestBundle\\Request\\ParamReader')->disableOriginalConstructor()->getMock();
     $reader->expects($this->any())->method('read')->will($this->returnValue(array('fero' => $param)));
     $constraint = new Regex(array('pattern' => '#^\\d+$#xsu', 'message' => $errorMessage));
     $errors = new ConstraintViolationList(array(new ConstraintViolation($errorMessage, null, array(), null, null, null)));
     $this->validator->expects($this->once())->method('validateValue')->with('foobar', $constraint)->will($this->returnValue($errors));
     $requestStack = new RequestStack();
     $requestStack->push($request);
     $queryFetcher = new ParamFetcher($reader, $requestStack, $this->violationFormatter, $this->validator);
     $queryFetcher->setController($this->controller);
     try {
         $queryFetcher->get('fero');
         $this->fail('Fetching get() in strict mode with no default value did not throw an exception');
     } catch (HttpException $httpException) {
         $this->assertEquals($errorMessage, $httpException->getMessage());
     }
 }
開發者ID:Alexey-Stogny,項目名稱:FOSRestBundle,代碼行數:25,代碼來源:ParamFetcherTest.php

示例2: testEmptyValidator

 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage The ParamFetcher requirements feature requires the symfony/validator component.
  */
 public function testEmptyValidator()
 {
     $param = $this->createMockedParam('none', null, array(), false, null, array('constraint'));
     $this->setParams([$param]);
     $fetcher = new ParamFetcher($this->paramReader, $this->requestStack, $this->violationFormatter, null);
     $fetcher->setContainer($this->container);
     $fetcher->setController($this->controller);
     $fetcher->get('none', '42');
 }
開發者ID:AAstakhov,項目名稱:FOSRestBundle,代碼行數:13,代碼來源:ParamFetcherTest.php

示例3: testNullValidatorWithoutRequirements

 public function testNullValidatorWithoutRequirements()
 {
     $param = new QueryParam();
     $param->name = 'bizoo';
     $param->default = 'not expected';
     $param->description = 'A param without requirement nor validator';
     $request = new Request(array('bizoo' => 'foobar'), array(), array('_controller' => __CLASS__ . '::stubAction'));
     $reader = $this->getMockBuilder('FOS\\RestBundle\\Request\\ParamReader')->disableOriginalConstructor()->getMock();
     $reader->expects($this->any())->method('read')->will($this->returnValue(array('bizoo' => $param)));
     $queryFetcher = new ParamFetcher($reader, $request, $this->violationFormatter);
     $queryFetcher->setController($this->controller);
     $this->assertEquals('foobar', $queryFetcher->get('bizoo'));
 }
開發者ID:saberyounis,項目名稱:Sonata-Project,代碼行數:13,代碼來源:ParamFetcherTest.php

示例4: testRegexSucceed

 /**
  * @dataProvider regexProvider
  */
 public function testRegexSucceed($regex, $input, $expected)
 {
     $param = new QueryParam();
     $param->name = 'regex_param';
     $param->requirements = $regex;
     $validator = $this->getMock('Symfony\\Component\\Validator\\ValidatorInterface');
     $validator->method('validateValue')->will($this->returnCallback(function ($param, $constraint) {
         //Emulating behavior of a Symfony RegexValidator
         return preg_match($constraint->pattern, $param) ? null : array('error');
     }));
     $request = new Request(array($param->name => $input), array(), array('_controller' => __CLASS__ . '::stubAction'));
     $reader = $this->getMockBuilder('FOS\\RestBundle\\Request\\ParamReader')->disableOriginalConstructor()->getMock();
     $reader->expects($this->any())->method('read')->will($this->returnValue(array($param->name => $param)));
     $requestStack = new RequestStack();
     $requestStack->push($request);
     $queryFetcher = new ParamFetcher($reader, $requestStack, $this->violationFormatter, $validator);
     $queryFetcher->setController($this->controller);
     $this->assertEquals($expected, $queryFetcher->get($param->name));
 }
開發者ID:ktounet,項目名稱:FOSRestBundle,代碼行數:22,代碼來源:ParamFetcherTest.php


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