8000 [DX][HttpFoundation] Add RequestInterface by amikheychik · Pull Request #13625 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DX][HttpFoundation] Add RequestInterface #13625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function setContentDisposition($disposition, $filename = '', $filenameFal
/**
* {@inheritdoc}
*/
public function prepare(Request $request)
public function prepare(RequestInterface $request)
{
$this->headers->set('Content-Length', $this->file->getSize());
< 8000 /td>
Expand All @@ -180,7 +180,7 @@ public function prepare(Request $request)
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
}

if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) {
if ('HTTP/1.0' != $request->getServer()->get('SERVER_PROTOCOL')) {
$this->setProtocolVersion('1.1');
}

Expand All @@ -189,13 +189,13 @@ public function prepare(Request $request)
$this->offset = 0;
$this->maxlen = -1;

if (self::$trustXSendfileTypeHeader && $request->headers->has('X-Sendfile-Type')) {
if (self::$trustXSendfileTypeHeader && $request->getHeaders()->has('X-Sendfile-Type')) {
// Use X-Sendfile, do not send any content.
$type = $request->headers->get('X-Sendfile-Type');
$type = $request->getHeaders()->get('X-Sendfile-Type');
$path = $this->file->getRealPath();
if (strtolower($type) == 'x-accel-redirect') {
// Do X-Accel-Mapping substitutions.
foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) {
foreach (explode(',', $request->getHeaders()->get('X-Accel-Mapping', '')) as $mapping) {
$mapping = explode('=', $mapping, 2);

if (2 == count($mapping)) {
Expand All @@ -211,10 +211,12 @@ public function prepare(Request $request)
}
$this->headers->set($type, $path);
$this->maxlen = 0;
} elseif ($request->headers->has('Range')) {
} elseif ($request->getHeaders()->has('Range')) {
// Process the range headers.
if (!$request->headers->has('If-Range') || $this->getEtag() == $request->headers->get('If-Range')) {
$range = $request->headers->get('Range');
if (!$request->getHeaders()->has('If-Range')
|| $this->getEtag() == $request->getHeaders()->get('If-Range')
) {
$range = $request->getHeaders()->get('Range');
$fileSize = $this->file->getSize();

list($start, $end) = explode('-', substr($range, 6), 2) + array(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function setExpression(ExpressionLanguage $language, $expression)
$this->expression = $expression;
}

public function matches(Request $request)
public function matches(RequestInterface $request)
{
if (!$this->language) {
throw new \LogicException('Unable to match the request as the expression language is not available.');
Expand All @@ -41,7 +41,7 @@ public function matches(Request $request)
'path' => rawurldecode($request->getPathInfo()),
'host' => $request->getHost(),
'ip' => $request->getClientIp(),
'attributes' => $request->attributes->all(),
'attributes' => $request->getAttributes()->all(),
)) && parent::matches($request);
}
}
85 changes: 34 additions & 51 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @api
*/
class Request
class Request implements RequestInterface
{
const HEADER_CLIENT_IP = 'client_ip';
const HEADER_CLIENT_HOST = 'client_host';
Expand Down Expand Up @@ -963,9 +963,7 @@ public function getBaseUrl()
}

/**
* Gets the request's scheme.
*
* @return string
* {@inheritdoc}
*
* @api
*/
Expand Down Expand Up @@ -1210,18 +1208,7 @@ public function getQueryString()
}

/**
* Checks whether the request is secure or not.
*
* This method can read the client port from the "X-Forwarded-Proto" header
* when trusted proxies were set via "setTrustedProxies()".
*
* The "X-Forwarded-Proto" header must contain the protocol: "https" or "http".
*
* If your reverse proxy uses a different header name than "X-Forwarded-Proto"
* ("SSL_HTTPS" for instance), configure it via "setTrustedHeaderName()" with
* the "client-proto" key.
*
* @return bool
* {@inheritdoc}
*
* @api
*/
Expand Down Expand Up @@ -1311,17 +1298,7 @@ public function setMethod($method)
}

/**
* Gets the request "intended" method.
*
* If the X-HTTP-Method-Override header is set, and if the method is a POST,
* then it is used to determine the "real" intended HTTP method.
*
* The _method request parameter can also be used to determine the HTTP method,
* but only if enableHttpMethodParameterOverride() has been called.
*
* The method is always an uppercased string.
*
* @return string The request method
* {@inheritdoc}
*
* @api
*
Expand Down Expand Up @@ -1357,11 +1334,7 @@ public function getRealMethod()
}

/**
* Gets the mime type associated with the format.
*
* @param string $format The format
*
* @return string The associated mime type (null if not found)
* {@inheritdoc}
*
* @api
*/
Expand Down Expand Up @@ -1418,17 +1391,7 @@ public function setFormat($format, $mimeTypes)
}

/**
* Gets the request format.
*
* Here is the process to determine the format:
*
* * format defined by the user (with setRequestFormat())
* * _format request parameter
* * $default
*
* @param string $default The default format
*
* @return string The request format
* {@inheritdoc}
*
* @api
*/
Expand Down Expand Up @@ -1514,9 +1477,7 @@ public function getLocale()
}

/**
* Checks if the request method is of specified type.
*
* @param string $method Uppercase request method (GET, POST etc).
* {@inheritdoc}
*
* @return bool
*/
Expand Down Expand Up @@ -1566,9 +1527,7 @@ public function getContent($asResource = false)
}

/**
* Gets the Etags.
*
* @return array The entity tags
* {@inheritdoc}
*/
public function getETags()
{
Expand Down Expand Up @@ -1725,6 +1684,30 @@ public function isXmlHttpRequest()
return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
}

/**
* {@inheritdoc}
*/
public function getAttributes()
{
return $this->attributes;
}

/**
* {@inheritdoc}
*/
public function getHeaders()
{
return $this->headers;
}

/**
* {@inheritdoc}
*/
public function getServer()
{
return $this->server;
}

/*
* The following methods are derived from code of the Zend Framework (1.10dev - 2010-01-24)
*
Expand Down Expand Up @@ -1963,8 +1946,8 @@ private static function createRequestFromFactory(array $query = array(), array $
if (self::$requestFactory) {
$request = call_user_func(self::$requestFactory, $query, $request, $attributes, $cookies, $files, $server, $content);

if (!$request instanceof Request) {
throw new \LogicException('The Request factory must return an instance of Symfony\Component\HttpFoundation\Request.');
if (!$request instanceof RequestInterface) {
throw new \LogicException('The Request factory must return an instance of Symfony\Component\HttpFoundation\RequestInterface.');
}

return $request;
Expand Down
Loading
0