/** * @param array $server * @param array $query * @param array $body * @param array $cookies * @param array $files * * @return ServerRequest */ public static function fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null) { $cookies = new CookieJar($cookies ?: $_COOKIE); $server = static::normalizeServer($server ?: $_SERVER); $files = static::normalizeFiles($files ?: $_FILES); $headers = static::marshalHeaders($server); $request = new Request($cookies, $server, $files, static::marshalUriFromServer($server, $headers), static::get('REQUEST_METHOD', $server, 'GET'), 'php://input', $headers); return $request->withQueryParams($query ?: $_GET)->withParsedBody($body ?: $_POST); }
public function ensureNotPreviouslyPaginated(Request $request) { if ($request->isPaginated()) { throw new BadRequestException('You may not request two methods of pagination'); } }
/** * @param Request $request * * @throws BadRequestException */ public function ensureGetOnlyRequest(Request $request) { if ($request->getMethod() !== 'GET') { throw new BadRequestException('Query parameter is only allowed on GET requests'); } }
public function testGetSetSorts() { $faker = $this->getFaker(); $sorts = [$faker->word => Sorts::SORT_DESCENDING, $faker->word => Sorts::SORT_ASCENDING, $faker->word => Sorts::SORT_DESCENDING]; $request = new Request(); $request->setSorts($sorts); $this->assertSame($sorts, $request->getSorts()); foreach (array_keys($sorts) as $sort) { $this->assertTrue($request->hasSort($sort)); } }