소스 검색

Adaptations VisitorBuilder #515

develop
Guillaume Bourgeois 2 년 전
부모
커밋
70f67acfae
1개의 변경된 파일29개의 추가작업 그리고 24개의 파일을 삭제
  1. +29
    -24
      Builder/User/VisitorBuilder.php

+ 29
- 24
Builder/User/VisitorBuilder.php 파일 보기

@@ -16,20 +16,21 @@ class VisitorBuilder
protected EntityManagerInterface $entityManager;

public function __construct(
EntityManagerInterface $entityManager,
CookieComponent $cookieComponent,
ParameterBagInterface $parameterBag
) {
EntityManagerInterface $entityManager,
CookieComponent $cookieComponent,
ParameterBagInterface $parameterBag
)
{
$this->entityManager = $entityManager;
$this->cookieComponent = $cookieComponent;
$this->parameterBag = $parameterBag;
}

// addVisitor
public function create(string $cookie, string $ip)
public function create(string $cookieValue, string $ip)
{
$visitorFactory = new VisitorFactory();
$visitor = $visitorFactory->create($cookie, $ip);
$visitor = $visitorFactory->create($cookieValue, $ip);

$this->entityManager->create($visitor);
$this->entityManager->flush();
@@ -37,9 +38,11 @@ class VisitorBuilder

public function update(VisitorInterface $visitor)
{
$totalVisit = $visitor->getTotalVisit() + 1;
if($visitor->getLastAccess() < new \DateTime('-1 hour')) {
$totalVisit = $visitor->getTotalVisit() + 1;
$visitor->setTotalVisit($totalVisit);
}

$visitor->setTotalVisit($totalVisit);
$visitor->setLastAccess(new \DateTime());

$this->entityManager->update($visitor);
@@ -47,30 +50,32 @@ class VisitorBuilder
}

// setCookieVisitor
public function setCookie($response, $cookie): void
public function setCookie($response, $cookieValue): Cookie
{
$response->headers->setCookie(
Cookie::create(
$this->parameterBag->get('app.cookie_name_visitor'),
$this->cookieComponent->cryptCookie($cookie),
new \DateTime('+2 months'),
'/',
$this->cookieComponent->getCookieDomain()
)
$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()
)
Cookie::create(
$this->parameterBag->get('app.cookie_name_visitor'),
$this->cookieComponent->cryptCookie($this->getVisitorCurrent()->getCookie()),
new \DateTime('+2 months'),
'/',
$this->cookieComponent->getCookieDomain()
)
);
}


Loading…
취소
저장