StateContainer.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/6/29
  6. * Time: 下午3:31
  7. */
  8. namespace app\common\modules\process;
  9. use app\common\modules\payType\remittance\models\state\RemittanceState;
  10. use app\common\modules\process\events\AfterProcessStateChangedEvent;
  11. use Illuminate\Container\Container;
  12. class StateContainer extends Container
  13. {
  14. /**
  15. * StatusContainer constructor.
  16. */
  17. public function __construct()
  18. {
  19. $this->setBinds();
  20. }
  21. public function handle(AfterProcessStateChangedEvent $event)
  22. {
  23. if ($this->bound($event->getProcess()->code)) {
  24. $this->make($event->getProcess()->code)->handle($event->getProcess());
  25. }
  26. }
  27. public function setBinds()
  28. {
  29. collect([
  30. [
  31. 'key' => 'remittance',
  32. 'class' => RemittanceState::class,
  33. ]
  34. ])->each(function ($item) {
  35. $this->bind($item['key'], function ($container) use ($item) {
  36. return new $item['class']();
  37. });
  38. });
  39. }
  40. }