Skip to content

Commit

Permalink
Merge branch 'release/0.8.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
pprkut committed Dec 13, 2023
2 parents bf174b1 + 8a7cf2a commit a12cd05
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 194 deletions.
126 changes: 1 addition & 125 deletions src/Lunr/Corona/Exceptions/BadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,9 @@
/**
* Exception for the Bad Request HTTP error (400).
*/
class BadRequestException extends HttpException
class BadRequestException extends ClientDataHttpException
{

/**
* Input data key.
* @var string
*/
protected string $key;

/**
* Input data value
* @var mixed
*/
protected $value;

/**
* Report data
* @var string
*/
protected string $report;

/**
* Constructor.
*
Expand All @@ -49,112 +31,6 @@ public function __construct(?string $message = NULL, int $app_code = 0, Exceptio
parent::__construct($message, HttpCode::BAD_REQUEST, $app_code, $previous);
}

/**
* Set input data that caused the bad request.
*
* @param string $key Key/URL parameter name
* @param mixed $value Input value
*
* @return void
*/
public function setData(string $key, $value): void
{
$this->key = $key;
$this->value = $value;
}

/**
* Set report data about the bad request.
*
* @param string $data Report data
*
* @return void
*/
public function setReport(string $data): void
{
if ($data === '')
{
return;
}

$this->report = $data;
}

/**
* Set report data about the bad request.
*
* @param array $failures Failure messages per key
*
* @return void
*/
public function setArrayReport(array $failures): void
{
if ($failures === [])
{
return;
}

$this->report = '';

foreach ($failures as $key => $messages)
{
foreach ($messages as $message)
{
$this->report .= "$key: $message\n";
}
}
}

/**
* Get the input data key.
*
* @return string|null Input data key
*/
public function getDataKey(): ?string
{
return $this->key;
}

/**
* Get the input data value.
*
* @return mixed Input data value
*/
public function getDataValue()
{
return $this->value;
}

/**
* Get the detailed input data report.
*
* @return string Detailed input data report
*/
public function getReport(): ?string
{
return $this->report;
}

/**
* Check whether input data was set or not.
*
* @return bool Input data was set or not.
*/
public function isDataAvailable(): bool
{
return isset($this->key);
}

/**
* Check whether a detailed input data report was set or not.
*
* @return bool Input data report was set or not.
*/
public function isReportAvailable(): bool
{
return isset($this->report);
}

}

?>
159 changes: 159 additions & 0 deletions src/Lunr/Corona/Exceptions/ClientDataHttpException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php

/**
* This file contains the ClientDataHttpException class.
*
* SPDX-FileCopyrightText: Copyright 2023 Move Agency Group B.V., Zwolle, The Netherlands
* SPDX-License-Identifier: MIT
*/

namespace Lunr\Corona\Exceptions;

use Exception;

/**
* Exception for a client data HTTP result.
*/
abstract class ClientDataHttpException extends HttpException
{

/**
* Input data key.
* @var string
*/
protected string $key;

/**
* Input data value
* @var mixed
*/
protected $value;

/**
* Report data
* @var string
*/
protected string $report;

/**
* Constructor.
*
* @param string|null $message Error message
* @param int $code Http code
* @param int $app_code Application error code
* @param Exception|null $previous The previously thrown exception
*/
public function __construct(?string $message = NULL, int $code = 0, int $app_code = 0, Exception $previous = NULL)
{
parent::__construct($message, $code, $app_code, $previous);
}

/**
* Set input data that caused the request.
*
* @param string $key Key/URL parameter name
* @param mixed $value Input value
*
* @return void
*/
public function setData(string $key, $value): void
{
$this->key = $key;
$this->value = $value;
}

/**
* Set report data about the request.
*
* @param string $data Report data
*
* @return void
*/
public function setReport(string $data): void
{
if ($data === '')
{
return;
}

$this->report = $data;
}

/**
* Set report data about the request.
*
* @param array $failures Failure messages per key
*
* @return void
*/
public function setArrayReport(array $failures): void
{
if ($failures === [])
{
return;
}

$this->report = '';

foreach ($failures as $key => $messages)
{
foreach ($messages as $message)
{
$this->report .= "$key: $message\n";
}
}
}

/**
* Get the input data key.
*
* @return string|null Input data key
*/
public function getDataKey(): ?string
{
return $this->key;
}

/**
* Get the input data value.
*
* @return mixed Input data value
*/
public function getDataValue()
{
return $this->value;
}

/**
* Get the detailed input data report.
*
* @return string Detailed input data report
*/
public function getReport(): ?string
{
return $this->report;
}

/**
* Check whether input data was set or not.
*
* @return bool Input data was set or not.
*/
public function isDataAvailable(): bool
{
return isset($this->key);
}

/**
* Check whether a detailed input data report was set or not.
*
* @return bool Input data report was set or not.
*/
public function isReportAvailable(): bool
{
return isset($this->report);
}

}

?>
58 changes: 1 addition & 57 deletions src/Lunr/Corona/Exceptions/ForbiddenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,9 @@
/**
* Exception for the Forbidden HTTP error (403).
*/
class ForbiddenException extends HttpException
class ForbiddenException extends ClientDataHttpException
{

/**
* Input data key.
* @var string
*/
protected string $key;

/**
* Input data value
* @var mixed
*/
protected $value;

/**
* Constructor.
*
Expand All @@ -43,50 +31,6 @@ public function __construct(?string $message = NULL, int $app_code = 0, Exceptio
parent::__construct($message, HttpCode::FORBIDDEN, $app_code, $previous);
}

/**
* Set input data that caused the forbidden request.
*
* @param string $key Key/URL parameter name
* @param mixed $value Input value
*
* @return void
*/
public function setData(string $key, $value): void
{
$this->key = $key;
$this->value = $value;
}

/**
* Get the input data key.
*
* @return string Input data key
*/
public function getDataKey(): string
{
return $this->key;
}

/**
* Get the input data value.
*
* @return mixed Input data value
*/
public function getDataValue()
{
return $this->value;
}

/**
* Check whether input data was set or not.
*
* @return bool Input data was set or not.
*/
public function isDataAvailable(): bool
{
return isset($this->key);
}

}

?>
Loading

0 comments on commit a12cd05

Please sign in to comment.