sfActions.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. * (c) 2004-2006 Sean Kerr <sean@code-box.org>
  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. * sfActions executes all the logic for the current request.
  12. *
  13. * @package symfony
  14. * @subpackage action
  15. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  16. * @author Sean Kerr <sean@code-box.org>
  17. * @version SVN: $Id: sfActions.class.php 9044 2008-05-19 06:18:41Z Carl.Vondrick $
  18. */
  19. abstract class sfActions extends sfAction
  20. {
  21. /**
  22. * Dispatches to the action defined by the 'action' parameter of the sfRequest object.
  23. *
  24. * This method try to execute the executeXXX() method of the current object where XXX is the
  25. * defined action name.
  26. *
  27. * @param sfRequest $request The current sfRequest object
  28. *
  29. * @return string A string containing the view name associated with this action
  30. *
  31. * @throws sfInitializationException
  32. *
  33. * @see sfAction
  34. */
  35. public function execute($request)
  36. {
  37. // dispatch action
  38. $actionToRun = 'execute'.ucfirst($this->getActionName());
  39. if (!is_callable(array($this, $actionToRun)))
  40. {
  41. // action not found
  42. throw new sfInitializationException(sprintf('sfAction initialization failed for module "%s", action "%s". You must create a "%s" method.', $this->getModuleName(), $this->getActionName(), $actionToRun));
  43. }
  44. if (sfConfig::get('sf_logging_enabled'))
  45. {
  46. $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Call "%s->%s()"', get_class($this), $actionToRun))));
  47. }
  48. // run action
  49. return $this->$actionToRun($request);
  50. }
  51. }