| 1 | <?php |
||
| 9 | class InvalidDirectory extends Exception |
||
| 10 | { |
||
| 11 | protected const MESSAGE_TEMPLATE = 'Invalid directory: `%s`.'; |
||
| 12 | |||
| 13 | private const CODE = 4002; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var null|string |
||
| 17 | */ |
||
| 18 | protected ?string $directory; |
||
|
|
|||
| 19 | |||
| 20 | /** |
||
| 21 | * @param string $directory Directory |
||
| 22 | * @param ExceptionContract $previous Previous Exception if nested exception |
||
| 23 | */ |
||
| 24 | public static function forDirectory(string $directory, ExceptionContract $previous = null): ExceptionContract |
||
| 25 | { |
||
| 26 | $message = sprintf(static::MESSAGE_TEMPLATE, $directory); |
||
| 27 | $self = new static($message, self::CODE, $previous); |
||
| 28 | $self->directory = $directory; |
||
| 29 | |||
| 30 | return $self; |
||
| 31 | } |
||
| 32 | |||
| 33 | final public function getDirectory(): ?string |
||
| 34 | { |
||
| 35 | return $this->directory; |
||
| 36 | } |
||
| 38 |