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


PHP Request::create方法代码示例

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


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

示例1: action

 /**
  * Perform an action on a Contenttype record.
  *
  * The action part of the POST request should take the form:
  * [
  *     contenttype => [
  *         id => [
  *             action => [field => value]
  *         ]
  *     ]
  * ]
  *
  * For example:
  * [
  *     'pages'   => [
  *         3 => ['modify' => ['status' => 'held']],
  *         5 => null,
  *         4 => ['modify' => ['status' => 'draft']],
  *         1 => ['delete' => null],
  *         2 => ['modify' => ['status' => 'published']],
  *     ],
  *     'entries' => [
  *         4 => ['modify' => ['status' => 'published']],
  *         1 => null,
  *         5 => ['delete' => null],
  *         2 => null,
  *         3 => ['modify' => ['title' => 'Drop Bear Attacks']],
  *     ]
  * ]
  *
  * @param Request $request Symfony Request
  *
  * @return Response
  */
 public function action(Request $request)
 {
     //         if (!$this->checkAntiCSRFToken($request->get('bolt_csrf_token'))) {
     //             $this->app->abort(Response::HTTP_BAD_REQUEST, Trans::__('Something went wrong'));
     //         }
     $contentType = $request->get('contenttype');
     $actionData = $request->get('actions');
     if ($actionData === null) {
         throw new \UnexpectedValueException('No content action data provided in the request.');
     }
     foreach ($actionData as $contentTypeSlug => $recordIds) {
         if (!$this->getContentType($contentTypeSlug)) {
             // sprintf('Attempt to modify invalid ContentType: %s', $contentTypeSlug);
             continue;
         } else {
             $this->app['storage.request.modify']->action($contentTypeSlug, $recordIds);
         }
     }
     $referer = Request::create($request->server->get('HTTP_REFERER'));
     $taxonomy = null;
     foreach (array_keys($this->getOption('taxonomy', [])) as $taxonomyKey) {
         if ($referer->query->get('taxonomy-' . $taxonomyKey)) {
             $taxonomy[$taxonomyKey] = $referer->query->get('taxonomy-' . $taxonomyKey);
         }
     }
     $options = (new ListingOptions())->setOrder($referer->query->get('order'))->setPage($referer->query->get('page_' . $contentType))->setFilter($referer->query->get('filter'))->setTaxonomies($taxonomy);
     $context = ['contenttype' => $this->getContentType($contentType), 'multiplecontent' => $this->app['storage.request.listing']->action($contentType, $options), 'filter' => array_merge((array) $taxonomy, (array) $options->getFilter()), 'permissions' => $this->getContentTypeUserPermissions($contentType, $this->users()->getCurrentUser())];
     return $this->render('@bolt/async/record_list.twig', ['context' => $context]);
 }
开发者ID:Twiebie,项目名称:bolt,代码行数:63,代码来源:Records.php

示例2: testAssetsController

 public function testAssetsController()
 {
     $assetsControler = new AssetsController();
     $request = new Request();
     $req = $request->create('/assets?application=Towel&path=css/towel_test.css', 'GET');
     $response = $assetsControler->index($req);
     $this->assertEquals('200', $response->getStatusCode());
     $this->assertEquals('body { font-size: 20px; }', $response->getContent());
     $req = $request->create('/assets?application=Towel&path=css/Error.css', 'GET');
     $response = $assetsControler->index($req);
     $this->assertEquals('404', $response->getStatusCode());
 }
开发者ID:42mate,项目名称:towel,代码行数:12,代码来源:AssetsTest.php

示例3: testExceptionListenerDisabledByDefault

 /**
  * @expectedException        RuntimeException
  * @expectedExceptionMessage Test Exception
  */
 public function testExceptionListenerDisabledByDefault()
 {
     $app = $this->createApplication();
     $this->assertFalse($app['new_relic.log_exceptions']);
     $app['new_relic.interactor.real']->expects($this->never())->method('noticeException');
     $response = $app->handle(Request::create('/error'));
 }
开发者ID:Aerendir,项目名称:EkinoNewRelicBundle,代码行数:11,代码来源:EkinoNewRelicServiceProviderTest.php

示例4: testUpdateResult

 public function testUpdateResult()
 {
     $this->allowLogin($this->getApp());
     $this->setRequest(Request::create('/bolt/dbupdate_result'));
     $this->checkTwigForTemplate($this->getApp(), '@bolt/dbcheck/dbcheck.twig');
     $this->controller()->updateResult($this->getRequest());
 }
开发者ID:nuffer,项目名称:bolt,代码行数:7,代码来源:DatabaseTest.php

示例5: setUp

 public function setUp()
 {
     $this->document = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Enhancer\\RouteObject');
     $mapping = array('Symfony\\Cmf\\Component\\Routing\\Tests\\Enhancer\\RouteObject' => 'cmf_content.controller:indexAction');
     $this->mapper = new FieldByClassEnhancer('_content', '_controller', $mapping);
     $this->request = Request::create('/test');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:7,代码来源:FieldByClassEnhancerTest.php

示例6: checkRouteResponse

 protected function checkRouteResponse(Application $app, $path, $expectedContent, $method = 'get', $message = null)
 {
     $app->register(new ServiceControllerServiceProvider());
     $request = Request::create($path, $method);
     $response = $app->handle($request);
     $this->assertEquals($expectedContent, $response->getContent(), $message);
 }
开发者ID:syntropysoftware,项目名称:cryptoffice-frontend,代码行数:7,代码来源:ServiceControllerResolverRouterTest.php

示例7: __invoke

 public function __invoke(ServiceManagerInterface $serviceManager, array $moreParams = [])
 {
     if (!isset($moreParams['buffer'])) {
         throw new Exception\UnexpectedValueException('Could not parse request.');
     }
     /** @var RequestParser $requestParser */
     $requestParser = $serviceManager->get('RequestParser');
     /** @var Request $request */
     $request = null;
     $requestParser->on(['state'], function (Event $event, $method, $path, $version) use(&$request) {
         $request = Request::create($path, $method);
         $event->getEventEmitter()->on(['header'], function (Event $e, $headerName, $headerValue) use($request) {
             /** @var Request $request */
             $name = \str_replace('-', '_', \strtoupper($headerName));
             if ($name === 'COOKIE') {
                 $cookieData = [];
                 parse_str($headerValue, $cookieData);
                 $request->setCookieParams(new ArrayObject($cookieData));
             } else {
                 $request->setHeader($name, $headerValue);
             }
         });
         $event->getEventEmitter()->on(['body'], function (Event $e, $body) use($request) {
             /** @var Request $request */
             if (!in_array($request->getMethod(), ['GET', 'HEAD']) && !empty($body)) {
                 $postData = [];
                 parse_str($body, $postData);
                 $request->setPostParams(new ArrayObject($postData));
             }
         });
     });
     $requestParser->parse($moreParams['buffer']);
     return $request;
 }
开发者ID:HugoSantiagoBecerraAdan,项目名称:php-io,代码行数:34,代码来源:Symfony.php

示例8: testImplicitGrant

 public function testImplicitGrant()
 {
     // Start session manually.
     $session = new Session(new MockFileSessionStorage());
     $session->start();
     // Query authorization endpoint with response_type = token.
     $parameters = array('response_type' => 'token', 'client_id' => 'http://democlient1.com/', 'redirect_uri' => 'http://democlient1.com/redirect_uri', 'scope' => 'demoscope1', 'state' => $session->getId());
     $server = array('PHP_AUTH_USER' => 'demousername1', 'PHP_AUTH_PW' => 'demopassword1');
     $client = $this->createClient();
     $crawler = $client->request('GET', '/api/oauth2/authorize', $parameters, array(), $server);
     $this->assertTrue($client->getResponse()->isRedirect());
     // Check basic auth response that can simply compare.
     $authResponse = Request::create($client->getResponse()->headers->get('Location'), 'GET');
     $this->assertEquals('http://democlient1.com/redirect_uri', $authResponse->getSchemeAndHttpHost() . $authResponse->getBaseUrl() . $authResponse->getPathInfo());
     // Check basic token response that can simply compare.
     $tokenResponse = $authResponse->query->all();
     $this->assertEquals('bearer', $tokenResponse['token_type']);
     $this->assertEquals('demoscope1', $tokenResponse['scope']);
     $this->assertEquals($session->getId(), $tokenResponse['state']);
     // Query debug endpoint with access_token.
     $parameters = array();
     $server = array('HTTP_Authorization' => implode(' ', array('Bearer', $tokenResponse['access_token'])));
     $client = $this->createClient();
     $crawler = $client->request('GET', '/api/oauth2/debug', $parameters, array(), $server);
     $debugResponse = json_decode($client->getResponse()->getContent(), true);
     $this->assertEquals('demousername1', $debugResponse['username']);
 }
开发者ID:rakesh-mohanta,项目名称:oauth2-symfony-bundle,代码行数:27,代码来源:OAuth2Test.php

示例9: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $session = new Session();
     $request = Request::create('/');
     $request->setSession($session);
     /** @var RequestStack $stack */
     $stack = $this->container->get('request_stack');
     $stack->pop();
     $stack->push($request);
     // Set the current user to one that can access comments. Specifically, this
     // user does not have access to the 'administer comments' permission, to
     // ensure only published comments are visible to the end user.
     $current_user = $this->container->get('current_user');
     $current_user->setAccount($this->createUser(array(), array('access comments')));
     // Install tables and config needed to render comments.
     $this->installSchema('comment', array('comment_entity_statistics'));
     $this->installConfig(array('system', 'filter', 'comment'));
     // Comment rendering generates links, so build the router.
     $this->installSchema('system', array('router'));
     $this->container->get('router.builder')->rebuild();
     // Set up a field, so that the entity that'll be referenced bubbles up a
     // cache tag when rendering it entirely.
     $this->addDefaultCommentField('entity_test', 'entity_test');
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:28,代码来源:CommentDefaultFormatterCacheTagsTest.php

示例10: testShouldBootAndHandleRequest

 public function testShouldBootAndHandleRequest()
 {
     if (version_compare(PHP_VERSION, '5.6', '>=')) {
         $this->markTestSkipped('CodeIgniter v2.1 is not compatible with PHP >= 5.6');
     }
     $session = new Session(new MockArraySessionStorage());
     $request = Request::create('/welcome/');
     $request->setSession($session);
     $requestStack = $this->prophesize('Symfony\\Component\\HttpFoundation\\RequestStack');
     $requestStack->getCurrentRequest()->willReturn($request);
     $container = $this->prophesize('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->get('request_stack')->willReturn($requestStack->reveal());
     $container->getParameter(Argument::any())->willReturn('foo');
     $container->set(Argument::type('string'), Argument::any())->shouldBeCalled();
     $classLoader = new CodeIgniterClassLoader();
     $kernel = new CodeIgniterKernel();
     $kernel->setRootDir($_ENV['THEODO_EVOLUTION_FAKE_PROJECTS'] . '/codeigniter21');
     $kernel->setOptions(array('environment' => 'prod', 'version' => '2.1.4', 'core' => false));
     $kernel->setClassLoader($classLoader);
     $kernel->boot($container->reveal());
     $this->assertTrue($kernel->isBooted());
     $this->assertTrue($classLoader->isAutoloaded());
     // CodeIgniter creates a global variables
     $this->assertArrayHasKey('BM', $GLOBALS);
     $this->assertArrayHasKey('EXT', $GLOBALS);
     $this->assertArrayHasKey('CFG', $GLOBALS);
     $this->assertArrayHasKey('UNI', $GLOBALS);
     $this->assertArrayHasKey('URI', $GLOBALS);
     $this->assertArrayHasKey('RTR', $GLOBALS);
     $this->assertArrayHasKey('OUT', $GLOBALS);
     $this->assertArrayHasKey('SEC', $GLOBALS);
     $response = $kernel->handle($request, 1, true);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals(200, $response->getStatusCode());
 }
开发者ID:chancegarcia,项目名称:TheodoEvolutionLegacyWrapperBundle,代码行数:35,代码来源:CodeIgniterKernelTest.php

示例11: testResponse

 public function testResponse()
 {
     $request = Request::create('/thumbs/320x240r/generic-logo.jpg', 'GET');
     $responder = $this->initializeResponder($request);
     $response = $responder->respond();
     $this->assertInstanceOf(Response::class, $response);
 }
开发者ID:rarila,项目名称:bolt-thumbs,代码行数:7,代码来源:ThumbnailResponderTest.php

示例12: testRender

 public function testRender()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->once())->method('get')->will($this->returnValue($this->getMockBuilder('\\Twig_Environment')->disableOriginalConstructor()->getMock()));
     $renderer = new ContainerAwareHIncludeFragmentRenderer($container);
     $renderer->render('/', Request::create('/'));
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:7,代码来源:LegacyContainerAwareHIncludeFragmentRendererTest.php

示例13: it_converts_exception_to_json

 /** @test */
 public function it_converts_exception_to_json()
 {
     $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
     $resolver->expects($this->once())->method('getController')->will($this->returnValue(function () {
         throw new NotFoundHttpException();
     }));
     $resolver->expects($this->once())->method('getArguments')->will($this->returnValue([]));
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $logger->expects($this->once())->method('error');
     $dispatcher = new EventDispatcher();
     $httpKernel = new HttpKernel($dispatcher, $resolver);
     $kernel = new KernelForTest('test', true);
     $kernel->boot();
     $kernel->getContainer()->set('http_kernel', $httpKernel);
     $dispatcher->addSubscriber(new RequestFormatNegotiationListener());
     $dispatcher->addSubscriber(new RequestFormatValidationListener());
     $dispatcher->addSubscriber(new ResponseConversionListener());
     $dispatcher->addSubscriber(new ExceptionConversionListener($logger));
     $request = Request::create('/exception', 'GET', [], [], [], ['HTTP_ACCEPT' => 'application/json']);
     $request->attributes->set('_format', 'json');
     $response = $kernel->handle($request)->prepare($request);
     $this->assertSame(404, $response->getStatusCode());
     $this->assertSame('application/vnd.error+json', $response->headers->get('Content-Type'));
     $this->assertJsonStringEqualsJsonString(json_encode(['message' => 'Not Found']), $response->getContent());
 }
开发者ID:jsor,项目名称:stack-hal,代码行数:26,代码来源:KernelTest.php

示例14: setUp

 protected function setUp()
 {
     $this->request = Request::create(self::TEST_URL);
     $this->token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->event = $this->getMockBuilder('Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent')->disableOriginalConstructor()->getMock();
     $this->listener = new LoginListener();
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:7,代码来源:LoginListenerTest.php

示例15: save

 /**
  * Save the image to the given outputFile
  *
  * @param $outputFile
  * @return string the URL to the saved image
  */
 public function save($outputFile)
 {
     $glideApi = GlideApiFactory::create();
     $outputImageData = $glideApi->run(Request::create(null, null, $this->modificationParameters), file_get_contents($this->getPathToImage()));
     file_put_contents($outputFile, $outputImageData);
     return $this->getURL();
 }
开发者ID:phazei,项目名称:laravel-glide,代码行数:13,代码来源:GlideImage.php


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