2023-07-02 22:08:14 -05:00
|
|
|
<?php
|
|
|
|
|
2023-07-04 06:29:19 -05:00
|
|
|
|
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
|
|
|
|
2023-07-15 09:02:42 -05:00
|
|
|
use Exception;
|
2023-07-02 22:08:14 -05:00
|
|
|
use FireflyIII\Support\Calendar\Periodicity;
|
2023-07-15 09:02:42 -05:00
|
|
|
use Throwable;
|
2023-07-02 22:08:14 -05:00
|
|
|
|
2023-07-04 06:29:19 -05:00
|
|
|
/**
|
|
|
|
* Class IntervalException
|
|
|
|
*/
|
2023-07-15 09:02:42 -05: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-11-04 05:31:14 -05:00
|
|
|
/** @var string */
|
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-11-04 05:31:14 -05: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 06:29:19 -05:00
|
|
|
/**
|
2023-07-15 09:02:42 -05:00
|
|
|
* @param Periodicity $periodicity
|
|
|
|
* @param array $intervals
|
|
|
|
* @param int $code
|
|
|
|
* @param Throwable|null $previous
|
|
|
|
*
|
2023-07-04 06:29:19 -05:00
|
|
|
* @return IntervalException
|
|
|
|
*/
|
2023-07-04 04:23:59 -05:00
|
|
|
public static function unavailable(
|
|
|
|
Periodicity $periodicity,
|
|
|
|
array $intervals,
|
|
|
|
int $code = 0,
|
2023-07-15 09:02:42 -05:00
|
|
|
?Throwable $previous = null
|
2023-11-04 08:09:51 -05:00
|
|
|
): IntervalException {
|
2023-07-02 22:08:14 -05:00
|
|
|
$message = sprintf(
|
|
|
|
'The periodicity %s is unknown. Choose one of available periodicity: %s',
|
|
|
|
$periodicity->name,
|
2023-07-04 04:23:59 -05:00
|
|
|
join(', ', $intervals)
|
2023-07-02 22:08:14 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
$exception = new IntervalException($message, $code, $previous);
|
|
|
|
$exception->periodicity = $periodicity;
|
2023-07-04 04:23:59 -05:00
|
|
|
$exception->availableIntervals = $intervals;
|
2023-07-02 22:08:14 -05:00
|
|
|
return $exception;
|
|
|
|
}
|
|
|
|
}
|