-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathHttpException.php
More file actions
72 lines (65 loc) · 2.04 KB
/
Copy pathHttpException.php
File metadata and controls
72 lines (65 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @since 3.0.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Http\Exception;
use Cake\Core\Exception\CakeException;
use Cake\Core\Exception\HttpErrorCodeInterface;
/**
* Parent class for all the HTTP related exceptions in CakePHP.
* All HTTP status/error related exceptions should extend this class so
* catch blocks can be specifically typed.
*
* You may also use this as a meaningful bridge to {@link \Cake\Core\Exception\CakeException}, e.g.:
* throw new \Cake\Network\Exception\HttpException('HTTP Version Not Supported', 505);
*/
class HttpException extends CakeException implements HttpErrorCodeInterface
{
/**
* @inheritDoc
*/
protected int $_defaultCode = 500;
/**
* @var array<non-empty-string, array<string>|string>
*/
protected array $headers = [];
/**
* Set a single HTTP response header.
*
* @param non-empty-string $header Header name
* @param array<string>|string|null $value Header value
* @return void
*/
public function setHeader(string $header, array|string|null $value = null): void
{
$this->headers[$header] = $value ?? '';
}
/**
* Sets HTTP response headers.
*
* @param array<non-empty-string, array<string>|string> $headers Array of header name and value pairs.
* @return void
*/
public function setHeaders(array $headers): void
{
$this->headers = $headers;
}
/**
* Returns array of response headers.
*
* @return array<non-empty-string, array<string>|string>
*/
public function getHeaders(): array
{
return $this->headers;
}
}