Skip to content

Commit a12cd05

Browse files
committed
Merge branch 'release/0.8.x'
2 parents bf174b1 + 8a7cf2a commit a12cd05

10 files changed

+574
-194
lines changed

src/Lunr/Corona/Exceptions/BadRequestException.php

Lines changed: 1 addition & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,9 @@
1616
/**
1717
* Exception for the Bad Request HTTP error (400).
1818
*/
19-
class BadRequestException extends HttpException
19+
class BadRequestException extends ClientDataHttpException
2020
{
2121

22-
/**
23-
* Input data key.
24-
* @var string
25-
*/
26-
protected string $key;
27-
28-
/**
29-
* Input data value
30-
* @var mixed
31-
*/
32-
protected $value;
33-
34-
/**
35-
* Report data
36-
* @var string
37-
*/
38-
protected string $report;
39-
4022
/**
4123
* Constructor.
4224
*
@@ -49,112 +31,6 @@ public function __construct(?string $message = NULL, int $app_code = 0, Exceptio
4931
parent::__construct($message, HttpCode::BAD_REQUEST, $app_code, $previous);
5032
}
5133

52-
/**
53-
* Set input data that caused the bad request.
54-
*
55-
* @param string $key Key/URL parameter name
56-
* @param mixed $value Input value
57-
*
58-
* @return void
59-
*/
60-
public function setData(string $key, $value): void
61-
{
62-
$this->key = $key;
63-
$this->value = $value;
64-
}
65-
66-
/**
67-
* Set report data about the bad request.
68-
*
69-
* @param string $data Report data
70-
*
71-
* @return void
72-
*/
73-
public function setReport(string $data): void
74-
{
75-
if ($data === '')
76-
{
77-
return;
78-
}
79-
80-
$this->report = $data;
81-
}
82-
83-
/**
84-
* Set report data about the bad request.
85-
*
86-
* @param array $failures Failure messages per key
87-
*
88-
* @return void
89-
*/
90-
public function setArrayReport(array $failures): void
91-
{
92-
if ($failures === [])
93-
{
94-
return;
95-
}
96-
97-
$this->report = '';
98-
99-
foreach ($failures as $key => $messages)
100-
{
101-
foreach ($messages as $message)
102-
{
103-
$this->report .= "$key: $message\n";
104-
}
105-
}
106-
}
107-
108-
/**
109-
* Get the input data key.
110-
*
111-
* @return string|null Input data key
112-
*/
113-
public function getDataKey(): ?string
114-
{
115-
return $this->key;
116-
}
117-
118-
/**
119-
* Get the input data value.
120-
*
121-
* @return mixed Input data value
122-
*/
123-
public function getDataValue()
124-
{
125-
return $this->value;
126-
}
127-
128-
/**
129-
* Get the detailed input data report.
130-
*
131-
* @return string Detailed input data report
132-
*/
133-
public function getReport(): ?string
134-
{
135-
return $this->report;
136-
}
137-
138-
/**
139-
* Check whether input data was set or not.
140-
*
141-
* @return bool Input data was set or not.
142-
*/
143-
public function isDataAvailable(): bool
144-
{
145-
return isset($this->key);
146-
}
147-
148-
/**
149-
* Check whether a detailed input data report was set or not.
150-
*
151-
* @return bool Input data report was set or not.
152-
*/
153-
public function isReportAvailable(): bool
154-
{
155-
return isset($this->report);
156-
}
157-
15834
}
15935

16036
?>
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
3+
/**
4+
* This file contains the ClientDataHttpException class.
5+
*
6+
* SPDX-FileCopyrightText: Copyright 2023 Move Agency Group B.V., Zwolle, The Netherlands
7+
* SPDX-License-Identifier: MIT
8+
*/
9+
10+
namespace Lunr\Corona\Exceptions;
11+
12+
use Exception;
13+
14+
/**
15+
* Exception for a client data HTTP result.
16+
*/
17+
abstract class ClientDataHttpException extends HttpException
18+
{
19+
20+
/**
21+
* Input data key.
22+
* @var string
23+
*/
24+
protected string $key;
25+
26+
/**
27+
* Input data value
28+
* @var mixed
29+
*/
30+
protected $value;
31+
32+
/**
33+
* Report data
34+
* @var string
35+
*/
36+
protected string $report;
37+
38+
/**
39+
* Constructor.
40+
*
41+
* @param string|null $message Error message
42+
* @param int $code Http code
43+
* @param int $app_code Application error code
44+
* @param Exception|null $previous The previously thrown exception
45+
*/
46+
public function __construct(?string $message = NULL, int $code = 0, int $app_code = 0, Exception $previous = NULL)
47+
{
48+
parent::__construct($message, $code, $app_code, $previous);
49+
}
50+
51+
/**
52+
* Set input data that caused the request.
53+
*
54+
* @param string $key Key/URL parameter name
55+
* @param mixed $value Input value
56+
*
57+
* @return void
58+
*/
59+
public function setData(string $key, $value): void
60+
{
61+
$this->key = $key;
62+
$this->value = $value;
63+
}
64+
65+
/**
66+
* Set report data about the request.
67+
*
68+
* @param string $data Report data
69+
*
70+
* @return void
71+
*/
72+
public function setReport(string $data): void
73+
{
74+
if ($data === '')
75+
{
76+
return;
77+
}
78+
79+
$this->report = $data;
80+
}
81+
82+
/**
83+
* Set report data about the request.
84+
*
85+
* @param array $failures Failure messages per key
86+
*
87+
* @return void
88+
*/
89+
public function setArrayReport(array $failures): void
90+
{
91+
if ($failures === [])
92+
{
93+
return;
94+
}
95+
96+
$this->report = '';
97+
98+
foreach ($failures as $key => $messages)
99+
{
100+
foreach ($messages as $message)
101+
{
102+
$this->report .= "$key: $message\n";
103+
}
104+
}
105+
}
106+
107+
/**
108+
* Get the input data key.
109+
*
110+
* @return string|null Input data key
111+
*/
112+
public function getDataKey(): ?string
113+
{
114+
return $this->key;
115+
}
116+
117+
/**
118+
* Get the input data value.
119+
*
120+
* @return mixed Input data value
121+
*/
122+
public function getDataValue()
123+
{
124+
return $this->value;
125+
}
126+
127+
/**
128+
* Get the detailed input data report.
129+
*
130+
* @return string Detailed input data report
131+
*/
132+
public function getReport(): ?string
133+
{
134+
return $this->report;
135+
}
136+
137+
/**
138+
* Check whether input data was set or not.
139+
*
140+
* @return bool Input data was set or not.
141+
*/
142+
public function isDataAvailable(): bool
143+
{
144+
return isset($this->key);
145+
}
146+
147+
/**
148+
* Check whether a detailed input data report was set or not.
149+
*
150+
* @return bool Input data report was set or not.
151+
*/
152+
public function isReportAvailable(): bool
153+
{
154+
return isset($this->report);
155+
}
156+
157+
}
158+
159+
?>

src/Lunr/Corona/Exceptions/ForbiddenException.php

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,9 @@
1616
/**
1717
* Exception for the Forbidden HTTP error (403).
1818
*/
19-
class ForbiddenException extends HttpException
19+
class ForbiddenException extends ClientDataHttpException
2020
{
2121

22-
/**
23-
* Input data key.
24-
* @var string
25-
*/
26-
protected string $key;
27-
28-
/**
29-
* Input data value
30-
* @var mixed
31-
*/
32-
protected $value;
33-
3422
/**
3523
* Constructor.
3624
*
@@ -43,50 +31,6 @@ public function __construct(?string $message = NULL, int $app_code = 0, Exceptio
4331
parent::__construct($message, HttpCode::FORBIDDEN, $app_code, $previous);
4432
}
4533

46-
/**
47-
* Set input data that caused the forbidden request.
48-
*
49-
* @param string $key Key/URL parameter name
50-
* @param mixed $value Input value
51-
*
52-
* @return void
53-
*/
54-
public function setData(string $key, $value): void
55-
{
56-
$this->key = $key;
57-
$this->value = $value;
58-
}
59-
60-
/**
61-
* Get the input data key.
62-
*
63-
* @return string Input data key
64-
*/
65-
public function getDataKey(): string
66-
{
67-
return $this->key;
68-
}
69-
70-
/**
71-
* Get the input data value.
72-
*
73-
* @return mixed Input data value
74-
*/
75-
public function getDataValue()
76-
{
77-
return $this->value;
78-
}
79-
80-
/**
81-
* Check whether input data was set or not.
82-
*
83-
* @return bool Input data was set or not.
84-
*/
85-
public function isDataAvailable(): bool
86-
{
87-
return isset($this->key);
88-
}
89-
9034
}
9135

9236
?>

0 commit comments

Comments
 (0)