CallbackPromiseAdapter.php 936 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace React\Promise\PromiseAdapter;
  3. use React\Promise\PromiseInterface;
  4. /**
  5. * @template T
  6. * @template-implements PromiseAdapterInterface<T>
  7. */
  8. class CallbackPromiseAdapter implements PromiseAdapterInterface
  9. {
  10. /** @var callable[] */
  11. private $callbacks;
  12. /**
  13. * @param callable[] $callbacks
  14. */
  15. public function __construct(array $callbacks)
  16. {
  17. $this->callbacks = $callbacks;
  18. }
  19. /**
  20. * @return PromiseInterface<T>
  21. */
  22. public function promise(): PromiseInterface
  23. {
  24. return ($this->callbacks['promise'])(...func_get_args());
  25. }
  26. public function resolve($value): void
  27. {
  28. ($this->callbacks['resolve'])(...func_get_args());
  29. }
  30. public function reject(): void
  31. {
  32. ($this->callbacks['reject'])(...func_get_args());
  33. }
  34. public function settle(): void
  35. {
  36. ($this->callbacks['settle'])(...func_get_args());
  37. }
  38. }