CookieHelper.php in Persistent Login 8
File
src/CookieHelper.php
View source
<?php
namespace Drupal\persistent_login;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Session\SessionConfigurationInterface;
use Symfony\Component\HttpFoundation\Request;
class CookieHelper implements CookieHelperInterface {
private $sessionConfiguration;
private $configFactory;
public function __construct(SessionConfigurationInterface $session_configuration, ConfigFactoryInterface $configFactory) {
$this->sessionConfiguration = $session_configuration;
$this->configFactory = $configFactory;
}
public function getCookieName(Request $request) {
$prefix = $this->configFactory
->get('persistent_login.settings')
->get('cookie_prefix');
if ($request
->isSecure()) {
$prefix = 'S' . $prefix;
}
$sessionConfigurationSettings = $this->sessionConfiguration
->getOptions($request);
$session_name = preg_replace('/^S?SESS/', '', $sessionConfigurationSettings['name']);
return $prefix . $session_name;
}
public function getCookieValue(Request $request) {
return $request->cookies
->get($this
->getCookieName($request));
}
public function hasCookie(Request $request) {
return $request->cookies
->has($this
->getCookieName($request));
}
}