-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to track by device_id instead of session_id cookie
- Loading branch information
Showing
6 changed files
with
156 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Escopecz\MauticFormSubmit; | ||
|
||
/** | ||
* HTTP Header Helper | ||
*/ | ||
class HttpHeader | ||
{ | ||
/** | ||
* Key-valye paries of headers | ||
* | ||
* @var array | ||
*/ | ||
private $headers = []; | ||
|
||
/** | ||
* Key-valye paries of cookies | ||
* | ||
* @var array | ||
*/ | ||
private $cookies = []; | ||
|
||
public function __construct($textHeaders) | ||
{ | ||
$this->parse($textHeaders); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return string|null | ||
*/ | ||
public function getHeaderValue($key) | ||
{ | ||
return isset($this->headers[$key]) ? $this->headers[$key] : null; | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return string|null | ||
*/ | ||
public function getCookieValue($key) | ||
{ | ||
return isset($this->cookies[$key]) ? $this->cookies[$key] : null; | ||
} | ||
|
||
/** | ||
* Parse text headers and fills in cookies and headers properites | ||
* | ||
* @param string $headers | ||
*/ | ||
private function parse($headers) | ||
{ | ||
foreach (preg_split('/\r\n|\r|\n/', $headers) as $i => $line) { | ||
if ($i === 0) { | ||
$this->headers['http_code'] = $line; | ||
} else { | ||
list($key, $value) = explode(': ', $line); | ||
|
||
if ($key === 'Set-Cookie') { | ||
list($textCookie) = explode(';', $value); | ||
list($cookieKey, $cookieValue) = explode('=', $textCookie); | ||
|
||
$this->cookies[$cookieKey] = $cookieValue; | ||
} else { | ||
$this->headers[$key] = $value; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Escopecz\MauticFormSubmit\Test; | ||
|
||
use Escopecz\MauticFormSubmit\HttpHeader; | ||
|
||
class HttpHeaderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $testTextHeader = 'HTTP/1.1 302 Found | ||
Date: Wed, 04 Jul 2018 08:33:39 GMT | ||
Server: Apache/2.4.33 (Unix) OpenSSL/1.0.2o PHP/7.1.16 | ||
X-Powered-By: PHP/7.1.16 | ||
Set-Cookie: 10b307a255ccdba6a2d32498b0c61978=5329avlkmibr4galpllvo1rmf7; path=/; HttpOnly | ||
Set-Cookie: mautic_session_id=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/ | ||
Set-Cookie: mautic_device_id=6txmz3mu2dslmkhrera668e; expires=Thu, 04-Jul-2019 08:33:39 GMT; Max-Age=31536000; path=/ | ||
Set-Cookie: mtc_id=18061; path=/ | ||
Set-Cookie: mtc_sid=6txmz3mu2dslmkhrera668e; path=/ | ||
Set-Cookie: mautic_session_id=6txmz3mu2dslmkhrera668e; expires=Thu, 04-Jul-2019 08:33:39 GMT; Max-Age=31536000; path=/ | ||
Set-Cookie: 6txmz3mu2dslmkhrera668e=18061; expires=Thu, 04-Jul-2019 08:33:39 GMT; Max-Age=31536000; path=/ | ||
Cache-Control: no-cache | ||
Location: http://localhost/mautic-form-submit/examples/simple-email-form/?mauticMessage=Hello%21 | ||
X-Debug-Token: 152d17 | ||
X-Debug-Token-Link: http://mautic.test/index_dev.php/_profiler/152d17 | ||
Content-Length: 588 | ||
Content-Type: text/html; charset=UTF-8'; | ||
|
||
function test_get_base_url() | ||
{ | ||
$headerHelper = new HttpHeader($this->testTextHeader); | ||
$this->assertEquals('6txmz3mu2dslmkhrera668e', $headerHelper->getCookieValue('mautic_session_id')); | ||
$this->assertEquals('18061', $headerHelper->getCookieValue('mtc_id')); | ||
$this->assertEquals('18061', $headerHelper->getCookieValue('6txmz3mu2dslmkhrera668e')); | ||
$this->assertEquals('Apache/2.4.33 (Unix) OpenSSL/1.0.2o PHP/7.1.16', $headerHelper->getHeaderValue('Server')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters