Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame^] | 1 | <?php namespace Sieve; |
| 2 | |
| 3 | require_once('SieveToken.php'); |
| 4 | |
| 5 | use Exception; |
| 6 | |
| 7 | class SieveException extends Exception |
| 8 | { |
| 9 | protected $token_; |
| 10 | |
| 11 | public function __construct(SieveToken $token, $arg) |
| 12 | { |
| 13 | $message = 'undefined sieve exception'; |
| 14 | $this->token_ = $token; |
| 15 | |
| 16 | if (is_string($arg)) |
| 17 | { |
| 18 | $message = $arg; |
| 19 | } |
| 20 | else |
| 21 | { |
| 22 | if (is_array($arg)) |
| 23 | { |
| 24 | $type = SieveToken::typeString(array_shift($arg)); |
| 25 | foreach($arg as $t) |
| 26 | { |
| 27 | $type .= ' or '. SieveToken::typeString($t); |
| 28 | } |
| 29 | } |
| 30 | else |
| 31 | { |
| 32 | $type = SieveToken::typeString($arg); |
| 33 | } |
| 34 | |
| 35 | $tokenType = SieveToken::typeString($token->type); |
| 36 | $message = "$tokenType where $type expected near ". $token->text; |
| 37 | } |
| 38 | |
| 39 | parent::__construct('line '. $token->line .": $message"); |
| 40 | } |
| 41 | |
| 42 | public function getLineNo() |
| 43 | { |
| 44 | return $this->token_->line; |
| 45 | } |
| 46 | |
| 47 | } |