Skip to content

Commit 6b879e1

Browse files
authored
Merge pull request #12 from 9rj/master
Adding a DTO object to control curl verbose logging
2 parents e6b8cc4 + 08eda85 commit 6b879e1

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ require __DIR__.'/vendor/autoload.php';
2727
// Define the namespace of the Mautic object
2828
use 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

examples/simple-email-form/controller.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require __DIR__.'/../../vendor/autoload.php';
55

66
use Escopecz\MauticFormSubmit\Mautic;
7+
use Escopecz\MauticFormSubmit\Mautic\Config;
78

89
class 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(

src/Mautic.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Escopecz\MauticFormSubmit\Mautic\Form;
66
use Escopecz\MauticFormSubmit\Mautic\Contact;
77
use 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
}

src/Mautic/Config.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

src/Mautic/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)