SieveException.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php namespace Sieve;
  2. require_once('SieveToken.php');
  3. use Exception;
  4. class SieveException extends Exception
  5. {
  6. protected $token_;
  7. public function __construct(SieveToken $token, $arg)
  8. {
  9. $message = 'undefined sieve exception';
  10. $this->token_ = $token;
  11. if (is_string($arg))
  12. {
  13. $message = $arg;
  14. }
  15. else
  16. {
  17. if (is_array($arg))
  18. {
  19. $type = SieveToken::typeString(array_shift($arg));
  20. foreach($arg as $t)
  21. {
  22. $type .= ' or '. SieveToken::typeString($t);
  23. }
  24. }
  25. else
  26. {
  27. $type = SieveToken::typeString($arg);
  28. }
  29. $tokenType = SieveToken::typeString($token->type);
  30. $message = "$tokenType where $type expected near ". $token->text;
  31. }
  32. parent::__construct('line '. $token->line .": $message");
  33. }
  34. public function getLineNo()
  35. {
  36. return $this->token_->line;
  37. }
  38. }