Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CookieService | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getId | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Drupal\visitors\Service; |
| 4 | |
| 5 | use Drupal\visitors\VisitorsCookieInterface; |
| 6 | use Symfony\Component\HttpFoundation\RequestStack; |
| 7 | |
| 8 | /** |
| 9 | * Cookie service. |
| 10 | */ |
| 11 | class CookieService implements VisitorsCookieInterface { |
| 12 | |
| 13 | /** |
| 14 | * The request object. |
| 15 | * |
| 16 | * @var \Symfony\Component\HttpFoundation\Request |
| 17 | */ |
| 18 | protected $request; |
| 19 | |
| 20 | /** |
| 21 | * Constructs a new CookieService. |
| 22 | * |
| 23 | * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack |
| 24 | * The request object. |
| 25 | */ |
| 26 | public function __construct(RequestStack $request_stack) { |
| 27 | $this->request = $request_stack->getCurrentRequest(); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * {@inheritdoc} |
| 32 | */ |
| 33 | public function getId(): ?string { |
| 34 | $_pk_id = NULL; |
| 35 | foreach ($this->request->cookies as $name => $value) { |
| 36 | if (strpos($name, '_pk_id_') === 0) { |
| 37 | $_pk_id = $value; |
| 38 | } |
| 39 | } |
| 40 | [$visitor_id] = is_string($_pk_id) ? explode('.', $_pk_id) : [NULL]; |
| 41 | |
| 42 | return $visitor_id; |
| 43 | } |
| 44 | |
| 45 | } |