2023-07-02 22:08:14 -05:00
|
|
|
<?php
|
|
|
|
|
2023-07-15 09:02:42 -05:00
|
|
|
/*
|
|
|
|
* IntervalException.php
|
2023-10-29 11:41:14 -05:00
|
|
|
* Copyright (c) 2023 james@firefly-iii.org
|
2023-07-04 04:23:59 -05:00
|
|
|
*
|
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-07-15 09:02:42 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-10-29 11:41:14 -05:00
|
|
|
namespace FireflyIII\Exceptions;
|
2023-07-02 22:08:14 -05:00
|
|
|
|
|
|
|
use FireflyIII\Support\Calendar\Periodicity;
|
|
|
|
|
2023-07-04 06:29:19 -05:00
|
|
|
/**
|
|
|
|
* Class IntervalException
|
|
|
|
*/
|
2023-12-20 12:35:52 -06:00
|
|
|
final class IntervalException extends \Exception
|
2023-07-02 22:08:14 -05:00
|
|
|
{
|
2023-10-30 13:49:40 -05:00
|
|
|
public array $availableIntervals;
|
|
|
|
public Periodicity $periodicity;
|
2023-12-20 12:35:52 -06:00
|
|
|
|
2023-11-05 12:41:37 -06:00
|
|
|
/** @var mixed */
|
2023-11-04 08:09:51 -05:00
|
|
|
protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s';
|
2023-10-29 11:41:14 -05:00
|
|
|
|
2023-12-20 12:35:52 -06:00
|
|
|
public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null)
|
2023-10-29 11:41:14 -05:00
|
|
|
{
|
|
|
|
parent::__construct($message, $code, $previous);
|
|
|
|
$this->availableIntervals = [];
|
|
|
|
$this->periodicity = Periodicity::Monthly;
|
|
|
|
}
|
2023-07-02 22:08:14 -05:00
|
|
|
|
2023-07-04 04:23:59 -05:00
|
|
|
public static function unavailable(
|
|
|
|
Periodicity $periodicity,
|
|
|
|
array $intervals,
|
|
|
|
int $code = 0,
|
2024-02-22 13:11:09 -06:00
|
|
|
?\Throwable $previous = null
|
2023-12-20 12:35:52 -06:00
|
|
|
): self {
|
2024-01-01 07:43:56 -06:00
|
|
|
$message = sprintf(
|
2023-07-02 22:08:14 -05:00
|
|
|
'The periodicity %s is unknown. Choose one of available periodicity: %s',
|
|
|
|
$periodicity->name,
|
2023-11-04 08:18:49 -05:00
|
|
|
implode(', ', $intervals)
|
2023-07-02 22:08:14 -05:00
|
|
|
);
|
|
|
|
|
2023-11-04 08:18:49 -05:00
|
|
|
$exception = new self($message, $code, $previous);
|
2023-07-02 22:08:14 -05:00
|
|
|
$exception->periodicity = $periodicity;
|
2023-07-04 04:23:59 -05:00
|
|
|
$exception->availableIntervals = $intervals;
|
2023-12-20 12:35:52 -06:00
|
|
|
|
2023-07-02 22:08:14 -05:00
|
|
|
return $exception;
|
|
|
|
}
|
|
|
|
}
|