GoodsWidget.php 674 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/18
  6. * Time: 下午5:56
  7. */
  8. namespace app\common\events;
  9. class GoodsWidget extends Event
  10. {
  11. protected $widgets;
  12. /**
  13. * Create a new event instance.
  14. *
  15. * @return void
  16. */
  17. public function __construct(array &$widgets)
  18. {
  19. // pass array by reference
  20. $this->widgets = &$widgets;
  21. }
  22. public function addWidget($widget)
  23. {
  24. if ($widget) {
  25. if (!is_string($widget)) {
  26. throw new \Exception("Can not add non-string widget", 1);
  27. }
  28. $this->widgets[] = $widget;
  29. }
  30. }
  31. }