|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/hubspot/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/hubspot/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\hubspot\criteria\traits; |
|
10
|
|
|
|
|
11
|
|
|
use flipbox\hubspot\helpers\TransformerHelper; |
|
12
|
|
|
use flipbox\hubspot\transformers\collections\DynamicTransformerCollection; |
|
13
|
|
|
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author Flipbox Factory <[email protected]> |
|
17
|
|
|
* @since 1.0.0 |
|
18
|
|
|
*/ |
|
19
|
|
|
trait TransformerCollectionTrait |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var TransformerCollectionInterface|null |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $transformer = ['class' => DynamicTransformerCollection::class]; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param $value |
|
28
|
|
|
* @return $this |
|
29
|
|
|
*/ |
|
30
|
|
|
public function transformer($value) |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->setTransformer($value); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param $value |
|
37
|
|
|
* @return $this |
|
38
|
|
|
*/ |
|
39
|
|
|
public function setTransformer($value) |
|
40
|
|
|
{ |
|
41
|
|
|
if (empty($value)) { |
|
42
|
|
|
$this->transformer = null; |
|
43
|
|
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (is_string($value)) { |
|
47
|
|
|
if (TransformerHelper::isTransformerCollectionClass($value)) { |
|
48
|
|
|
$value = ['class' => $value]; |
|
49
|
|
|
} else { |
|
50
|
|
|
$value = ['handle' => [$value]]; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (array_key_exists('class', $value)) { |
|
55
|
|
|
$this->transformer = $value; |
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
TransformerHelper::populateTransformerCollection( |
|
60
|
|
|
$this->getTransformer(), |
|
|
|
|
|
|
61
|
|
|
$value |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return TransformerCollectionInterface|null |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getTransformer() |
|
71
|
|
|
{ |
|
72
|
|
|
if ($this->transformer === false) { |
|
73
|
|
|
return null; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if ($this->transformer instanceof TransformerCollectionInterface) { |
|
77
|
|
|
return $this->transformer; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
// Prevent subsequent resolves (since it already didn't) |
|
81
|
|
|
if (null === ($this->transformer = TransformerHelper::resolveCollection($this->transformer))) { |
|
|
|
|
|
|
82
|
|
|
$this->transformer = false; |
|
|
|
|
|
|
83
|
|
|
return null; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $this->transformer; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.