entityManager = $entityManager; $this->cookieComponent = $cookieComponent; $this->parameterBag = $parameterBag; } // addVisitor public function create(string $cookieValue, string $ip) { $visitorFactory = new VisitorFactory(); $visitor = $visitorFactory->create($cookieValue, $ip); $this->entityManager->create($visitor); $this->entityManager->flush(); } public function update(VisitorInterface $visitor) { if($visitor->getLastAccess() < new \DateTime('-1 hour')) { $totalVisit = $visitor->getTotalVisit() + 1; $visitor->setTotalVisit($totalVisit); } $visitor->setLastAccess(new \DateTime()); $this->entityManager->update($visitor); $this->entityManager->flush(); } // setCookieVisitor public function setCookie($response, $cookieValue): Cookie { $cookie = Cookie::create( $this->parameterBag->get('app.cookie_name_visitor'), $this->cookieComponent->cryptCookie($cookieValue), new \DateTime('+2 months'), '/', $this->cookieComponent->getCookieDomain() ); $response->headers->setCookie($cookie); return $cookie; } // updateVisitorCookie public function updateCookie($response): void { $response->headers->setCookie( Cookie::create( $this->parameterBag->get('app.cookie_name_visitor'), $this->cookieComponent->cryptCookie($this->getVisitorCurrent()->getCookie()), new \DateTime('+2 months'), '/', $this->cookieComponent->getCookieDomain() ) ); } }