class CookieHelper in Persistent Login 8
Cookie helper service.
Hierarchy
- class \Drupal\persistent_login\CookieHelper implements CookieHelperInterface
Expanded class hierarchy of CookieHelper
1 string reference to 'CookieHelper'
1 service uses CookieHelper
File
- src/
CookieHelper.php, line 12
Namespace
Drupal\persistent_loginView source
class CookieHelper implements CookieHelperInterface {
/**
* The session configuration.
*
* @var \Drupal\Core\Session\SessionConfigurationInterface
*/
private $sessionConfiguration;
/**
* The Config Factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
private $configFactory;
/**
* Instantiates a new CookieHelper instance.
*
* @param \Drupal\Core\Session\SessionConfigurationInterface $session_configuration
* The session configuration.
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The Config Factory service.
*/
public function __construct(SessionConfigurationInterface $session_configuration, ConfigFactoryInterface $configFactory) {
$this->sessionConfiguration = $session_configuration;
$this->configFactory = $configFactory;
}
/**
* {@inheritdoc}
*/
public function getCookieName(Request $request) {
$prefix = $this->configFactory
->get('persistent_login.settings')
->get('cookie_prefix');
// Use different session identifiers for HTTPS and HTTP to prevent a cookie
// collision.
// @see \Drupal\Core\Session\SessionConfiguration::getName()
if ($request
->isSecure()) {
$prefix = 'S' . $prefix;
}
$sessionConfigurationSettings = $this->sessionConfiguration
->getOptions($request);
// Replace the session cookie prefix.
$session_name = preg_replace('/^S?SESS/', '', $sessionConfigurationSettings['name']);
return $prefix . $session_name;
}
/**
* {@inheritdoc}
*/
public function getCookieValue(Request $request) {
return $request->cookies
->get($this
->getCookieName($request));
}
/**
* {@inheritdoc}
*/
public function hasCookie(Request $request) {
return $request->cookies
->has($this
->getCookieName($request));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CookieHelper:: |
private | property | The Config Factory service. | |
CookieHelper:: |
private | property | The session configuration. | |
CookieHelper:: |
public | function |
Returns the name of the persistent login cookie. Overrides CookieHelperInterface:: |
|
CookieHelper:: |
public | function |
Returns the value of the persistent login cookie. Overrides CookieHelperInterface:: |
|
CookieHelper:: |
public | function |
Checks if a request contains a persistent login cookie. Overrides CookieHelperInterface:: |
|
CookieHelper:: |
public | function | Instantiates a new CookieHelper instance. |