Source for file Crafty_Exceptions.class.php

Documentation is available at Crafty_Exceptions.class.php

  1. <?php
  2.  
  3. /**
  4. * Implementation file of the Crafty_Exception classes.
  5. *
  6. * <pre>
  7. * PROJECT : Crafty
  8. * Template Engine.
  9. * AUTHOR : Crafty Team <crafty@zulan.net>
  10. * COPYRIGHT : (c) Thomas Ilsche, 2004
  11. *
  12. * FILE : [ROOT]\Crafty_Exceptions.php
  13. * DESCRIPTION: Implementation file of the Crafty main class.
  14. * </pre>
  15. *
  16. * This library is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU Lesser General Public
  18. * License as published by the Free Software Foundation; either
  19. * version 2.1 of the License, or (at your option) any later version.
  20. *
  21. * This library is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. * Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public
  27. * License along with this library; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. *
  30. * @package Crafty_Compiler
  31. * @author Crafty Team <crafty@zulan.net>
  32. * @copyright Copyright (c) Thomas Ilsche 2004
  33. * @version 1.0.4.2005.02.15
  34. * @link http://crafty.zulan.net
  35. * @license http://www.gnu.org/licenses/lgpl.html
  36. * GNU Lesser General Public License Version 2.1
  37. ***/
  38.  
  39. /**
  40. * Crafty_Exception class implementation
  41. *
  42. * The compiler will throw this on really bad errors.
  43. * Crafty itsself will handle these exceptions.
  44. *
  45. * @package Crafty_Compiler
  46. * @author Crafty Team <crafty@zulan.net>
  47. * @copyright Copyright (c) Thomas Ilsche
  48. * @version 1.0.4.2005.02.15
  49. * @link http://crafty.zulan.net
  50. * @license http://www.gnu.org/licenses/lgpl.html
  51. * GNU Lesser General Public License Version 2.1
  52. ***/
  53. class Crafty_Exception extends Exception
  54. {
  55. public $file;
  56. public $line;
  57. protected $type = 'Crafty Exception';
  58.  
  59. public function __construct($message, $file = '', $line = -1)
  60. {
  61. parent::__construct($message);
  62. $this->file = $file;
  63. $this->line = $line;
  64. }
  65.  
  66. /**
  67. * Returns a formatted error message.
  68. *
  69. * Possible values for $type:<br/>
  70. * <ul><li>'TXT'</li>
  71. * <li>'HTML'</li>
  72. * <li>'HTML_FULL'</li></ul>
  73. *
  74. * @param string $type [optional, default='TXT'] Message format type
  75. * @return string The formatted error message
  76. ***/
  77. public function getFormattedMessage($type = 'TXT')
  78. {
  79. switch(strtoupper($type)) {
  80. case 'TXT' :
  81. return $this->getParsedMessage();
  82. case 'HTML' :
  83. return htmlspecialchars($this->getParsedMessage());
  84. case 'HTML_FULL' :
  85. $r = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
  86. . '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
  87. . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"'
  88. . ' lang="en">'
  89. . "<head><title>$this->type</title>"
  90. . "<body><b>$this->type:</b> "
  91. . htmlspecialchars($this->getParsedMessage());
  92. if (!empty($this->file)) {
  93. $r .= " in <b>$this->file</b>";
  94. if ($this->line > -1) {
  95. $r .= " on line <b>$this->line</b>";
  96. }
  97. }
  98. $r .= '</body></html>';
  99. return $r;
  100. /* I'm not a designer so don't blame me if it doesn't look nice. */
  101. }
  102. }
  103.  
  104. public function getParsedMessage()
  105. {
  106. $msg = $this->getMessage();
  107. return preg_replace('/\s+/', ' ', $msg);
  108. }
  109. }
  110.  
  111. /**
  112. * Crafty_Exception_Core class implementation
  113. *
  114. * This exception will be thrown on errors in the parsed template.
  115. * Crafty_Core will handle these exceptions.
  116. *
  117. * @package Crafty_Compiler
  118. * @author Crafty Team <crafty@zulan.net>
  119. * @copyright Copyright (c) Thomas Ilsche
  120. * @version 1.0.0.2004.09.15
  121. * @link http://crafty.zulan.net
  122. * @license http://www.gnu.org/licenses/lgpl.html
  123. * GNU Lesser General Public License Version 2.1
  124. ***/
  125. class Crafty_Exception_Core extends Crafty_Exception
  126. {
  127. protected $type = 'Crafty_Core Exception';
  128. }
  129. ?>

Documentation generated on Sat, 19 Feb 2005 01:43:48 +0100 by phpDocumentor 1.3.0RC3