ExtendedPromiseInterface.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace React\Promise;
  3. interface ExtendedPromiseInterface extends PromiseInterface
  4. {
  5. /**
  6. * Consumes the promise's ultimate value if the promise fulfills, or handles the
  7. * ultimate error.
  8. *
  9. * It will cause a fatal error if either `$onFulfilled` or
  10. * `$onRejected` throw or return a rejected promise.
  11. *
  12. * Since the purpose of `done()` is consumption rather than transformation,
  13. * `done()` always returns `null`.
  14. *
  15. * @param callable|null $onFulfilled
  16. * @param callable|null $onRejected
  17. * @param callable|null $onProgress This argument is deprecated and should not be used anymore.
  18. * @return void
  19. */
  20. public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null);
  21. /**
  22. * Registers a rejection handler for promise. It is a shortcut for:
  23. *
  24. * ```php
  25. * $promise->then(null, $onRejected);
  26. * ```
  27. *
  28. * Additionally, you can type hint the `$reason` argument of `$onRejected` to catch
  29. * only specific errors.
  30. *
  31. * @param callable $onRejected
  32. * @return ExtendedPromiseInterface
  33. */
  34. public function otherwise(callable $onRejected);
  35. /**
  36. * Allows you to execute "cleanup" type tasks in a promise chain.
  37. *
  38. * It arranges for `$onFulfilledOrRejected` to be called, with no arguments,
  39. * when the promise is either fulfilled or rejected.
  40. *
  41. * * If `$promise` fulfills, and `$onFulfilledOrRejected` returns successfully,
  42. * `$newPromise` will fulfill with the same value as `$promise`.
  43. * * If `$promise` fulfills, and `$onFulfilledOrRejected` throws or returns a
  44. * rejected promise, `$newPromise` will reject with the thrown exception or
  45. * rejected promise's reason.
  46. * * If `$promise` rejects, and `$onFulfilledOrRejected` returns successfully,
  47. * `$newPromise` will reject with the same reason as `$promise`.
  48. * * If `$promise` rejects, and `$onFulfilledOrRejected` throws or returns a
  49. * rejected promise, `$newPromise` will reject with the thrown exception or
  50. * rejected promise's reason.
  51. *
  52. * `always()` behaves similarly to the synchronous finally statement. When combined
  53. * with `otherwise()`, `always()` allows you to write code that is similar to the familiar
  54. * synchronous catch/finally pair.
  55. *
  56. * Consider the following synchronous code:
  57. *
  58. * ```php
  59. * try {
  60. * return doSomething();
  61. * } catch(\Exception $e) {
  62. * return handleError($e);
  63. * } finally {
  64. * cleanup();
  65. * }
  66. * ```
  67. *
  68. * Similar asynchronous code (with `doSomething()` that returns a promise) can be
  69. * written:
  70. *
  71. * ```php
  72. * return doSomething()
  73. * ->otherwise('handleError')
  74. * ->always('cleanup');
  75. * ```
  76. *
  77. * @param callable $onFulfilledOrRejected
  78. * @return ExtendedPromiseInterface
  79. */
  80. public function always(callable $onFulfilledOrRejected);
  81. /**
  82. * Registers a handler for progress updates from promise. It is a shortcut for:
  83. *
  84. * ```php
  85. * $promise->then(null, null, $onProgress);
  86. * ```
  87. *
  88. * @param callable $onProgress
  89. * @return ExtendedPromiseInterface
  90. * @deprecated 2.6.0 Progress support is deprecated and should not be used anymore.
  91. */
  92. public function progress(callable $onProgress);
  93. }