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


PHP Diactoros\ServerRequestFactory类代码示例

本文整理汇总了PHP中Zend\Diactoros\ServerRequestFactory的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestFactory类的具体用法?PHP ServerRequestFactory怎么用?PHP ServerRequestFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testIsNotExcluded

 public function testIsNotExcluded()
 {
     $request = ServerRequestFactory::fromGlobals();
     $request = $request->withHeader('X-Forwarded', '80.80.80.80');
     $excluder = new IP($this->excludedIPs, ['10.10.10.10']);
     self::assertFalse($excluder->isExcluded($request));
 }
开发者ID:juliangut,项目名称:janitor,代码行数:7,代码来源:IPTest.php

示例2: handle

 /**
  * Handles the request and returns a response.
  *
  * @param  \Psr\Http\Message\ServerRequestInterface|null $request
  * @param  \Psr\Http\Message\ResponseInterface|null      $response
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function handle(ServerRequestInterface $request = null, ResponseInterface $response = null)
 {
     $request = $request ?: ServerRequestFactory::fromGlobals();
     $response = $response ?: new Response();
     $this->emit(Event::REQUEST_RECEIVED, $request, $response);
     return $this->dispatchThroughMiddleware($request, $response);
 }
开发者ID:yuloh,项目名称:crux,代码行数:15,代码来源:HandlesHttpRequests.php

示例3: tagsListIsReturnedIfCorrectShortCodeIsProvided

 /**
  * @test
  */
 public function tagsListIsReturnedIfCorrectShortCodeIsProvided()
 {
     $shortCode = 'abc123';
     $this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl())->shouldBeCalledTimes(1);
     $response = $this->action->__invoke(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')->withParsedBody(['tags' => []]), new Response());
     $this->assertEquals(200, $response->getStatusCode());
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:10,代码来源:EditTagsActionTest.php

示例4: invalidApiKeyReturnsErrorResponse

 /**
  * @test
  */
 public function invalidApiKeyReturnsErrorResponse()
 {
     $this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->setEnabled(false))->shouldBeCalledTimes(1);
     $request = ServerRequestFactory::fromGlobals()->withParsedBody(['apiKey' => 'foo']);
     $response = $this->action->__invoke($request, new Response());
     $this->assertEquals(401, $response->getStatusCode());
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:10,代码来源:AuthenticateActionTest.php

示例5: datesAreReadFromQuery

 /**
  * @test
  */
 public function datesAreReadFromQuery()
 {
     $shortCode = 'abc123';
     $this->visitsTracker->info($shortCode, new DateRange(null, new \DateTime('2016-01-01 00:00:00')))->willReturn([])->shouldBeCalledTimes(1);
     $response = $this->action->__invoke(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)->withQueryParams(['endDate' => '2016-01-01 00:00:00']), new Response());
     $this->assertEquals(200, $response->getStatusCode());
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:10,代码来源:GetVisitsActionTest.php

示例6: getRequest

 /**
  * Get the request from server.
  *
  * @return RequestInterface Server request
  */
 public function getRequest()
 {
     if (!isset($this->request)) {
         $this->request = ServerRequestFactory::fromGlobals();
     }
     return $this->request;
 }
开发者ID:spajak,项目名称:flow,代码行数:12,代码来源:Server.php

示例7: anExceptionsReturnsErrorResponse

 /**
  * @test
  */
 public function anExceptionsReturnsErrorResponse()
 {
     $page = 3;
     $this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class)->shouldBeCalledTimes(1);
     $response = $this->action->__invoke(ServerRequestFactory::fromGlobals()->withQueryParams(['page' => $page]), new Response());
     $this->assertEquals(500, $response->getStatusCode());
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:10,代码来源:ListShortcodesActionTest.php

示例8: getRequest

 /**
  * Get Request
  *
  * @param array $routeVariables Route Variables
  *
  * @return HttpMessages_CraftRequest Request
  */
 public function getRequest(array $routeVariables = [])
 {
     $route = craft()->httpMessages_routes->getRoute($routeVariables);
     $serverRequest = \Zend\Diactoros\ServerRequestFactory::fromGlobals();
     $request = HttpMessages_RequestFactory::fromRequest($serverRequest);
     return $request->withRoute($route);
 }
开发者ID:airtype,项目名称:craft-httpmessages,代码行数:14,代码来源:HttpMessagesService.php

示例9: testOversizedResponse

 public function testOversizedResponse()
 {
     $expectedClass = 'NetworkJs\\Response\\OversizedResponse';
     $moduleName = 'download';
     $this->assertInstanceOf($expectedClass, ResponseFactory::fromValues($moduleName, 10, 5));
     $this->assertInstanceOf($expectedClass, ResponseFactory::fromRequest(ServerRequestFactory::fromGlobals(null, ['module' => $moduleName, 'size' => 10]), 5));
 }
开发者ID:network-js,项目名称:php-server,代码行数:7,代码来源:ResponseFactoryTest.php

示例10: nonRestPathsAreNotProcessed

 /**
  * @test
  */
 public function nonRestPathsAreNotProcessed()
 {
     $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/non-rest'));
     $test = $this;
     $this->middleware->__invoke($request, new Response(), function ($req) use($request, $test) {
         $test->assertSame($request, $req);
     });
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:11,代码来源:PathVersionMiddlewareTest.php

示例11: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->request = ServerRequestFactory::fromGlobals();
     $this->response = new Response();
     $this->callback = function ($request, $response) {
         return $response;
     };
 }
开发者ID:juliangut,项目名称:cacheware,代码行数:11,代码来源:CacheWareTest.php

示例12: createRequest

 public static function createRequest(RequestInterface $request)
 {
     $psrRequest = ServerRequestFactory::fromGlobals()->withUri($request->getUri())->withMethod($request->getMethod())->withBody($request->getBody());
     foreach ($request->getHeaders() as $name => $values) {
         $psrRequest = $psrRequest->withHeader($name, $values);
     }
     return $psrRequest;
 }
开发者ID:seytar,项目名称:psx,代码行数:8,代码来源:Psr7Factory.php

示例13: to_applies_filters

 /**
  * @test
  */
 public function to_applies_filters()
 {
     $applied = false;
     $this->proxy->forward(ServerRequestFactory::fromGlobals())->filter(function ($request, $response) use(&$applied) {
         $applied = true;
     })->to('http://www.example.com');
     $this->assertTrue($applied);
 }
开发者ID:allantatter,项目名称:php-proxy,代码行数:11,代码来源:ProxyTest.php

示例14: aGenericExceptionWillReturnError

 /**
  * @test
  */
 public function aGenericExceptionWillReturnError()
 {
     $this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'))->willThrow(\Exception::class)->shouldBeCalledTimes(1);
     $request = ServerRequestFactory::fromGlobals()->withParsedBody(['longUrl' => 'http://www.domain.com/foo/bar']);
     $response = $this->action->__invoke($request, new Response());
     $this->assertEquals(500, $response->getStatusCode());
     $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0);
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:11,代码来源:CreateShortcodeActionTest.php

示例15: testNamedRoutes

 public function testNamedRoutes()
 {
     $routes = new RouteCollection(new HttpMessageStrategy());
     $routes->addRoute('GET', '/user/{id}', function () {
     })->setName('UserProfile');
     $builder = new UrlBuilder(ServerRequestFactory::fromGlobals($this->fakeServerParams()), $routes);
     $this->assertEquals('/site/user/23', $builder->createByName('UserProfile', ['id' => 23]));
 }
开发者ID:laasti,项目名称:directions,代码行数:8,代码来源:UrlBuilderTest.php


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