adoptedPromise; return new Promise($adoptedPromise->then($onFulfilled, $onRejected), $this); } /** * @inheritdoc */ public function create(callable $resolver) { $promise = new ReactPromise($resolver); return new Promise($promise, $this); } /** * @inheritdoc */ public function createFulfilled($value = null) { $promise = resolve($value); return new Promise($promise, $this); } /** * @inheritdoc */ public function createRejected($reason) { $promise = reject($reason); return new Promise($promise, $this); } /** * @inheritdoc */ public function all(array $promisesOrValues) { // TODO: rework with generators when PHP minimum required version is changed to 5.5+ $promisesOrValues = Utils::map( $promisesOrValues, static function ($item) { return $item instanceof Promise ? $item->adoptedPromise : $item; } ); $promise = all($promisesOrValues)->then(static function ($values) use ($promisesOrValues) : array { $orderedResults = []; foreach ($promisesOrValues as $key => $value) { $orderedResults[$key] = $values[$key]; } return $orderedResults; }); return new Promise($promise, $this); } }