The
resolve
function resolves a given class or interface name to an instance using the service container:<?php $api = resolve('HelpSpot\API');
<?php foreach ($promisesOrValues as $promiseOrValue) {
$cancellationQueue->enqueue($promiseOrValue);
resolve($promiseOrValue)
->done($resolve, $reject);
}
}, $cancellationQueue);
<?php function some(array $promisesOrValues, int $howMany): PromiseInterface
{
if ($howMany < 1) {
return resolve([]);
}
$len = \count($promisesOrValues);
<?php $cancellationQueue->enqueue($promiseOrValue);
resolve($promiseOrValue)
->done($fulfiller, $rejecter);
}
}, $cancellationQueue);
<?php function map(array $promisesOrValues, callable $mapFunc): PromiseInterface
{
if (!$promisesOrValues) {
return resolve([]);
}
$cancellationQueue = new Internal\CancellationQueue();
<?php $cancellationQueue->enqueue($promiseOrValue);
$values[$i] = null;
resolve($promiseOrValue)
->then($mapFunc)
->done(
function ($mapped) use ($i, &$values, &$toResolve, $resolve): void {
<?php return $current
->then(function ($c) use ($reduceFunc, $total, &$i, $val) {
return resolve($val)
->then(function ($value) use ($reduceFunc, $total, &$i, $c) {
return $reduceFunc($c, $value, $i++, $total);
});
<?php $cancellationQueue->enqueue($initialValue);
\array_reduce($promisesOrValues, $wrappedReduceFunc, resolve($initialValue))
->done($resolve, $reject);
}, $cancellationQueue);
}
<?php public function finally(callable $onFulfilledOrRejected): PromiseInterface
{
return $this->then(function ($value) use ($onFulfilledOrRejected): PromiseInterface {
return resolve($onFulfilledOrRejected())->then(function () use ($value) {
return $value;
});
});
<?php public function finally(callable $onFulfilledOrRejected): PromiseInterface
{
return $this->then(null, function (\Throwable $reason) use ($onFulfilledOrRejected): PromiseInterface {
return resolve($onFulfilledOrRejected())->then(function () use ($reason): PromiseInterface {
return new RejectedPromise($reason);
});
});
<?php public function finally(callable $onFulfilledOrRejected): PromiseInterface
{
return $this->then(static function ($value) use ($onFulfilledOrRejected) {
return resolve($onFulfilledOrRejected())->then(function () use ($value) {
return $value;
});
}, static function ($reason) use ($onFulfilledOrRejected) {
<?php return $value;
});
}, static function ($reason) use ($onFulfilledOrRejected) {
return resolve($onFulfilledOrRejected())->then(function () use ($reason) {
return new RejectedPromise($reason);
});
});
<?php $callback(
static function ($value = null) use (&$target) {
if ($target !== null) {
$target->settle(resolve($value));
$target = null;
}
},
<?php ->method('__invoke')
->with(self::identicalTo([1, 2, 3]));
all([resolve(1), resolve(2), resolve(3)])
->then($mock);
}
<?php ->method('__invoke')
->with(self::identicalTo($exception2));
all([resolve(1), reject($exception2), resolve($exception3)])
->then($this->expectCallableNever(), $mock);
}
<?php $deferred = new Deferred();
all([resolve(1), $deferred->promise(), resolve(3)])
->then($mock);
$deferred->resolve(2);