1: <?php
2:
3: /**
4: * Copyright 2015, Eduardo Trujillo
5: *
6: * For the full copyright and license information, please view the LICENSE
7: * file that was distributed with this source code.
8: *
9: * This file is part of the Nucleus package
10: */
11:
12: namespace Chromabits\Nucleus\Meditation\Exceptions;
13:
14: use Chromabits\Nucleus\Exceptions\CoreException;
15: use Chromabits\Nucleus\Meditation\Interfaces\CheckableInterface;
16: use Chromabits\Nucleus\Meditation\Interfaces\CheckResultInterface;
17: use Exception;
18:
19: /**
20: * Class FailedSpecException.
21: *
22: * Thrown when a check fails (most commonly a Spec or Validator). This
23: * exception is available for cases when it is useful to raise the failed
24: * status of a check into an exception, however, Spec/Validators won't throw
25: * by default whenever a check fails.
26: *
27: * @author Eduardo Trujillo <ed@chromabits.com>
28: * @package Chromabits\Nucleus\Meditation\Exceptions
29: */
30: class FailedCheckException extends CoreException
31: {
32: /**
33: * @var CheckableInterface
34: */
35: protected $checkable;
36:
37: /**
38: * @var CheckResultInterface
39: */
40: protected $result;
41:
42: /**
43: * Construct an instance of a FailedCheckException.
44: *
45: * @param CheckableInterface $checkable
46: * @param CheckResultInterface $result
47: * @param string $message
48: * @param int $code
49: * @param Exception|null $previous
50: */
51: public function __construct(
52: CheckableInterface $checkable,
53: CheckResultInterface $result,
54: $message = '',
55: $code = 0,
56: Exception $previous = null
57: ) {
58: parent::__construct($message, $code, $previous);
59:
60: $this->checkable = $checkable;
61: $this->result = $result;
62: }
63:
64: /**
65: * Get the class used to check the failed input.
66: *
67: * @return CheckableInterface
68: */
69: public function getCheckable()
70: {
71: return $this->checkable;
72: }
73:
74: /**
75: * Get the result of the check operation.
76: *
77: * @return CheckResultInterface
78: */
79: public function getResult()
80: {
81: return $this->result;
82: }
83: }
84: