BxDolModuleProxy.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Proxy class for module classes, now only module template class is proxied.
  11. * It's possible to override any module template method call by making a response
  12. * for 'module_template_method_call' alert.
  13. */
  14. class BxDolModuleProxy
  15. {
  16. private $_oProxifiedObject;
  17. private $_sObjectType;
  18. function __construct($sObjectType, $oProxifiedObject)
  19. {
  20. $this->_sObjectType = $sObjectType;
  21. $this->_oProxifiedObject = $oProxifiedObject;
  22. }
  23. public function __call($sMethodName, $aArguments)
  24. {
  25. if (is_callable(array($this->_oProxifiedObject, $sMethodName))) {
  26. // check if we need to include css&js files
  27. if ('module_template' == $this->_sObjectType && !empty($this->_oProxifiedObject->aMethodsToCallAddJsCss)) {
  28. foreach ($this->_oProxifiedObject->aMethodsToCallAddJsCss as $s) {
  29. if (0 === strpos($sMethodName, $s)) {
  30. $this->_oProxifiedObject->addCssJs();
  31. break;
  32. }
  33. }
  34. }
  35. $oModule = ('module_template' == $this->_sObjectType ? $this->_oProxifiedObject->getModule() : null);
  36. // make it possible to override the call or arguments
  37. $res = null;
  38. /**
  39. * @hooks
  40. * @hookdef hook-module_template_method_call-method_name 'module_template_method_call', '{method_name}' - hook to override a method from template class in a module
  41. * - $unit_name - equals `module_template_method_call`
  42. * - $action - method name
  43. * - $object_id - not used
  44. * - $sender_id - not used
  45. * - $extra_params - array of additional params with the following array keys:
  46. * - `module` - [object] an instance of a module, @see BxDolModule
  47. * - `args` - [array] by ref, array with method call arguments, can be overridden in hook processing
  48. * - `override_result` - [mixed] by ref, method call response, if equals to 'null', the default method will be called, can be overridden in hook processing
  49. * @hook @ref hook-module_template_method_call-method_name
  50. */
  51. bx_alert($this->_sObjectType . '_method_call', $sMethodName, 0, 0, [
  52. 'module' => $oModule,
  53. 'args' => &$aArguments,
  54. 'args_ref' => &$aArguments,
  55. 'override_result' => &$res
  56. ]);
  57. if (null !== $res)
  58. return $res;
  59. // call original method
  60. return call_user_func_array(array($this->_oProxifiedObject, $sMethodName), $aArguments);
  61. }
  62. else {
  63. $sClass = get_class($this->_oProxifiedObject);
  64. trigger_error('Method ' . $sMethodName . ' was not found for the class ' . $sClass, E_USER_ERROR);
  65. }
  66. }
  67. public function getClassName()
  68. {
  69. return get_class($this->_oProxifiedObject);
  70. }
  71. public function isMethodExists($s)
  72. {
  73. return method_exists($this->_oProxifiedObject, $s);
  74. }
  75. /**
  76. * Dirty fix for pass by reference to BxTimelineTemplate::getData
  77. */
  78. public function getData(&$aEvent, $aBrowseParams = array())
  79. {
  80. return $this->_oProxifiedObject->getData($aEvent, $aBrowseParams);
  81. }
  82. /**
  83. * Dirty fix for pass by reference to BxNtfsTemplate::getPost
  84. */
  85. public function getPost(&$aEvent, $aBrowseParams = array())
  86. {
  87. return $this->_oProxifiedObject->getPost($aEvent, $aBrowseParams);
  88. }
  89. /**
  90. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationEmail
  91. */
  92. public function getNotificationEmail($iRecipient, &$aEvent)
  93. {
  94. return $this->_oProxifiedObject->getNotificationEmail($iRecipient, $aEvent);
  95. }
  96. /**
  97. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationPush
  98. */
  99. public function getNotificationPush($iRecipient, &$aEvent)
  100. {
  101. return $this->_oProxifiedObject->getNotificationPush($iRecipient, $aEvent);
  102. }
  103. }
  104. /** @} */