@@ 21-59 (lines=39) @@ | ||
18 | /** |
|
19 | * Class CallbackInterceptor |
|
20 | */ |
|
21 | class CallbackInterceptor implements InterceptorInterface |
|
22 | { |
|
23 | /** |
|
24 | * @var DeferredCollection |
|
25 | */ |
|
26 | private $storage; |
|
27 | ||
28 | /** |
|
29 | * DeferredInterceptor constructor. |
|
30 | * @param DeferredCollection $storage |
|
31 | */ |
|
32 | public function __construct(DeferredCollection $storage) |
|
33 | { |
|
34 | $this->storage = $storage; |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * @param RuleInterface $value |
|
39 | * @return bool |
|
40 | */ |
|
41 | public function match($value): bool |
|
42 | { |
|
43 | return $value instanceof \Closure; |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * @param ContextInterface $context |
|
48 | * @param mixed $value |
|
49 | * @return array |
|
50 | */ |
|
51 | public function resolve(ContextInterface $context, $value): array |
|
52 | { |
|
53 | $deferred = new Deferred($value); |
|
54 | ||
55 | $this->storage->add($deferred); |
|
56 | ||
57 | return [$context, $deferred]; |
|
58 | } |
|
59 | } |
|
60 |
@@ 20-56 (lines=37) @@ | ||
17 | /** |
|
18 | * Class DeferredInterceptor |
|
19 | */ |
|
20 | class DeferredInterceptor implements InterceptorInterface |
|
21 | { |
|
22 | /** |
|
23 | * @var DeferredCollection |
|
24 | */ |
|
25 | private $storage; |
|
26 | ||
27 | /** |
|
28 | * DeferredInterceptor constructor. |
|
29 | * @param DeferredCollection $storage |
|
30 | */ |
|
31 | public function __construct(DeferredCollection $storage) |
|
32 | { |
|
33 | $this->storage = $storage; |
|
34 | } |
|
35 | ||
36 | /** |
|
37 | * @param RuleInterface $value |
|
38 | * @return bool |
|
39 | */ |
|
40 | public function match($value): bool |
|
41 | { |
|
42 | return $value instanceof DeferredInterface; |
|
43 | } |
|
44 | ||
45 | /** |
|
46 | * @param ContextInterface $context |
|
47 | * @param mixed $value |
|
48 | * @return array |
|
49 | */ |
|
50 | public function resolve(ContextInterface $context, $value): array |
|
51 | { |
|
52 | $this->storage->add($value); |
|
53 | ||
54 | return [$context, $value]; |
|
55 | } |
|
56 | } |
|
57 |