blob: da7fe60459d76c28c4911b6af26ee27255da88f4 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php namespace Sieve;
2
3require_once('SieveToken.php');
4
5use Exception;
6
7class 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}