1. sfCallable.class.php
  2. /** * sfCallable represents a PHP callable. * * @package symfony * @subpackage util * @author Fabien Potencier * @version SVN: $Id: sfCallable.class.php 21875 2009-09-11 05:54:39Z fabien $ */
  3. class sfCallable
  4. {
  5. protected
  6. $callable = null;
  7. /**
  8. * Constructor.
  9. *
  10. * @param mixed $callable A valid PHP callable (must be valid when calling the call() method)
  11. */
  12. public function __construct($callable)
  13. {
  14. $this->callable = $callable;
  15. }
  16. /**
  17. * Returns the current callable.
  18. *
  19. * @return mixed The current callable
  20. */
  21. public function getCallable()
  22. {
  23. return $this->callable;
  24. }
  25. /**
  26. * Calls the current callable with the given arguments.
  27. *
  28. * The callable is called with the arguments given to this method.
  29. *
  30. * This method throws an exception if the callable is not valid.
  31. * This check is not done during the object construction to allow
  32. * you to load the callable as late as possible.
  33. */
  34. public function call()
  35. {
  36. if (!is_callable($this->callable))
  37. {
  38. throw new sfException(sprintf('"%s" is not a valid callable.', is_array($this->callable) ? sprintf('%s:%s', is_object($this->callable[0]) ? get_class($this->callable[0]) : $this->callable[0], $this->callable[1]) : (is_object($this->callable) ? sprintf('Object(%s)', get_class($this->callable)) : var_export($this->callable, true))));
  39. }
  40. $arguments = func_get_args();
  41. return call_user_func_array($this->callable, $arguments);
  42. }
  43. }

Debug toolbar