Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • project/social_api
  • issue/social_api-3227814
  • issue/social_api-3250391
  • issue/social_api-3284354
  • issue/social_api-3298114
  • issue/social_api-3313622
  • issue/social_api-3317310
  • issue/social_api-3428131
  • issue/social_api-3434674
  • issue/social_api-3471591
  • issue/social_api-3487630
  • issue/social_api-3492428
  • issue/social_api-3501411
13 results
Show changes
Commits on Source (21)
Showing
with 260 additions and 174 deletions
################
# GitLabCI template for Drupal projects.
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification.
# It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
# As long as you include the project, ref and three files below, any future updates added by the Drupal Association will be used in your
# pipelines automatically. However, you can modify this template if you have additional needs for your project.
# The full documentation is on https://project.pages.drupalcode.org/gitlab_templates/
################
# For information on alternative values for 'ref' see https://project.pages.drupalcode.org/gitlab_templates/info/templates-version/
# To test a Drupal 7 project, change the first include filename from .main.yml to .main-d7.yml
include:
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- "/includes/include.drupalci.main.yml"
- "/includes/include.drupalci.variables.yml"
- "/includes/include.drupalci.workflows.yml"
################
# Pipeline configuration variables are defined with default values and descriptions in the file
# https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
# Uncomment the lines below if you want to override any of the variables. The following is just an example.
################
variables:
OPT_IN_TEST_PREVIOUS_MAJOR: 1
OPT_IN_TEST_PREVIOUS_MINOR: 1
OPT_IN_TEST_NEXT_MINOR: 1
OPT_IN_TEST_NEXT_MAJOR: 1
# Check for deprecation.
RUN_JOB_UPGRADE_STATUS: 1
_CSPELL_WORDS: 'autoposting, phpcompatibility'
CONTENTS OF THIS FILE
---------------------
* Introduction
* Recommended modules
* Installation
* Support requests
* Maintainers
INTRODUCTION
------------
* This project is part of the [Drupal Social Initiative](https://groups.drupal.org/social-initiative).
* The Social API harmonizes social networking services in Drupal,
providing an extensible module that allows integration of modules
for user login, autoposting, and social widgets.
* Social API aims to abstract parameters for communicating with various social
networking services.
* For a full description of the module, visit the project page:
[https://www.drupal.org/project/social_api](https://www.drupal.org/project/social_api)
* To submit bug reports and feature suggestions, or to track changes:
[https://drupal.org/project/issues/social_api](https://drupal.org/project/issues/social_api)
RECOMMENDED MODULES
-------------------
* [Social Auth](https://www.drupal.org/project/social_auth):
Implements methods and templates that will be used by login-related modules.
* [Social Post](https://www.drupal.org/project/social_post):
Provides methods to allow autoposting to social network accounts.
* [Social Widgets](https://www.drupal.org/project/social_widgets):
Allows sub-modules to add functionality to add widgets (like buttons, embedded
content) to node, blocks, etc.
INSTALLATION
------------
Install as you would normally install a contributed Drupal module. See
[Installing Modules](https://www.drupal.org/docs/extending-drupal/installing-modules)
for details.
SUPPORT REQUESTS
----------------
Before posting a support request, carefully read the installation
instructions provided in module documentation page.
Before posting a support request, check Recent log entries at
admin/reports/dblog.
Once you have done this, you can post a support request at module issue queue:
[https://www.drupal.org/project/issues/social_api](https://www.drupal.org/project/issues/social_api)
When posting a support request, please inform what does the status report say
at admin/reports/dblog and if you were able to see any errors in
Recent log entries.
MAINTAINERS
-----------
Current maintainers:
* [Christopher C. Wells (wells)](https://www.drupal.org/u/wells)
Development sponsored by:
* [Cascade Public Media](https://www.drupal.org/cascade-public-media)
# SOCIAL API
INTRODUCTION
------------
* This project is part of the Drupal Social Initiative
(https://groups.drupal.org/social-initiative).
* The Social API harmonizes social networking services in Drupal,
providing an extensible module that allows integration of modules
for user login, autoposting, and social widgets.
* Social API aims to abstract parameters for communicating with various social
networking services.
* For a full description of the module, visit the project page:
https://www.drupal.org/project/social_api
* To submit bug reports and feature suggestions, or to track changes:
https://drupal.org/project/issues/social_api
RECOMMENDED MODULES
-------------------
* Social Auth (https://www.drupal.org/project/social_auth):
Implements methods and templates that will be used by login-related modules.
* Social Post (https://www.drupal.org/project/social_post):
Provides methods to allow autoposting to social network accounts.
* Social Widgets (https://www.drupal.org/project/social_widgets):
Allows sub-modules to add functionality to add widgets (like buttons, embedded
content) to node, blocks, etc.
UPDATES IN V2/V3
-------------
* Added default support for PHP League OAuth2 library that allows
authentication for OAuth 2.0 services such as Facebook, Google, and others.
However, other libraries and authentication protocols can still be used.
MAINTAINERS
-----------
Current maintainers:
* gvso - https://www.drupal.org/u/gvso
* himanshu-dixit - https://www.drupal.org/u/himanshu-dixit
Supporting organizations:
* Google Summer of Code (https://www.drupal.org/google-summer-of-code-0)
Google Summer of Code is a global program focused on bringing more student
developers into open source software development. Students work on a three
month programming project with an open source organization during their break
from university.
......@@ -32,14 +32,14 @@
],
"require" : {
"ext-openssl": "*",
"drupal/core": "^8.8 || ^9.0",
"league/oauth2-client": "^2.0"
"league/oauth2-client": "^2.0",
"drupal/core": "^9.5 || ^10 || ^11"
},
"require-dev": {
"drupal/coder": "^8.3",
"drupal/social_auth": "^3.0@dev",
"phpcompatibility/php-compatibility": "^9.3"
},
"minimum-stability": "dev",
"config": {
"sort-packages": true,
"allow-plugins": {
......
......@@ -7,7 +7,7 @@
<arg value="p"/>
<config name="drupal_core_version" value="9"/>
<config name="testVersion" value="7.3-" />
<config name="testVersion" value="8.0-" />
<file>.</file>
<exclude-pattern>vendor</exclude-pattern>
......
......@@ -2,5 +2,5 @@ name: Social API
type: module
description: Common interface for communicating with social networking services.
package: Social
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9.5 || ^10 || ^11
configure: social_api.admin_config
administer social api widgets:
title: 'Administer Social API widgets'
description: 'Perform administration tasks for Social API Plugins'
administer social api blocks:
title: 'Administer Social API blocks'
description: 'Perform administration tasks for Social API Blocks'
administer social api autoposting:
title: 'Administer Social API autoposting'
description: 'Perform administration tasks for Social API Autoposting'
administer social api authentication:
title: 'Administer Social API user authentication'
description: 'Perform administration tasks for Social API user authentication'
administer social api autoposting:
title: 'Administer Social API autoposting'
description: 'Perform administration tasks for Social API Autoposting'
administer social api blocks:
title: 'Administer Social API blocks'
description: 'Perform administration tasks for Social API Blocks'
administer social api configuration:
title: 'Administer Social API admin configuration'
description: 'Perform administration tasks for Social API configuration'
administer social api widgets:
title: 'Administer Social API widgets'
description: 'Perform administration tasks for Social API Plugins'
......@@ -4,4 +4,4 @@ social_api.admin_config:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
_title: 'Social API'
requirements:
_permission: 'administer site configuration'
_permission: 'administer social api configuration'
services:
plugin.network.manager:
class: Drupal\social_api\Plugin\NetworkManager
arguments: ['@container.namespaces', '@cache.discovery', '@module_handler']
arguments:
- '@container.namespaces'
- '@cache.discovery'
- '@module_handler'
......@@ -3,6 +3,7 @@
namespace Drupal\social_api\Annotation;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Defines a Social Network item annotation object.
......@@ -19,23 +20,30 @@ class Network extends Plugin {
*
* @var string
*/
public $id;
public string $id;
/**
* The social network service implemented by the plugin.
*
* @var \Drupal\Core\Annotation\Translation
* @var \Drupal\Core\Annotation\Translation|string
*
* @ingroup plugin_translatable
*/
public $socialNetwork;
public Translation|string $socialNetwork;
/**
* The type of the plugin.
*
* @var string
*/
public $type;
public string $type;
/**
* Fully qualified Class name of the plugin SDK.
*
* @var string
*/
public string $className;
/**
* A list of extra handlers.
......@@ -44,6 +52,6 @@ class Network extends Plugin {
*
* @todo Check the entity type plugins to copy from.
*/
public $handlers = [];
public array $handlers = [];
}
......@@ -17,43 +17,49 @@ abstract class OAuth2Manager implements OAuth2ManagerInterface {
* The service client.
*
* @var \League\OAuth2\Client\Provider\AbstractProvider|mixed
*
* @todo Figure out why this is mixed and narrow it.
*/
protected $client;
protected mixed $client = NULL;
/**
* Access token for OAuth2 authentication.
*
* @var \League\OAuth2\Client\Token\AccessToken|string|mixed
*
* @todo Figure out why this is mixed and narrow it.
*/
protected $accessToken;
protected mixed $accessToken = NULL;
/**
* Social Auth implementer settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $settings;
protected ImmutableConfig $settings;
/**
* The logger factory.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $loggerFactory;
protected LoggerChannelFactoryInterface $loggerFactory;
/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request|null
*/
protected $request;
protected ?Request $request;
/**
* The user returned by the provider.
*
* @var \League\OAuth2\Client\Provider\GenericResourceOwner|array|mixed
*
* @todo Figure out why this is mixed and narrow it.
*/
protected $user;
protected mixed $user = NULL;
/**
* OAuth2Manager Constructor.
......@@ -62,7 +68,7 @@ abstract class OAuth2Manager implements OAuth2ManagerInterface {
* The implementer settings.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* The logger factory.
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Symfony\Component\HttpFoundation\Request|null $request
* The current request.
*/
public function __construct(ImmutableConfig $settings,
......@@ -77,7 +83,7 @@ public function __construct(ImmutableConfig $settings,
/**
* {@inheritdoc}
*/
public function setClient($client) {
public function setClient($client): static {
$this->client = $client;
return $this;
}
......@@ -85,21 +91,21 @@ public function setClient($client) {
/**
* {@inheritdoc}
*/
public function getClient() {
public function getClient(): mixed {
return $this->client;
}
/**
* {@inheritdoc}
*/
public function getAccessToken() {
public function getAccessToken(): mixed {
return $this->accessToken;
}
/**
* {@inheritdoc}
*/
public function setAccessToken($access_token) {
public function setAccessToken($access_token): static {
$this->accessToken = $access_token;
return $this;
}
......
......@@ -23,7 +23,7 @@ public function authenticate();
* @return $this
* The current object.
*/
public function setClient($client);
public function setClient(mixed $client): static;
/**
* Gets the service client object.
......@@ -31,7 +31,7 @@ public function setClient($client);
* @return mixed
* The service client object.
*/
public function getClient();
public function getClient(): mixed;
/**
* Gets the access token after authentication.
......@@ -39,7 +39,7 @@ public function getClient();
* @return \League\OAuth2\Client\Token\AccessToken|mixed
* The access token.
*/
public function getAccessToken();
public function getAccessToken(): mixed;
/**
* Sets the access token.
......@@ -50,7 +50,7 @@ public function getAccessToken();
* @return $this
* The current object.
*/
public function setAccessToken($access_token);
public function setAccessToken(mixed $access_token): static;
/**
* Returns the authorization URL where user will be redirected.
......@@ -58,7 +58,7 @@ public function setAccessToken($access_token);
* @return string|mixed
* Absolute authorization URL.
*/
public function getAuthorizationUrl();
public function getAuthorizationUrl(): mixed;
/**
* Returns OAuth2 state.
......@@ -66,7 +66,7 @@ public function getAuthorizationUrl();
* @return string
* The OAuth2 state.
*/
public function getState();
public function getState(): string;
/**
* Gets data about the user.
......@@ -74,6 +74,6 @@ public function getState();
* @return \League\OAuth2\Client\Provider\GenericResourceOwner|array|mixed
* User info returned by provider.
*/
public function getUserInfo();
public function getUserInfo(): mixed;
}
......@@ -3,34 +3,49 @@
namespace Drupal\social_api\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Extension\ExtensionPathResolver;
use Drupal\social_api\Plugin\NetworkManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Renders integrations of social api.
*/
class SocialApiController extends ControllerBase {
/**
* Extension path resolver.
*
* @var \Drupal\Core\Extension\ExtensionPathResolver
*/
protected ExtensionPathResolver $extensionPathResolver;
/**
* The network manager.
*
* @var \Drupal\social_api\Plugin\NetworkManager
*/
private $networkManager;
private NetworkManager $networkManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('plugin.network.manager'));
public static function create(ContainerInterface $container): static {
return new static(
$container->get('extension.path.resolver'),
$container->get('plugin.network.manager')
);
}
/**
* SocialApiController constructor.
*
* @param \Drupal\Core\Extension\ExtensionPathResolver $extensionPathResolver
* Extension path resolver.
* @param \Drupal\social_api\Plugin\NetworkManager $networkManager
* The network manager.
*/
public function __construct(NetworkManager $networkManager) {
public function __construct(ExtensionPathResolver $extensionPathResolver, NetworkManager $networkManager) {
$this->extensionPathResolver = $extensionPathResolver;
$this->networkManager = $networkManager;
}
......@@ -43,7 +58,7 @@ public function __construct(NetworkManager $networkManager) {
* @return array
* Render array listing the integrations.
*/
public function integrations($type) {
public function integrations(string $type): array {
$networks = $this->networkManager->getDefinitions();
$header = [
$this->t('Module'),
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Site\Settings;
/**
......@@ -14,12 +15,10 @@ class SocialApi extends ContentEntityBase implements ContentEntityInterface {
/**
* {@inheritdoc}
*/
public static function create(array $values = []) {
public static function create(array $values = []): EntityInterface {
if (isset($values['token'])) {
$values['token'] = static::encryptToken($values['token']);
}
return parent::create($values);
}
......@@ -29,7 +28,7 @@ public static function create(array $values = []) {
* @return int
* User ID.
*/
public function getUserId() {
public function getUserId(): int {
return (int) $this->get('user_id')->target_id;
}
......@@ -39,12 +38,10 @@ public function getUserId() {
* @param string $token
* The serialized access token.
*
* @return \Drupal\social_auth\Entity\SocialApi
* Drupal Social Auth Entity.
* @return static
*/
public function setToken($token) {
public function setToken(string $token): static {
$this->set('token', $this->encryptToken($token));
return $this;
}
......@@ -54,9 +51,8 @@ public function setToken($token) {
* @return string
* The serialized access token.
*/
public function getToken() {
public function getToken(): string {
$token = $this->get('token')->value;
return $this->decryptToken($token);
}
......@@ -69,7 +65,7 @@ public function getToken() {
* @return string
* The encrypted token.
*/
protected static function encryptToken($token) {
protected static function encryptToken(string $token): string {
$key = static::getEncryptionKey();
// Remove the base64 encoding from our key.
......@@ -84,7 +80,7 @@ protected static function encryptToken($token) {
// The $iv is just as important as the key for decrypting, so save it with
// our encrypted data using a unique separator (::).
return base64_encode($encrypted . '::' . $iv);
return base64_encode("$encrypted::$iv");
}
/**
......@@ -96,7 +92,7 @@ protected static function encryptToken($token) {
* @return string
* The plain-text token provided by the provider.
*/
protected function decryptToken($token) {
protected function decryptToken(string $token): string {
$key = $this->getEncryptionKey();
// Removes the base64 encoding from our key.
......@@ -115,7 +111,7 @@ protected function decryptToken($token) {
* @return string
* The encryption key.
*/
protected static function getEncryptionKey() {
protected static function getEncryptionKey(): string {
return Settings::getHashSalt();
}
......
......@@ -21,35 +21,42 @@ abstract class NetworkBase extends PluginBase implements NetworkInterface {
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $loggerFactory;
protected LoggerChannelFactoryInterface $loggerFactory;
/**
* The global site settings.
*
* @var \Drupal\Core\Site\Settings
*/
protected $siteSettings;
protected Settings $siteSettings;
/**
* The implementer/plugin settings.
*
* @var \Drupal\social_api\Settings\SettingsInterface
*/
protected $settings;
protected SettingsInterface $settings;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
protected EntityTypeManagerInterface $entityTypeManager;
/**
* Network manager.
*
* @var \Drupal\social_api\Plugin\NetworkManager
*/
protected NetworkManager $networkManager;
/**
* The SDK client.
*
* @var mixed
*/
protected $sdk;
protected mixed $sdk = NULL;
/**
* Sets the underlying SDK library.
......@@ -58,9 +65,9 @@ abstract class NetworkBase extends PluginBase implements NetworkInterface {
* The initialized 3rd party library instance.
*
* @throws \Drupal\social_api\SocialApiException
* If the SDK library does not exist.
* If the SDK library does not exist or other validation fails.
*/
abstract protected function initSdk();
abstract protected function initSdk(): mixed;
/**
* Instantiates a NetworkBase object.
......@@ -79,6 +86,10 @@ abstract protected function initSdk();
* The entity type manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory object.
* @param \Drupal\social_api\Plugin\NetworkManager $network_manager
* Network manager.
*
* @throws \Drupal\social_api\SocialApiException
*/
public function __construct(array $configuration,
$plugin_id,
......@@ -86,7 +97,8 @@ public function __construct(array $configuration,
LoggerChannelFactoryInterface $logger_factory,
Settings $settings,
EntityTypeManagerInterface $entity_type_manager,
ConfigFactoryInterface $config_factory) {
ConfigFactoryInterface $config_factory,
NetworkManager $network_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
......@@ -95,6 +107,7 @@ public function __construct(array $configuration,
$this->entityTypeManager = $entity_type_manager;
$this->configuration = $entity_type_manager;
$this->init($config_factory);
$this->networkManager = $network_manager;
}
/**
......@@ -109,17 +122,17 @@ public function __construct(array $configuration,
* @throws \Drupal\social_api\SocialApiException
* When the settings are not valid.
*/
protected function init(ConfigFactoryInterface $config_factory) {
protected function init(ConfigFactoryInterface $config_factory): void {
$definition = $this->getPluginDefinition();
if (!empty($definition['handlers']['settings']['class']) && !empty($definition['handlers']['settings']['config_id'])) {
if (!class_exists($definition['handlers']['settings']['class'])) {
throw new SocialApiException('The specified settings class does not exist. Please check your plugin annotation.');
throw new SocialApiException("The settings class {$definition['handlers']['settings']['class']} does not exist. Please check your plugin annotation.");
}
$config = $config_factory->get($definition['handlers']['settings']['config_id']);
$settings = call_user_func($definition['handlers']['settings']['class'] . '::factory', $config);
if (!$settings instanceof SettingsInterface) {
throw new SocialApiException('The provided settings class does not implement the expected settings interface.');
throw new SocialApiException("The settings class {$definition['handlers']['settings']['class']} does not implement the expected settings interface.");
}
$this->settings = $settings;
......@@ -129,8 +142,7 @@ protected function init(ConfigFactoryInterface $config_factory) {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
return new static(
$configuration,
$plugin_id,
......@@ -138,7 +150,8 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('logger.factory'),
$container->get('settings'),
$container->get('entity_type.manager'),
$container->get('config.factory')
$container->get('config.factory'),
$container->get('plugin.network.manager'),
);
}
......@@ -146,11 +159,10 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function getSdk() {
public function getSdk(): mixed {
if (!$this->sdk) {
$this->sdk = $this->initSdk();
}
return $this->sdk;
}
......
......@@ -16,6 +16,6 @@ interface NetworkInterface extends PluginInspectionInterface, ContainerFactoryPl
* @return mixed
* The SDK client.
*/
public function getSdk();
public function getSdk(): mixed;
}
......@@ -2,9 +2,9 @@
namespace Drupal\social_api\Plugin;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Provides the Social Network plugin manager.
......@@ -29,4 +29,14 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
$this->setCacheBackend($cache_backend, 'social_api_network_plugins');
}
/**
* Gets the module handler.
*
* @return \Drupal\Core\Extension\ModuleHandlerInterface
* Module handler.
*/
public function getModuleHandler(): ModuleHandlerInterface {
return $this->moduleHandler;
}
}
......@@ -16,7 +16,7 @@ abstract class SettingsBase implements SettingsInterface {
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
protected ImmutableConfig $config;
/**
* Creates a new settings object.
......@@ -31,14 +31,14 @@ public function __construct(ImmutableConfig $config) {
/**
* {@inheritdoc}
*/
public static function factory(ImmutableConfig $config) {
public static function factory(ImmutableConfig $config): static {
return new static($config);
}
/**
* {@inheritdoc}
*/
public function getConfig() {
public function getConfig(): ImmutableConfig {
return $this->config;
}
......
......@@ -17,7 +17,7 @@ interface SettingsInterface {
* @return \Drupal\Core\Config\ImmutableConfig
* The configuration object associated with the settings.
*/
public function getConfig();
public function getConfig(): ImmutableConfig;
/**
* Factory method to create a new settings object.
......@@ -25,6 +25,6 @@ public function getConfig();
* @param \Drupal\Core\Config\ImmutableConfig $config
* The configuration object.
*/
public static function factory(ImmutableConfig $config);
public static function factory(ImmutableConfig $config): static;
}
......@@ -11,23 +11,16 @@ abstract class SocialApiDataHandler {
/**
* The session service.
*
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface
*/
protected $session;
protected SessionInterface $session;
/**
* The prefix each session variable will have.
*
* @var string
*/
protected $sessionPrefix;
protected string $sessionPrefix;
/**
* Constructor.
*
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
* Used for reading data from and writing data to session.
*/
public function __construct(SessionInterface $session) {
$this->session = $session;
......@@ -35,47 +28,37 @@ public function __construct(SessionInterface $session) {
/**
* Gets a session variable by key.
*
* @param string $key
* The session variable key.
*
* @return mixed
* The session variable value.
*/
public function get($key) {
public function get(string $key): mixed {
return $this->session->get($this->getSessionPrefix() . $key);
}
/**
* Sets a new session variable.
*
* @param string $key
* The session variable key.
* @param mixed $value
* The session variable value.
*/
public function set($key, $value) {
public function set(string $key, mixed $value): void {
$this->session->set($this->getSessionPrefix() . $key, $value);
}
/**
* Gets the session prefix for the data handler.
*
* @return string
* The session prefix.
*/
public function getSessionPrefix() {
public function getSessionPrefix(): string {
return $this->sessionPrefix;
}
/**
* Sets the session prefix for the data handler.
*
* @param string $prefix
* The session prefix.
*/
public function setSessionPrefix($prefix) {
$this->sessionPrefix = $prefix . '_';
public function setSessionPrefix(string $prefix): void {
$this->sessionPrefix = "{$prefix}_";
}
/**
* Gets the session being used by the data handler.
*/
public function getSession(): SessionInterface {
return $this->session;
}
}