Event.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fecshop\services;
  10. use Yii;
  11. //use yii\base\Component;
  12. //use fecshop\services\event\FecshopEvent;
  13. /**
  14. * @author Terry Zhao <2358269014@qq.com>
  15. * @since 1.0
  16. */
  17. class Event extends Service
  18. {
  19. public $eventList; //Array
  20. /**
  21. * @param $eventName | String , 时间的名字
  22. * @param $data | Array , 数据数组,将各个数据以数组的方式传递过来。
  23. * 从配置中找到相应的event,然后执行event。
  24. * event 相当于插代码的感觉。
  25. */
  26. public function trigger($eventName, $data)
  27. {
  28. if (!is_array($data)) {
  29. //Yii::$service->helper->errors->add('event data must array');
  30. return;
  31. }
  32. if (isset($this->eventList[$eventName]) && !empty($this->eventList[$eventName]) && is_array($this->eventList[$eventName])) {
  33. foreach ($this->eventList[$eventName] as $one) {
  34. if (is_array($one) && !empty($one)) {
  35. list($class, $method) = $one;
  36. if ($class && $method) {
  37. $class::$method($data);
  38. }
  39. }
  40. }
  41. }
  42. }
  43. }