Widget.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 03/03/2017
  6. * Time: 10:32
  7. */
  8. namespace app\common\components;
  9. use app\common\traits\TemplateTrait;
  10. abstract class Widget
  11. {
  12. use TemplateTrait;
  13. /**
  14. * @todo widget init event
  15. * @event Event an event that is triggered when the widget is initialized via [[init()]].
  16. */
  17. const EVENT_INIT = 'init';
  18. /**
  19. * @todo widget beforeRun event
  20. * @event WidgetEvent an event raised right before executing a widget.
  21. * You may set [[WidgetEvent::isValid]] to be false to cancel the widget execution.
  22. */
  23. const EVENT_BEFORE_RUN = 'beforeRun';
  24. /**
  25. * @todo widget afterRun event
  26. * @event WidgetEvent an event raised right after executing a widget.
  27. */
  28. const EVENT_AFTER_RUN = 'afterRun';
  29. /**
  30. * Constructor.
  31. *
  32. * @param array $config
  33. */
  34. public function __construct(array $config = [])
  35. {
  36. if (!empty($config)) {
  37. \YunShop::configure($this, $config);
  38. }
  39. $this->init();
  40. }
  41. public function init()
  42. {
  43. }
  44. abstract public function run();
  45. }