Resolver::onResolve()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
/*
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Core\Async\Promise;
13
14
/**
15
 * Resolver class.
16
 *
17
 * @author Karel Osorio Ramírez <[email protected]>
18
 */
19
abstract class Resolver implements ResolverInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function resolve($value = null)
25
    {
26
        try {
27
            $this->onResolve($value);
28
        } catch (\Exception $e) {
29
            $this->onInnerFailure($e);
30
        }
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function notify($state = null)
37
    {
38
        try {
39
            $this->onNotify($state);
40
        } catch (\Exception $e) {
41
            $this->onInnerFailure($e);
42
        }
43
    }
44
45
    /**
46
     * @param mixed $value
47
     */
48
    abstract protected function onResolve($value = null);
49
50
    /**
51
     * @param mixed $state
52
     */
53
    abstract protected function onNotify($state = null);
54
55
    /**
56
     * @param \Exception $reason
57
     */
58
    protected function onInnerFailure(\Exception $reason)
59
    {
60
        $this->reject($reason);
61
    }
62
}
63