1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Transform |
5
|
|
|
* @author Flipbox Factory |
6
|
|
|
* @copyright Copyright (c) 2017, Flipbox Digital |
7
|
|
|
* @link https://github.com/flipbox/transform/releases/latest |
8
|
|
|
* @license https://github.com/flipbox/transform/blob/master/LICENSE |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace flipbox\transform\transformers; |
12
|
|
|
|
13
|
|
|
use flipbox\transform\helpers\Object as ObjectHelper; |
14
|
|
|
use flipbox\transform\Scope; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @package flipbox\transform\transformers |
18
|
|
|
* @author Flipbox Factory <[email protected]> |
19
|
|
|
* @since 1.0.0 |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractTransformer implements TransformerInterface |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var Scope |
26
|
|
|
*/ |
27
|
|
|
protected $scope; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param array $config |
31
|
|
|
*/ |
32
|
|
|
public function __construct(array $config = []) |
33
|
|
|
{ |
34
|
|
|
ObjectHelper::configure($this, $config); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public function getIncludes(): array |
41
|
|
|
{ |
42
|
|
|
return []; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param null $key |
47
|
|
|
* @return \flipbox\transform\ParamBag|null |
48
|
|
|
*/ |
49
|
|
|
protected function getParams($key = null) |
50
|
|
|
{ |
51
|
|
|
return $this->scope->getParams($key); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param mixed $data |
56
|
|
|
* @param TransformerInterface|callable $transformer |
57
|
|
|
* |
58
|
|
|
* @return NestedItem |
59
|
|
|
*/ |
60
|
|
|
protected function item($data, $transformer): NestedItem |
61
|
|
|
{ |
62
|
|
|
return new NestedItem(['data' => $data, 'transformer' => $transformer]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param mixed $data |
67
|
|
|
* @param TransformerInterface|callable $transformer |
68
|
|
|
* |
69
|
|
|
* @return NestedCollection |
70
|
|
|
*/ |
71
|
|
|
protected function collection($data, $transformer): NestedCollection |
72
|
|
|
{ |
73
|
|
|
return new NestedCollection(['data' => $data, 'transformer' => $transformer]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
|
|
public function __invoke($data, Scope $scope, string $identifier = null): array |
80
|
|
|
{ |
81
|
|
|
$this->scope = $scope; |
82
|
|
|
return $this->transform($data, $identifier); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.