@@ -54,8 +54,7 @@ |
||
| 54 | 54 | * @class EmitterInterface |
| 55 | 55 | * @package Platine\Framework\Http\Emitter |
| 56 | 56 | */ |
| 57 | -interface EmitterInterface |
|
| 58 | -{
|
|
| 57 | +interface EmitterInterface { |
|
| 59 | 58 | /** |
| 60 | 59 | * Emits a HTTP response, that including status line, headers and message |
| 61 | 60 | * body, according to the environment. |
@@ -58,8 +58,7 @@ discard block |
||
| 58 | 58 | * @class ResponseEmitter |
| 59 | 59 | * @package Platine\Framework\Http\Emitter |
| 60 | 60 | */ |
| 61 | -class ResponseEmitter implements EmitterInterface |
|
| 62 | -{
|
|
| 61 | +class ResponseEmitter implements EmitterInterface { |
|
| 63 | 62 | /** |
| 64 | 63 | * The response buffer length |
| 65 | 64 | * @var int|null |
@@ -70,9 +69,8 @@ discard block |
||
| 70 | 69 | * Create new instance |
| 71 | 70 | * @param int|null $bufferLength |
| 72 | 71 | */ |
| 73 | - public function __construct(?int $bufferLength = null) |
|
| 74 | - {
|
|
| 75 | - if ($bufferLength !== null && $bufferLength < 1) {
|
|
| 72 | + public function __construct(?int $bufferLength = null) { |
|
| 73 | + if ($bufferLength !== null && $bufferLength < 1) { |
|
| 76 | 74 | throw new InvalidArgumentException(sprintf( |
| 77 | 75 | 'The response buffer length must be greater than zero; received [%d].', |
| 78 | 76 | $bufferLength |
@@ -87,18 +85,18 @@ discard block |
||
| 87 | 85 | */ |
| 88 | 86 | public function emit(ResponseInterface $response, bool $withBody = true): void |
| 89 | 87 | {
|
| 90 | - if (headers_sent()) {
|
|
| 88 | + if (headers_sent()) { |
|
| 91 | 89 | throw HeadersAlreadySentException::create(); |
| 92 | 90 | } |
| 93 | 91 | |
| 94 | - if (ob_get_level() > 0 && ob_get_length() > 0) {
|
|
| 92 | + if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
| 95 | 93 | throw OutputAlreadySentException::create(); |
| 96 | 94 | } |
| 97 | 95 | |
| 98 | 96 | $this->emitHeaders($response); |
| 99 | 97 | $this->emitStatusLine($response); |
| 100 | 98 | |
| 101 | - if ($withBody && $response->getBody()->isReadable()) {
|
|
| 99 | + if ($withBody && $response->getBody()->isReadable()) { |
|
| 102 | 100 | $this->emitBody($response); |
| 103 | 101 | } |
| 104 | 102 | } |
@@ -110,7 +108,7 @@ discard block |
||
| 110 | 108 | */ |
| 111 | 109 | protected function emitHeaders(ResponseInterface $response): void |
| 112 | 110 | {
|
| 113 | - foreach ($response->getHeaders() as $name => $values) {
|
|
| 111 | + foreach ($response->getHeaders() as $name => $values) { |
|
| 114 | 112 | $name = str_replace( |
| 115 | 113 | ' ', |
| 116 | 114 | '-', |
@@ -118,7 +116,7 @@ discard block |
||
| 118 | 116 | ); |
| 119 | 117 | |
| 120 | 118 | $isFirst = $name !== 'Set-Cookie'; |
| 121 | - foreach ($values as $value) {
|
|
| 119 | + foreach ($values as $value) { |
|
| 122 | 120 | $header = sprintf('%s: %s', $name, $value);
|
| 123 | 121 | header($header, $isFirst); |
| 124 | 122 | $isFirst = false; |
@@ -148,7 +146,7 @@ discard block |
||
| 148 | 146 | */ |
| 149 | 147 | protected function emitBody(ResponseInterface $response): void |
| 150 | 148 | {
|
| 151 | - if ($this->bufferLength === null) {
|
|
| 149 | + if ($this->bufferLength === null) { |
|
| 152 | 150 | echo $response->getBody(); |
| 153 | 151 | return; |
| 154 | 152 | } |
@@ -159,16 +157,16 @@ discard block |
||
| 159 | 157 | $response->getHeaderLine('content-range')
|
| 160 | 158 | ); |
| 161 | 159 | |
| 162 | - if (isset($range['unit']) && $range['unit'] === 'bytes') {
|
|
| 160 | + if (isset($range['unit']) && $range['unit'] === 'bytes') { |
|
| 163 | 161 | $this->emitBodyRange($body, $range['first'], $range['last']); |
| 164 | 162 | return; |
| 165 | 163 | } |
| 166 | 164 | |
| 167 | - if ($body->isSeekable()) {
|
|
| 165 | + if ($body->isSeekable()) { |
|
| 168 | 166 | $body->rewind(); |
| 169 | 167 | } |
| 170 | 168 | |
| 171 | - while (!$body->eof()) {
|
|
| 169 | + while (!$body->eof()) { |
|
| 172 | 170 | echo $body->read($this->bufferLength); |
| 173 | 171 | } |
| 174 | 172 | } |
@@ -183,18 +181,18 @@ discard block |
||
| 183 | 181 | protected function emitBodyRange(StreamInterface $body, int $first, int $last): void |
| 184 | 182 | {
|
| 185 | 183 | $length = $last - $first + 1; |
| 186 | - if ($body->isSeekable()) {
|
|
| 184 | + if ($body->isSeekable()) { |
|
| 187 | 185 | $body->seek($first); |
| 188 | 186 | } |
| 189 | 187 | |
| 190 | - while ($length >= $this->bufferLength && !$body->eof()) {
|
|
| 188 | + while ($length >= $this->bufferLength && !$body->eof()) { |
|
| 191 | 189 | $contents = $body->read((int) $this->bufferLength); |
| 192 | 190 | $length -= strlen($contents); |
| 193 | 191 | |
| 194 | 192 | echo $contents; |
| 195 | 193 | } |
| 196 | 194 | |
| 197 | - if ($length > 0 && !$body->eof()) {
|
|
| 195 | + if ($length > 0 && !$body->eof()) { |
|
| 198 | 196 | echo $body->read($length); |
| 199 | 197 | } |
| 200 | 198 | } |
@@ -214,7 +212,7 @@ discard block |
||
| 214 | 212 | $header, |
| 215 | 213 | $matches |
| 216 | 214 | ) |
| 217 | - ) {
|
|
| 215 | + ) { |
|
| 218 | 216 | return [ |
| 219 | 217 | 'unit' => $matches['unit'], |
| 220 | 218 | 'first' => (int) $matches['first'], |
@@ -40,8 +40,7 @@ |
||
| 40 | 40 | * @class OutputAlreadySentException |
| 41 | 41 | * @package Platine\Http\Framework\Emitter\Exception |
| 42 | 42 | */ |
| 43 | -class OutputAlreadySentException extends RuntimeException |
|
| 44 | -{
|
|
| 43 | +class OutputAlreadySentException extends RuntimeException { |
|
| 45 | 44 | /** |
| 46 | 45 | * Create new instance |
| 47 | 46 | * @return self |
@@ -40,8 +40,7 @@ |
||
| 40 | 40 | * @class HeadersAlreadySentException |
| 41 | 41 | * @package Platine\Framework\Http\Emitter\Exception |
| 42 | 42 | */ |
| 43 | -class HeadersAlreadySentException extends RuntimeException |
|
| 44 | -{
|
|
| 43 | +class HeadersAlreadySentException extends RuntimeException { |
|
| 45 | 44 | /** |
| 46 | 45 | * Create new instance |
| 47 | 46 | * @return self |
@@ -56,8 +56,7 @@ discard block |
||
| 56 | 56 | * @package Platine\Framework\Http\Maintenance\Driver |
| 57 | 57 | * @template T |
| 58 | 58 | */ |
| 59 | -class FileMaintenanceDriver implements MaintenanceDriverInterface |
|
| 60 | -{
|
|
| 59 | +class FileMaintenanceDriver implements MaintenanceDriverInterface { |
|
| 61 | 60 | /** |
| 62 | 61 | * The application configuration |
| 63 | 62 | * @var Config<T> |
@@ -75,8 +74,7 @@ discard block |
||
| 75 | 74 | * @param Config<T> $config |
| 76 | 75 | * @param Filesystem $filesystem |
| 77 | 76 | */ |
| 78 | - public function __construct(Config $config, Filesystem $filesystem) |
|
| 79 | - {
|
|
| 77 | + public function __construct(Config $config, Filesystem $filesystem) { |
|
| 80 | 78 | $this->config = $config; |
| 81 | 79 | $this->filesystem = $filesystem; |
| 82 | 80 | } |
@@ -107,7 +105,7 @@ discard block |
||
| 107 | 105 | */ |
| 108 | 106 | public function deactivate(): void |
| 109 | 107 | {
|
| 110 | - if ($this->active()) {
|
|
| 108 | + if ($this->active()) { |
|
| 111 | 109 | $path = $this->getFilePath(); |
| 112 | 110 | $this->filesystem->file($path)->delete(); |
| 113 | 111 | } |
@@ -51,8 +51,7 @@ |
||
| 51 | 51 | * @class MaintenanceDriverInterface |
| 52 | 52 | * @package Platine\Framework\Http\Maintenance |
| 53 | 53 | */ |
| 54 | -interface MaintenanceDriverInterface |
|
| 55 | -{
|
|
| 54 | +interface MaintenanceDriverInterface { |
|
| 56 | 55 | /** |
| 57 | 56 | * Whether the maintenance is active or not |
| 58 | 57 | * @return bool |
@@ -41,8 +41,7 @@ discard block |
||
| 41 | 41 | * @class HttpException |
| 42 | 42 | * @package Platine\Framework\Http\Exception |
| 43 | 43 | */ |
| 44 | -class HttpException extends Exception |
|
| 45 | -{
|
|
| 44 | +class HttpException extends Exception { |
|
| 46 | 45 | /** |
| 47 | 46 | * The instance of server request that throw this exception |
| 48 | 47 | * @var ServerRequestInterface |
@@ -79,7 +78,7 @@ discard block |
||
| 79 | 78 | string $message = '', |
| 80 | 79 | int $code = 0, |
| 81 | 80 | ?Throwable $previous = null |
| 82 | - ) {
|
|
| 81 | + ) { |
|
| 83 | 82 | parent::__construct($message, $code, $previous); |
| 84 | 83 | $this->request = $request; |
| 85 | 84 | } |
@@ -40,8 +40,7 @@ discard block |
||
| 40 | 40 | * @class HttpNotFoundException |
| 41 | 41 | * @package Platine\Framework\Http\Exception |
| 42 | 42 | */ |
| 43 | -class HttpNotFoundException extends HttpSpecialException |
|
| 44 | -{
|
|
| 43 | +class HttpNotFoundException extends HttpSpecialException { |
|
| 45 | 44 | /** |
| 46 | 45 | * |
| 47 | 46 | * @var int |
@@ -66,7 +65,7 @@ discard block |
||
| 66 | 65 | ServerRequestInterface $request, |
| 67 | 66 | ?string $message = null, |
| 68 | 67 | ?Throwable $previous = null |
| 69 | - ) {
|
|
| 68 | + ) { |
|
| 70 | 69 | parent::__construct($request, $message, $previous); |
| 71 | 70 | |
| 72 | 71 | $this->description = sprintf( |
@@ -39,8 +39,7 @@ |
||
| 39 | 39 | * @class HttpForbiddenException |
| 40 | 40 | * @package Platine\Framework\Http\Exception |
| 41 | 41 | */ |
| 42 | -class HttpForbiddenException extends HttpSpecialException |
|
| 43 | -{
|
|
| 42 | +class HttpForbiddenException extends HttpSpecialException { |
|
| 44 | 43 | /** |
| 45 | 44 | * |
| 46 | 45 | * @var int |