sfActions.class.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 19911 2009-07-06 07:52:48Z FabianLange $
  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 ($actionToRun === 'execute')
  40. {
  41. // no action given
  42. throw new sfInitializationException(sprintf('sfAction initialization failed for module "%s". There was no action given.', $this->getModuleName()));
  43. }
  44. if (!is_callable(array($this, $actionToRun)))
  45. {
  46. // action not found
  47. throw new sfInitializationException(sprintf('sfAction initialization failed for module "%s", action "%s". You must create a "%s" method.', $this->getModuleName(), $this->getActionName(), $actionToRun));
  48. }
  49. if (sfConfig::get('sf_logging_enabled'))
  50. {
  51. $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Call "%s->%s()"', get_class($this), $actionToRun))));
  52. }
  53. // run action
  54. return $this->$actionToRun($request);
  55. }
  56. }