sfError404Exception.class.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfError404Exception is thrown when a 404 error occurs in an action.
  11. *
  12. * @package symfony
  13. * @subpackage exception
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfError404Exception.class.php 11471 2008-09-12 10:03:49Z fabien $
  16. */
  17. class sfError404Exception extends sfException
  18. {
  19. /**
  20. * Forwards to the 404 action.
  21. */
  22. public function printStackTrace()
  23. {
  24. $exception = is_null($this->wrappedException) ? $this : $this->wrappedException;
  25. if (sfConfig::get('sf_debug') && !sfConfig::get('sf_test'))
  26. {
  27. $response = sfContext::getInstance()->getResponse();
  28. if (is_null($response))
  29. {
  30. $response = new sfWebResponse(sfContext::getInstance()->getEventDispatcher());
  31. sfContext::getInstance()->setResponse($response);
  32. }
  33. $response->setStatusCode(404);
  34. return parent::printStackTrace();
  35. }
  36. else
  37. {
  38. // log all exceptions in php log
  39. if (!sfConfig::get('sf_test'))
  40. {
  41. error_log($this->getMessage());
  42. }
  43. sfContext::getInstance()->getController()->forward(sfConfig::get('sf_error_404_module'), sfConfig::get('sf_error_404_action'));
  44. }
  45. }
  46. }