PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/kohana-twig/vendor/Twig-1.0/lib/Twig/Error.php

https://bitbucket.org/sapphiriq/assets-example
PHP | 122 lines | 56 code | 16 blank | 50 comment | 6 complexity | df71c330141d59436ba44c6cbccaa3c3 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2009 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Twig base exception.
  12. *
  13. * @package twig
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. */
  16. class Twig_Error extends Exception
  17. {
  18. protected $lineno;
  19. protected $filename;
  20. protected $rawMessage;
  21. protected $previous;
  22. /**
  23. * Constructor.
  24. *
  25. * @param string $message The error message
  26. * @param integer $lineno The template line where the error occurred
  27. * @param string $filename The template file name where the error occurred
  28. * @param Exception $previous The previous exception
  29. */
  30. public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null)
  31. {
  32. $this->lineno = $lineno;
  33. $this->filename = $filename;
  34. $this->rawMessage = $message;
  35. $this->updateRepr();
  36. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  37. $this->previous = $previous;
  38. parent::__construct($this->message);
  39. } else {
  40. parent::__construct($this->message, 0, $previous);
  41. }
  42. }
  43. /**
  44. * Gets the filename where the error occurred.
  45. *
  46. * @return string The filename
  47. */
  48. public function getTemplateFile()
  49. {
  50. return $this->filename;
  51. }
  52. /**
  53. * Sets the filename where the error occurred.
  54. *
  55. * @param string $filename The filename
  56. */
  57. public function setTemplateFile($filename)
  58. {
  59. $this->filename = $filename;
  60. $this->updateRepr();
  61. }
  62. /**
  63. * Gets the template line where the error occurred.
  64. *
  65. * @return integer The template line
  66. */
  67. public function getTemplateLine()
  68. {
  69. return $this->lineno;
  70. }
  71. /**
  72. * Sets the template line where the error occurred.
  73. *
  74. * @param integer $lineno The template line
  75. */
  76. public function setTemplateLine($lineno)
  77. {
  78. $this->lineno = $lineno;
  79. $this->updateRepr();
  80. }
  81. /**
  82. * For PHP < 5.3.0, provides access to the getPrevious() method.
  83. *
  84. * @param string $method The method name
  85. * @param array $arguments The parameters to be passed to the method
  86. *
  87. * @return Exception The previous exception or null
  88. */
  89. public function __call($method, $arguments)
  90. {
  91. if ('getprevious' == strtolower($method)) {
  92. return $this->previous;
  93. }
  94. throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method));
  95. }
  96. protected function updateRepr()
  97. {
  98. $this->message = $this->rawMessage;
  99. if (null !== $this->filename) {
  100. $this->message .= sprintf(' in %s', json_encode($this->filename));
  101. }
  102. if ($this->lineno >= 0) {
  103. $this->message .= sprintf(' at line %d', $this->lineno);
  104. }
  105. }
  106. }