當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。