1 | <?php |
||
10 | class Contact |
||
11 | { |
||
12 | /** |
||
13 | * Mautic contact IP address |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $ip; |
||
18 | |||
19 | /** |
||
20 | * Mautic Cookie |
||
21 | * |
||
22 | * @var Cookie |
||
23 | */ |
||
24 | protected $cookie; |
||
25 | |||
26 | /** |
||
27 | * Constructor |
||
28 | * |
||
29 | * @param Cookie $cookie |
||
30 | */ |
||
31 | 38 | public function __construct(Cookie $cookie) |
|
36 | |||
37 | /** |
||
38 | * Returns Contact ID |
||
39 | * |
||
40 | * @return int |
||
41 | */ |
||
42 | 16 | public function getId() |
|
46 | |||
47 | /** |
||
48 | * Set Mautic Contact ID to global cookie |
||
49 | * |
||
50 | * @param int $contactId |
||
51 | * |
||
52 | * @return Contact |
||
53 | */ |
||
54 | 6 | public function setId($contactId) |
|
60 | |||
61 | /** |
||
62 | * Returns Contact IP address |
||
63 | * |
||
64 | * @return string|null |
||
65 | */ |
||
66 | 12 | public function getIp() |
|
70 | |||
71 | /** |
||
72 | * Sert Contact IP address |
||
73 | * |
||
74 | * @param string $ip |
||
75 | * |
||
76 | * @return Contact |
||
77 | */ |
||
78 | 4 | public function setIp($ip) |
|
82 | |||
83 | /** |
||
84 | * Returns Mautic Contact Session ID |
||
85 | * |
||
86 | * @return string|null |
||
87 | */ |
||
88 | 4 | public function getSessionId() |
|
92 | |||
93 | /** |
||
94 | * Set Mautic session ID to global cookie |
||
95 | * |
||
96 | * @param string $sessionId |
||
97 | * |
||
98 | * @return Contact |
||
99 | */ |
||
100 | 2 | public function setSessionId($sessionId) |
|
106 | |||
107 | /** |
||
108 | * Set Mautic device ID to global cookie |
||
109 | * |
||
110 | * @param string $deviceId |
||
111 | * |
||
112 | 38 | * @return Contact |
|
113 | */ |
||
114 | 38 | public function setDeviceId($deviceId) |
|
120 | |||
121 | /** |
||
122 | * Guesses IP address from $_SERVER |
||
123 | * |
||
124 | * @return string |
||
125 | 38 | */ |
|
126 | 38 | public function getIpFromServer() |
|
156 | } |
||
157 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: