Skip to content

[HttpFoundation] [Response] Use constants for HTTP codes #9808

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 1 commit into from
Closed
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
32 changes: 16 additions & 16 deletions src/Symfony/Component/HttpFoundation/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Response
*
* @api
*/
public function __construct($content = '', $status = 200, $headers = array())
public function __construct($content = '', $status = self::HTTP_OK, $headers = array())
{
$this->headers = new ResponseHeaderBag($headers);
$this->setContent($content);
Expand All @@ -221,7 +221,7 @@ public function __construct($content = '', $status = 200, $headers = array())
*
* @return Response
*/
public static function create($content = '', $status = 200, $headers = array())
public static function create($content = '', $status = self::HTTP_OK, $headers = array())
{
return new static($content, $status, $headers);
}
Expand Down Expand Up @@ -268,7 +268,7 @@ public function prepare(Request $request)
{
$headers = $this->headers;

if ($this->isInformational() || in_array($this->statusCode, array(204, 304))) {
if ($this->isInformational() || in_array($this->statusCode, array(self::HTTP_NO_CONTENT, self::HTTP_NOT_MODIFIED))) {
$this->setContent(null);
}

Expand Down Expand Up @@ -558,7 +558,7 @@ public function getCharset()
*/
public function isCacheable()
{
if (!in_array($this->statusCode, array(200, 203, 300, 301, 302, 404, 410))) {
if (!in_array($this->statusCode, array(self::HTTP_OK, self::HTTP_NON_AUTHORITATIVE_INFORMATION, self::HTTP_MULTIPLE_CHOICES, self::HTTP_MOVED_PERMANENTLY, self::HTTP_FOUND, self::HTTP_NOT_FOUND, self::HTTP_GONE))) {
return false;
}

Expand Down Expand Up @@ -1016,7 +1016,7 @@ public function setCache(array $options)
*/
public function setNotModified()
{
$this->setStatusCode(304);
$this->setStatusCode(self::HTTP_NOT_MODIFIED);
$this->setContent(null);

// remove headers that MUST NOT be included with 304 Not Modified responses
Expand Down Expand Up @@ -1116,7 +1116,7 @@ public function isNotModified(Request $request)
*/
public function isInvalid()
{
return $this->statusCode < 100 || $this->statusCode >= 600;
return $this->statusCode < self::HTTP_CONTINUE || $this->statusCode >= 600;
}

/**
Expand All @@ -1128,7 +1128,7 @@ public function isInvalid()
*/
public function isInformational()
{
return $this->statusCode >= 100 && $this->statusCode < 200;
return $this->statusCode >= self::HTTP_CONTINUE && $this->statusCode < self::HTTP_OK;
}

/**
Expand All @@ -1140,7 +1140,7 @@ public function isInformational()
*/
public function isSuccessful()
{
return $this->statusCode >= 200 && $this->statusCode < 300;
return $this->statusCode >= self::HTTP_OK && $this->statusCode < self::HTTP_MULTIPLE_CHOICES;
}

/**
Expand All @@ -1152,7 +1152,7 @@ public function isSuccessful()
*/
public function isRedirection()
{
return $this->statusCode >= 300 && $this->statusCode < 400;
return $this->statusCode >= self::HTTP_MULTIPLE_CHOICES && $this->statusCode < self::HTTP_BAD_REQUEST;
}

/**
Expand All @@ -1164,7 +1164,7 @@ public function isRedirection()
*/
public function isClientError()
{
return $this->statusCode >= 400 && $this->statusCode < 500;
return $this->statusCode >= self::HTTP_BAD_REQUEST && $this->statusCode < self::HTTP_INTERNAL_SERVER_ERROR;
}

/**
Expand All @@ -1176,7 +1176,7 @@ public function isClientError()
*/
public function isServerError()
{
return $this->statusCode >= 500 && $this->statusCode < 600;
return $this->statusCode >= self::HTTP_INTERNAL_SERVER_ERROR && $this->statusCode < 600;
}

/**
Expand All @@ -1188,7 +1188,7 @@ public function isServerError()
*/
public function isOk()
{
return 200 === $this->statusCode;
return self::HTTP_OK === $this->statusCode;
}

/**
Expand All @@ -1200,7 +1200,7 @@ public function isOk()
*/
public function isForbidden()
{
return 403 === $this->statusCode;
return self::HTTP_FORBIDDEN === $this->statusCode;
}

/**
Expand All @@ -1212,7 +1212,7 @@ public function isForbidden()
*/
public function isNotFound()
{
return 404 === $this->statusCode;
return self::HTTP_NOT_FOUND === $this->statusCode;
}

/**
Expand All @@ -1226,7 +1226,7 @@ public function isNotFound()
*/
public function isRedirect($location = null)
{
return in_array($this->statusCode, array(201, 301, 302, 303, 307, 308)) && (null === $location ?: $location == $this->headers->get('Location'));
return in_array($this->statusCode, array(self::HTTP_CREATED, self::HTTP_MOVED_PERMANENTLY, self::HTTP_FOUND, self::HTTP_SEE_OTHER, self::HTTP_TEMPORARY_REDIRECT, self::HTTP_PERMANENTLY_REDIRECT)) && (null === $location ?: $location == $this->headers->get('Location'));
}

/**
Expand All @@ -1238,7 +1238,7 @@ public function isRedirect($location = null)
*/
public function isEmpty()
{
return in_array($this->statusCode, array(201, 204, 304));
return in_array($this->statusCode, array(self::HTTP_CREATED, self::HTTP_NO_CONTENT, self::HTTP_NOT_MODIFIED));
}

/**
Expand Down