1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipboxfactory/craft-integration/blob/master/LICENSE |
6
|
|
|
* @link https://github.com/flipboxfactory/craft-integration/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\craft\integration\queries; |
10
|
|
|
|
11
|
|
|
use craft\db\QueryAbortedException; |
12
|
|
|
use craft\helpers\Db; |
13
|
|
|
use flipbox\craft\ember\queries\AuditAttributesTrait; |
14
|
|
|
use flipbox\craft\ember\queries\CacheableActiveQuery; |
15
|
|
|
use flipbox\craft\ember\queries\SiteAttributeTrait; |
16
|
|
|
use flipbox\craft\integration\records\IntegrationConnection; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Flipbox Factory <[email protected]> |
20
|
|
|
* @since 2.0.0 |
21
|
|
|
* |
22
|
|
|
* @method IntegrationConnection[] getCachedResult() |
23
|
|
|
* @method IntegrationConnection[] all() |
24
|
|
|
* @method IntegrationConnection one() |
25
|
|
|
*/ |
26
|
|
|
class IntegrationConnectionQuery extends CacheableActiveQuery |
27
|
|
|
{ |
28
|
|
|
use AuditAttributesTrait, |
29
|
|
|
SiteAttributeTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string|string[]|null |
33
|
|
|
*/ |
34
|
|
|
public $handle; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string|string[]|null |
38
|
|
|
*/ |
39
|
|
|
public $class; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param $value |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
|
|
public function handle($value) |
46
|
|
|
{ |
47
|
|
|
$this->handle = $value; |
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param $value |
53
|
|
|
* @return $this |
54
|
|
|
*/ |
55
|
|
|
public function setHandle($value) |
56
|
|
|
{ |
57
|
|
|
return $this->handle($value); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param $value |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
|
|
public function class($value) |
65
|
|
|
{ |
66
|
|
|
$this->class = $value; |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param $value |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function setClass($value) |
75
|
|
|
{ |
76
|
|
|
return $this->class($value); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @inheritdoc |
81
|
|
|
* @throws QueryAbortedException |
82
|
|
|
*/ |
83
|
|
|
public function prepare($builder) |
84
|
|
|
{ |
85
|
|
|
// Is the query already doomed? |
86
|
|
|
if (($this->handle !== null && empty($this->handle))) { |
87
|
|
|
throw new QueryAbortedException(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->applyAttributeConditions(); |
91
|
|
|
$this->applyAuditAttributeConditions(); |
92
|
|
|
|
93
|
|
|
return parent::prepare($builder); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Prepares simple attributes |
98
|
|
|
*/ |
99
|
|
|
protected function applyAttributeConditions() |
100
|
|
|
{ |
101
|
|
|
$attributes = [ |
102
|
|
|
'class', |
103
|
|
|
'handle' |
104
|
|
|
]; |
105
|
|
|
|
106
|
|
|
foreach ($attributes as $attribute) { |
107
|
|
|
if (null !== ($value = $this->{$attribute})) { |
108
|
|
|
$this->andWhere(Db::parseParam($attribute, $value)); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
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.