|
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\connections\IntegrationConnectionInterface; |
|
12
|
|
|
use flipbox\hubspot\HubSpot; |
|
13
|
|
|
use flipbox\hubspot\services\Connections; |
|
14
|
|
|
use yii\base\InvalidConfigException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Flipbox Factory <[email protected]> |
|
18
|
|
|
* @since 1.0.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
trait IntegrationConnectionTrait |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var IntegrationConnectionInterface|string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $connection = Connections::DEFAULT_INTEGRATION_CONNECTION; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param $value |
|
29
|
|
|
* @return $this |
|
30
|
|
|
*/ |
|
31
|
|
|
public function connection($value) |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->setConnection($value); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param $value |
|
38
|
|
|
* @return $this |
|
39
|
|
|
*/ |
|
40
|
|
|
public function setConnection($value) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->connection = $value; |
|
43
|
|
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return IntegrationConnectionInterface |
|
48
|
|
|
* @throws InvalidConfigException |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getConnection(): IntegrationConnectionInterface |
|
51
|
|
|
{ |
|
52
|
|
|
if ($this->connection instanceof IntegrationConnectionInterface) { |
|
53
|
|
|
return $this->connection; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if ($this->connection === null) { |
|
57
|
|
|
$this->connection = Connections::DEFAULT_INTEGRATION_CONNECTION; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$this->connection = HubSpot::getInstance()->getConnections()->get($this->connection); |
|
61
|
|
|
|
|
62
|
|
|
if (!$this->connection instanceof IntegrationConnectionInterface) { |
|
63
|
|
|
throw new InvalidConfigException(sprintf( |
|
64
|
|
|
"Integration Connection must be an instance of '%s', '%s' given.", |
|
65
|
|
|
IntegrationConnectionInterface::class, |
|
66
|
|
|
get_class($this->connection) |
|
67
|
|
|
)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $this->connection; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|