use Larapie\Guard\Exceptions\ResolveFailedException;
7
8
/**
9
* Class Guard.
10
*/
11
abstract class Guard implements GuardContract
12
{
13
/**
14
* @var string
15
*/
16
protected $exception;
17
18
/**
19
* The exception that gets thrown when the condition is satisfied.
20
*
21
* @return \Throwable
22
* @throws ResolveFailedException
23
*/
24
public function exception(): \Throwable
25
{
26
return $this->resolveException($this->exception);
27
}
28
29
/**
30
* @param $exception
31
* @return \Throwable
32
* @throws ResolveFailedException
33
*/
34
protected function resolveException($exception) :\Throwable
35
{
36
if (is_string($exception) || ! ($exception instanceof \Throwable)) {
37
try {
38
$exception = new $exception;
39
} catch (\Exception $e) {
40
throw new ResolveFailedException('Could not resolve the string to an exception. It probably requires additional arguments. Try to pass it as an object');