LibXMLException.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\Xml;
  4. use LibXMLError;
  5. /**
  6. * This exception is thrown when the Reader runs into a parsing error.
  7. *
  8. * This exception effectively wraps 1 or more LibXMLError objects.
  9. *
  10. * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
  11. * @author Evert Pot (http://evertpot.com/)
  12. * @license http://sabre.io/license/ Modified BSD License
  13. */
  14. class LibXMLException extends ParseException
  15. {
  16. /**
  17. * The error list.
  18. *
  19. * @var \LibXMLError[]
  20. */
  21. protected $errors;
  22. /**
  23. * Creates the exception.
  24. *
  25. * You should pass a list of LibXMLError objects in its constructor.
  26. *
  27. * @param \LibXMLError[] $errors
  28. */
  29. public function __construct(array $errors, int $code = 0, ?\Throwable $previousException = null)
  30. {
  31. $this->errors = $errors;
  32. parent::__construct($errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column, $code, $previousException);
  33. }
  34. /**
  35. * Returns the LibXML errors.
  36. */
  37. public function getErrors(): array
  38. {
  39. return $this->errors;
  40. }
  41. }