1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Incoming |
4
|
|
|
* |
5
|
|
|
* @author Trevor Suarez (Rican7) |
6
|
|
|
* @copyright (c) Trevor Suarez |
7
|
|
|
* @link https://github.com/Rican7/incoming |
8
|
|
|
* @license MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace Incoming\Hydrator; |
14
|
|
|
|
15
|
|
|
use Incoming\Structure\Map; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* An abstract, context enabled extension of the `AbstractDelegateBuilderHydrator`. |
19
|
|
|
* |
20
|
|
|
* @see AbstractDelegateBuilderHydrator |
21
|
|
|
* @see AbstractDelegateContextualBuilder |
22
|
|
|
* @see AbstractDelegateContextualHydrator |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractDelegateContextualBuilderHydrator extends AbstractDelegateBuilderHydrator implements |
25
|
|
|
ContextualBuilder, |
26
|
|
|
ContextualHydrator |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
* |
32
|
|
|
* @param mixed $incoming The input data. |
33
|
|
|
* @param Map|null $context An optional generic key-value map, for providing |
34
|
|
|
* contextual values during the build process. |
35
|
|
|
* @return mixed The built model. |
36
|
|
|
*/ |
37
|
3 |
|
public function build($incoming, Map $context = null) |
38
|
|
|
{ |
39
|
3 |
|
$callable = $this->getDelegateBuilder(); |
40
|
|
|
|
41
|
3 |
|
return $callable($incoming, $context); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
* |
47
|
|
|
* @param mixed $incoming The input data. |
48
|
|
|
* @param mixed $model The model to hydrate. |
49
|
|
|
* @param Map|null $context An optional generic key-value map, for providing |
50
|
|
|
* contextual values during the hydrate process. |
51
|
|
|
* @return mixed The hydrated model. |
52
|
|
|
*/ |
53
|
3 |
|
public function hydrate($incoming, $model, Map $context = null) |
54
|
|
|
{ |
55
|
3 |
|
$callable = $this->getDelegateHydrator(); |
56
|
|
|
|
57
|
3 |
|
return $callable($incoming, $model, $context); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|