1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpha\VisitorTrackingBundle\Features\Context; |
4
|
|
|
|
5
|
|
|
use Alpha\VisitorTrackingBundle\Entity\Session; |
6
|
|
|
use Alpha\VisitorTrackingBundle\EventListener\VisitorTrackingSubscriber; |
7
|
|
|
use Behat\Behat\Context\Context; |
8
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
9
|
|
|
use Behat\MinkExtension\Context\RawMinkContext; |
10
|
|
|
use Doctrine\Inflector\InflectorFactory; |
11
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
12
|
|
|
use Alpha\VisitorTrackingBundle\Entity\Lifetime; |
13
|
|
|
|
14
|
|
|
class DeviceContext extends RawMinkContext implements Context, SnippetAcceptingContext |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
private $entityManager; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var array<int, string> |
20
|
|
|
*/ |
21
|
|
|
private $utmCodes = [ |
22
|
|
|
'utm_source', |
23
|
|
|
'utm_medium', |
24
|
|
|
'utm_campaign', |
25
|
|
|
'utm_term', |
26
|
|
|
'utm_content' |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
public function __construct(EntityManagerInterface $entityManager) |
30
|
|
|
{ |
31
|
|
|
$this->entityManager = $entityManager; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @Given /^a user session exists$/ |
36
|
|
|
*/ |
37
|
|
|
public function theCookieHasTheValue(): void |
38
|
|
|
{ |
39
|
|
|
$session = new Session(); |
40
|
|
|
$session->setIp('127.0.0.1'); |
41
|
|
|
$session->setReferrer(''); |
42
|
|
|
$session->setUserAgent(''); |
43
|
|
|
$session->setQueryString(''); |
44
|
|
|
$session->setLoanTerm(''); |
45
|
|
|
$session->setRepApr(''); |
46
|
|
|
foreach ($this->utmCodes as $code) { |
47
|
|
|
$method = 'set'.InflectorFactory::create()->build()->classify($code); |
48
|
|
|
$session->$method(''); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$lifetime = new Lifetime(); |
52
|
|
|
$lifetime->addSession($session); |
53
|
|
|
$session->setLifetime($lifetime); |
54
|
|
|
|
55
|
|
|
$this->entityManager->persist($lifetime); |
56
|
|
|
$this->entityManager->persist($session); |
57
|
|
|
$this->entityManager->flush(); |
58
|
|
|
|
59
|
|
|
$this->getSession()->setCookie(VisitorTrackingSubscriber::COOKIE_SESSION, $session->getId()); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.