Broker.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ f04vcN3k+F0v125Z/hSDEpJ6TqKt5ZBBOTaIsNJtnV0=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2015 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.4
  11. */
  12. /**
  13. * controller action helper broker
  14. */
  15. namespace Cube\Controller\Action\Helper;
  16. use Cube\Controller\Action\AbstractAction;
  17. class Broker
  18. {
  19. /**
  20. *
  21. * action object
  22. *
  23. * @var \Cube\Controller\Action\AbstractAction
  24. */
  25. protected $_action;
  26. /**
  27. *
  28. * class constructor
  29. *
  30. * @param \Cube\Controller\Action\AbstractAction $action
  31. */
  32. public function __construct(AbstractAction $action)
  33. {
  34. $this->_action = $action;
  35. }
  36. /**
  37. * get action helper by name
  38. *
  39. * @param string $name
  40. *
  41. * @throws \InvalidArgumentException
  42. * @return \Cube\Controller\Action\Helper\AbstractHelper
  43. */
  44. public function getHelper($name)
  45. {
  46. $className = '\\' . __NAMESPACE__ . '\\' . ucfirst($name);
  47. if (class_exists($className)) {
  48. /** @var \Cube\Controller\Action\Helper\AbstractHelper $helper */
  49. $helper = new $className();
  50. $helper->setAction($this->_action);
  51. }
  52. else {
  53. throw new \InvalidArgumentException(
  54. sprintf("The action helper '%s' does not exist.", $className));
  55. }
  56. return $helper;
  57. }
  58. /**
  59. * @param string $name
  60. * @param mixed $arguments
  61. *
  62. * @return \Cube\Controller\Action\Helper\AbstractHelper
  63. */
  64. public function __call($name, $arguments)
  65. {
  66. return $this->getHelper($name);
  67. }
  68. }