本文整理汇总了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));
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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;
}
示例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());
}
示例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);
}
示例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));
}
示例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);
});
}
示例11: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
$this->request = ServerRequestFactory::fromGlobals();
$this->response = new Response();
$this->callback = function ($request, $response) {
return $response;
};
}
示例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;
}
示例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);
}
示例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);
}
示例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]));
}