Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | namespace LdapRecord; |
| 4 | |
| 5 | use Exception; |
| 6 | |
| 7 | class LdapRecordException extends Exception |
| 8 | { |
| 9 | /** |
| 10 | * The detailed LDAP error (if available). |
| 11 | * |
| 12 | * @var DetailedError|null |
| 13 | */ |
| 14 | protected $detailedError; |
| 15 | |
| 16 | /** |
| 17 | * Create a new Bind Exception with a detailed connection error. |
| 18 | * |
| 19 | * @param Exception $e |
| 20 | * @param DetailedError|null $error |
| 21 | * |
| 22 | * @return $this |
| 23 | */ |
| 24 | public static function withDetailedError(Exception $e, DetailedError $error = null) |
| 25 | { |
| 26 | return (new static($e->getMessage(), $e->getCode(), $e))->setDetailedError($error); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Set the detailed error. |
| 31 | * |
| 32 | * @param DetailedError|null $error |
| 33 | * |
| 34 | * @return $this |
| 35 | */ |
| 36 | public function setDetailedError(DetailedError $error = null) |
| 37 | { |
| 38 | $this->detailedError = $error; |
| 39 | |
| 40 | return $this; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the detailed error. |
| 45 | * |
| 46 | * @return DetailedError|null |
| 47 | */ |
| 48 | public function getDetailedError() |
| 49 | { |
| 50 | return $this->detailedError; |
| 51 | } |
| 52 | } |