Commit 1783e05c authored by Tino Goratsch's avatar Tino Goratsch

removed the CookiesParameterBag and use the ParameterBag from the Symfony request stack

parent eb66a027
......@@ -81,11 +81,11 @@ abstract class AbstractRequest implements RequestInterface
/**
* Returns the parameter bag of the $_COOKIE superglobal
*
* @return \ACP3\Core\Http\Request\CookiesParameterBag
* @return \Symfony\Component\HttpFoundation\ParameterBag
*/
public function getCookies()
{
return $this->cookies;
return $this->symfonyRequest->cookies;
}
/**
......@@ -140,7 +140,6 @@ abstract class AbstractRequest implements RequestInterface
protected function fillParameterBags()
{
$this->cookies = new CookiesParameterBag($this->symfonyRequest->cookies->all());
$this->userAgent = new UserAgent($this->symfonyRequest->server);
}
}
<?php
namespace ACP3\Core\Http\Request;
use Symfony\Component\HttpFoundation\ParameterBag;
/**
* Class CookieParameterBag
* @package ACP3\Core\Http\Request
*/
class CookiesParameterBag extends ParameterBag
{
/**
* @param string $key
* @param string $value
* @param int $expire
* @param string $path
* @param string $domain
* @param bool $isSecure
* @param bool $isHttpOnly
*/
public function set($key, $value, $expire = 0, $path = '', $domain = '', $isSecure = false, $isHttpOnly = true)
{
setcookie($key, $value, $expire, $path, $domain, $isSecure, $isHttpOnly);
parent::set($key, $value);
}
}
......@@ -115,7 +115,7 @@ interface RequestInterface
/**
* Returns the parameter bag of the $_COOKIE superglobal
*
* @return \ACP3\Core\Http\Request\CookiesParameterBag
* @return \Symfony\Component\HttpFoundation\ParameterBag
*/
public function getCookies();
......
......@@ -9,6 +9,8 @@ namespace ACP3\Core\Session;
use ACP3\Core\Database\Connection;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Http\RequestInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
/**
* @package ACP3\Core
......@@ -27,24 +29,31 @@ class SessionHandler extends AbstractSessionHandler
* @var \ACP3\Core\Http\RequestInterface
*/
protected $request;
/**
* @var Response
*/
protected $response;
/**
* @var bool
*/
protected $gcCalled = false;
/**
* @param \ACP3\Core\Database\Connection $db
* @param \ACP3\Core\Database\Connection $db
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Http\RequestInterface $request
* @param Response $response
*/
public function __construct(
Connection $db,
ApplicationPath $appPath,
RequestInterface $request
RequestInterface $request,
Response $response
) {
$this->db = $db;
$this->appPath = $appPath;
$this->request = $request;
$this->response = $response;
$this->configureSession();
}
......@@ -140,7 +149,14 @@ class SessionHandler extends AbstractSessionHandler
$this->resetSessionData();
if ($this->request->getCookies()->has(self::SESSION_NAME)) {
setcookie(self::SESSION_NAME, '', time() - 3600, $this->appPath->getWebRoot());
$cookie = new Cookie(
self::SESSION_NAME,
'',
(new \DateTime())->modify('-3600 seconds'),
$this->appPath->getWebRoot()
);
$this->response->headers->setCookie($cookie);
//setcookie(self::SESSION_NAME, '', time() - 3600, $this->appPath->getWebRoot());
}
// Delete the session from the database
......
......@@ -8,6 +8,8 @@ use ACP3\Core\Helpers\Secure;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\Session\SessionHandlerInterface;
use ACP3\Modules\ACP3\Users;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
/**
* Class User
......@@ -71,20 +73,26 @@ class User
* @var \ACP3\Core\Environment\ApplicationPath
*/
protected $appPath;
/**
* @var Response
*/
protected $response;
/**
* User constructor.
*
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param \ACP3\Core\Http\RequestInterface $request
* @param Response $response
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param \ACP3\Core\Authentication\AuthenticationInterface $authentication
* @param \ACP3\Core\Session\SessionHandlerInterface $sessionHandler
* @param \ACP3\Core\Helpers\Secure $secureHelper
* @param \ACP3\Core\Config $config
* @param \ACP3\Modules\ACP3\Users\Model\UserRepository $userRepository
* @param \ACP3\Core\Session\SessionHandlerInterface $sessionHandler
* @param \ACP3\Core\Helpers\Secure $secureHelper
* @param \ACP3\Core\Config $config
* @param \ACP3\Modules\ACP3\Users\Model\UserRepository $userRepository
*/
public function __construct(
RequestInterface $request,
Response $response,
ApplicationPath $appPath,
AuthenticationInterface $authentication,
SessionHandlerInterface $sessionHandler,
......@@ -93,6 +101,7 @@ class User
Users\Model\UserRepository $userRepository
) {
$this->request = $request;
$this->response = $response;
$this->appPath = $appPath;
$this->authentication = $authentication;
$this->sessionHandler = $sessionHandler;
......@@ -143,13 +152,15 @@ class User
*/
public function setRememberMeCookie($userId, $token, $expiry)
{
$this->request->getCookies()->set(
$cookie = new Cookie(
self::AUTH_NAME,
$userId . '|' . $token,
time() + $expiry,
(new \DateTime())->modify('+' . $expiry . ' seconds'),
$this->appPath->getWebRoot(),
$this->getCookieDomain()
);
$this->response->headers->setCookie($cookie);
}
/**
......
......@@ -104,11 +104,13 @@ services:
- '@core.db'
- '@core.environment.application_path'
- '@core.http.request'
- '@core.http.response'
core.user:
class: ACP3\Core\User
arguments:
- '@core.http.request'
- '@core.http.response'
- '@core.environment.application_path'
- '@core.authentication'
- '@core.session'
......
......@@ -27,11 +27,14 @@ $cacheStore = new \Symfony\Component\HttpKernel\HttpCache\Store(
$kernel->getAppPath()->getCacheDir() . 'http/'
);
$httpCache = new \Symfony\Component\HttpKernel\HttpCache\HttpCache(
$kernel,
$cacheStore,
new \Symfony\Component\HttpKernel\HttpCache\Esi(),
['debug' => $appMode === \ACP3\Core\Environment\ApplicationMode::DEVELOPMENT]
);
// Enable the HTTP cache only if we are in production mode
if ($appMode === \ACP3\Core\Environment\ApplicationMode::PRODUCTION) {
$kernel = new \Symfony\Component\HttpKernel\HttpCache\HttpCache(
$kernel,
$cacheStore,
new \Symfony\Component\HttpKernel\HttpCache\Esi(),
['debug' => $appMode === \ACP3\Core\Environment\ApplicationMode::DEVELOPMENT]
);
}
$httpCache->handle($request)->send();
$kernel->handle($request)->send();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment