File tree Expand file tree Collapse file tree 5 files changed +78
-4
lines changed
examples/simple-email-form Expand file tree Collapse file tree 5 files changed +78
-4
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,14 @@ require __DIR__.'/vendor/autoload.php';
2727// Define the namespace of the Mautic object
2828use Escopecz\MauticFormSubmit\Mautic;
2929
30+ // Define the namespace of the Mautic configuration object
31+ use Escopecz\MauticFormSubmit\Mautic\Config;
32+
33+ // It's optional to declare the configuration object to change some default values.
34+ // For example to disable Curl verbose logging.
35+ $config = new Config;
36+ $config->setCurlVerbose(true);
37+
3038// Instantiate the Mautic object with the base URL where the Mautic runs
3139$mautic = new Mautic('https://mymautic.com');
3240
Original file line number Diff line number Diff line change 44require __DIR__ .'/../../vendor/autoload.php ' ;
55
66use Escopecz \MauticFormSubmit \Mautic ;
7+ use Escopecz \MauticFormSubmit \Mautic \Config ;
78
89class Controller
910{
@@ -13,8 +14,14 @@ public function __construct()
1314 $ _SESSION [$ key ] = $ val ;
1415 }
1516
16- if (isset ($ _POST ['email_label ' ]) && isset ($ _POST [$ _POST ['email_label ' ]]) && isset ($ _POST ['mautic_base_url ' ]) && isset ($ _POST ['form_id ' ])) {
17- $ mautic = new Mautic ($ _POST ['mautic_base_url ' ]);
17+ if (isset ($ _POST ['email_label ' ]) && isset ($ _POST [$ _POST ['email_label ' ]]) && isset ($ _POST ['mautic_base_url ' ]) && isset ($ _POST ['form_id ' ])) {
18+
19+ // It's optional to create a Config DTO object and pass it to the Mautic object.
20+ // For example to set Curl verbose logging to true.
21+ $ config = new Config ;
22+ $ config ->setCurlVerbose (true );
23+
24+ $ mautic = new Mautic ($ _POST ['mautic_base_url ' ], $ config );
1825 $ form = $ mautic ->getForm ($ _POST ['form_id ' ]);
1926
2027 $ info = $ form ->submit (
Original file line number Diff line number Diff line change 55use Escopecz \MauticFormSubmit \Mautic \Form ;
66use Escopecz \MauticFormSubmit \Mautic \Contact ;
77use Escopecz \MauticFormSubmit \Mautic \Cookie as MauticCookie ;
8+ use Escopecz \MauticFormSubmit \Mautic \Config ;
89
910/**
1011 * Mautic representation
@@ -32,16 +33,24 @@ class Mautic
3233 */
3334 protected $ cookie ;
3435
36+ /**
37+ * Mautic Configuration
38+ *
39+ * @var Config
40+ */
41+ protected $ config ;
42+
3543 /**
3644 * Constructor
3745 *
3846 * @param string $baseUrl
3947 */
40- public function __construct ($ baseUrl )
48+ public function __construct ($ baseUrl, Config $ config = null )
4149 {
4250 $ this ->baseUrl = rtrim (trim ($ baseUrl ), '/ ' );
4351 $ this ->cookie = new MauticCookie ;
4452 $ this ->contact = new Contact ($ this ->cookie );
53+ $ this ->config = $ config ?: new Config ;
4554 }
4655
4756 /**
@@ -99,4 +108,14 @@ public function getCookie()
99108 {
100109 return $ this ->cookie ;
101110 }
111+
112+ /**
113+ * Returns Mautic Configuration representation object
114+ *
115+ * @return Config
116+ */
117+ public function getConfig ()
118+ {
119+ return $ this ->config ;
120+ }
102121}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Escopecz \MauticFormSubmit \Mautic ;
4+
5+ /**
6+ * Configuration object for Mautic form submission.
7+ */
8+ class Config
9+ {
10+ /**
11+ * Curl verbose logging option
12+ *
13+ * @var bool
14+ */
15+ protected $ curlVerbose = true ;
16+
17+ /**
18+ * Returns Curl verbose logging option
19+ *
20+ * @return bool
21+ */
22+ public function getCurlVerbose ()
23+ {
24+ return $ this ->curlVerbose ;
25+ }
26+
27+ /**
28+ * Set Curl verbose logging option
29+ *
30+ * @param bool $curlVerbose
31+ *
32+ * @return Config
33+ */
34+ public function setCurlVerbose ($ curlVerbose )
35+ {
36+ $ this ->curlVerbose = $ curlVerbose ;
37+
38+ return $ this ;
39+ }
40+ }
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ public function submit(array $data, array $curlOpts = [])
6767 }
6868
6969 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
70- curl_setopt ($ ch , CURLOPT_VERBOSE , 1 );
70+ curl_setopt ($ ch , CURLOPT_VERBOSE , $ this -> mautic -> getConfig ()-> getCurlVerbose () );
7171 curl_setopt ($ ch , CURLOPT_HEADER , 1 );
7272
7373 foreach ($ curlOpts as $ key => $ value ) {
You can’t perform that action at this time.
0 commit comments