GetSpecifyAdsCfgEvent.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace common\events\mall;
  3. use Exception;
  4. use common\enums\EventNameEnum;
  5. use common\components\BaseEvent;
  6. use common\services\mall\BaseAdsSettingService;
  7. use Yii;
  8. /**
  9. * 获取指定插件配置事件
  10. * @package common\events\mall
  11. */
  12. final class GetSpecifyAdsCfgEvent extends BaseEvent
  13. {
  14. /**
  15. * 触发事件名称(不可修改)
  16. *
  17. * @var string
  18. */
  19. public $name = EventNameEnum::GET_SPECIFY_ADDONS_CONFIG;
  20. /**
  21. * 配置文件
  22. *
  23. * @var array
  24. */
  25. protected $config = [];
  26. /**
  27. * @var int
  28. */
  29. public $mall_id;
  30. /**
  31. * @var array
  32. */
  33. public $listeners = [];
  34. public function __construct(int $mall_id)
  35. {
  36. $this->mall_id = $mall_id;
  37. }
  38. /**
  39. * @param BaseAdsSettingService $service
  40. * @return void
  41. */
  42. public function setService(BaseAdsSettingService $service)
  43. {
  44. $name = preg_replace_callback('/[A-Z][a-z]*/', function ($match) {
  45. return '_' . strtolower($match[0]);
  46. }, lcfirst($service->getAddosName()));
  47. $this->setConfig($name, $service->getSetting());
  48. }
  49. /**
  50. * @param string $addons_name
  51. * @param array $config
  52. * @return void
  53. */
  54. public function setConfig(string $addons_name, array $config = [])
  55. {
  56. $this->config = array_merge($this->config, $config);
  57. }
  58. /**
  59. * @return array
  60. */
  61. public function getConfig() : array
  62. {
  63. return $this->config;
  64. }
  65. }