1 | <?php |
||
10 | class Form |
||
11 | { |
||
12 | /** |
||
13 | * @var Mautic |
||
14 | */ |
||
15 | protected $mautic; |
||
16 | |||
17 | /** |
||
18 | * Form ID |
||
19 | * |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $id; |
||
23 | |||
24 | /** |
||
25 | * Constructor |
||
26 | * |
||
27 | * @param Mautic $mautic |
||
28 | * @param int $id |
||
29 | */ |
||
30 | 10 | public function __construct(Mautic $mautic, $id) |
|
35 | |||
36 | /** |
||
37 | * Submit the $data array to the Mautic form |
||
38 | * Returns array containing info about the request, response and cookie |
||
39 | * |
||
40 | * @param array $data |
||
41 | * |
||
42 | * @return array |
||
43 | */ |
||
44 | public function submit(array $data) |
||
81 | |||
82 | /** |
||
83 | * Prepares data for CURL request based on provided form data, $_COOKIE and $_SERVER |
||
84 | * |
||
85 | * @param array $data |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | 2 | public function prepareRequest(array $data) |
|
124 | |||
125 | /** |
||
126 | * Builds the form URL |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | 4 | public function getUrl() |
|
134 | |||
135 | /** |
||
136 | * Returns the Form ID |
||
137 | * |
||
138 | * @return int |
||
139 | */ |
||
140 | 6 | public function getId() |
|
144 | } |
||
145 |
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: