Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
namespace React\Promise;
4
 
5
/**
6
 * @deprecated 2.8.0 External usage of FulfilledPromise is deprecated, use `resolve()` instead.
7
 */
8
class FulfilledPromise implements ExtendedPromiseInterface, CancellablePromiseInterface
9
{
10
    private $value;
11
 
12
    public function __construct($value = null)
13
    {
14
        if ($value instanceof PromiseInterface) {
15
            throw new \InvalidArgumentException('You cannot create React\Promise\FulfilledPromise with a promise. Use React\Promise\resolve($promiseOrValue) instead.');
16
        }
17
 
18
        $this->value = $value;
19
    }
20
 
21
    public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
22
    {
23
        if (null === $onFulfilled) {
24
            return $this;
25
        }
26
 
27
        try {
28
            return resolve($onFulfilled($this->value));
29
        } catch (\Throwable $exception) {
30
            return new RejectedPromise($exception);
31
        } catch (\Exception $exception) {
32
            return new RejectedPromise($exception);
33
        }
34
    }
35
 
36
    public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
37
    {
38
        if (null === $onFulfilled) {
39
            return;
40
        }
41
 
42
        $result = $onFulfilled($this->value);
43
 
44
        if ($result instanceof ExtendedPromiseInterface) {
45
            $result->done();
46
        }
47
    }
48
 
49
    public function otherwise(callable $onRejected)
50
    {
51
        return $this;
52
    }
53
 
54
    public function always(callable $onFulfilledOrRejected)
55
    {
56
        return $this->then(function ($value) use ($onFulfilledOrRejected) {
57
            return resolve($onFulfilledOrRejected())->then(function () use ($value) {
58
                return $value;
59
            });
60
        });
61
    }
62
 
63
    public function progress(callable $onProgress)
64
    {
65
        return $this;
66
    }
67
 
68
    public function cancel()
69
    {
70
    }
71
}