BxDolService.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @package Dolphin Core
  4. * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * @license CC-BY - http://creativecommons.org/licenses/by/3.0/
  6. */
  7. defined('BX_DOL') or die('hack attempt');
  8. bx_import('BxDolRequest');
  9. /**
  10. * Service calls to modules' methods.
  11. *
  12. * The class has one static method is needed to make service calls
  13. * to module's methods from the Dolphin's core or the other modules.
  14. *
  15. *
  16. * Example of usage:
  17. * @code
  18. * BxDolService::call('payment', 'get_add_to_cart_link', array($iVendorId, $mixedModuleId, $iItemId, $iItemCount));
  19. * @endcode
  20. *
  21. *
  22. * Memberships/ACL:
  23. * Doesn't depend on user's membership.
  24. *
  25. *
  26. * Alerts:
  27. * no alerts available
  28. *
  29. */
  30. class BxDolService extends BxDol
  31. {
  32. function BxDolService ()
  33. {
  34. parent::BxDol();
  35. }
  36. public static function call($mixed, $sMethod, $aParams = array(), $sClass = 'Module')
  37. {
  38. bx_import('BxDolModuleQuery');
  39. $oDb = BxDolModuleQuery::getInstance();
  40. $aModule = array();
  41. if(is_string($mixed))
  42. $aModule = $oDb->getModuleByName($mixed);
  43. else
  44. $aModule = $oDb->getModuleById($mixed);
  45. return empty($aModule) ? '' : BxDolRequest::processAsService($aModule, $sMethod, $aParams, $sClass);
  46. }
  47. public static function callSerialized($s, $aMarkers = array(), $sReplaceIn = 'params')
  48. {
  49. $a = @unserialize($s);
  50. if (false === $a || !is_array($a))
  51. return '';
  52. if (isset($a[$sReplaceIn]))
  53. $a[$sReplaceIn] = bx_replace_markers($a[$sReplaceIn], $aMarkers);
  54. return self::call($a['module'], $a['method'], isset($a['params']) ? $a['params'] : array(), isset($a['class']) ? $a['class'] : 'Module');
  55. }
  56. public static function isSerializedService($s)
  57. {
  58. return preg_match('/^a:[\d+]:\{/', $s);
  59. }
  60. }