Skip to content

Commit

Permalink
[Session] deprecate session class (pimcore#13923)
Browse files Browse the repository at this point in the history
* [Session] deprecate session class

* Update lib/Tool/Session.php

Co-authored-by: Bernhard Rusch <[email protected]>

* [Session] deprecate session class

* Update Session.php

* Update Session.php

* Update Session.php

* [Session] add upgrade notes

* clarify session variable

* Apply suggestions from code review

Co-authored-by: Jacob Dreesen <[email protected]>

* Apply suggestions from code review

Co-authored-by: Bernhard Rusch <[email protected]>
Co-authored-by: Jacob Dreesen <[email protected]>
  • Loading branch information
3 people authored Jan 2, 2023
1 parent f14d52d commit 4d3f1e3
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* @deprecated
*/
class PreAuthenticatedAdminSessionFactory implements AuthenticatorFactoryInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

/**
* @internal
* @deprecated
*/
class AdminSessionHandler implements LoggerAwareInterface, AdminSessionHandlerInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

/**
* @internal
* @deprecated
*/
interface AdminSessionHandlerInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Upgrade Notes

## 10.6.0
- [Session] The `getHandler`, `setHandler`, `useSession`, `getSessionId`, `getSessionName`, `invalidate`, `regenerateId`, `requestHasSessionId`, `getSessionIdFromRequest`, `get`, `getReadOnly` and `writeClose` methods of `Pimcore\Tool\Session` and class `PreAuthenticatedAdminSessionFactory` are deprecated and get removed with Pimcore 11. Session Management will be handled by Symfony in Pimcore 11.
- [AreabrickManagerInterface] The `enable`, `disable`, `isEnabled` and `getState` methods of `Pimcore\Extension\Document\Areabrick\AreabrickManagerInterface` are deprecated as maintaining state of extensions is deprecated. This impacts `\Pimcore\Document\Editable\EditableHandler::isBrickEnabled()` method which is also deprecated.
- [Twig] Pimcore now requires the `twig/extra-bundle` which eases the usage of Twig's "extra" extensions.
- [UrlSlug] Deprecated `$index` property and its getter and setter methods as they were not being used. These will be removed in Pimcore 11.
Expand Down
127 changes: 111 additions & 16 deletions lib/Tool/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Pimcore\Bundle\AdminBundle\Session\Handler\AdminSessionHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

final class Session
{
Expand All @@ -29,83 +30,165 @@ final class Session
*/
private static $handler;

public static function getHandler(): AdminSessionHandlerInterface
/**
* @desc This is for forward compatibility, the custom Session implementation is not being used anymore in Pimcore 11.
* @desc For forward compatibility, you can use this class and pass the SessionInterface from the request, in Pimcore 10.6, the Admin Session will be used instead
*
* @param SessionInterface $session Parameter is not used here since the dedicated Admin Session is used. Please pass the Request SessionInterface here for forward compatibility
*
* @param callable(AttributeBagInterface, SessionInterface):mixed $func
*
*/
public static function useBag(SessionInterface $session, callable $func, string $namespace = 'pimcore_admin'): mixed
{
return self::getSessionHandler()->useSessionAttributeBag($func, $namespace);
}

/**
* @desc This is for forward compatibility, the custom Session implementation is not being used anymore in Pimcore 11.
* @desc For forward compatibility, you can use this class and pass the SessionInterface from the request, in Pimcore 10.6, the Admin Session will be used instead
*
* @param SessionInterface $session Parameter is not used here since the dedicated Admin Session is used. Please pass the Request SessionInterface here for forward compatibility
*
* @param string $namespace
*
*/
public static function getSessionBag(
SessionInterface $session,
string $namespace = 'pimcore_admin'
): ?AttributeBagInterface {

$bag = self::getSessionHandler()->loadAttributeBag($namespace);
if ($bag instanceof AttributeBagInterface) {
return $bag;
}

return null;
}

/**
* @deprecated
*/
private static function getSessionHandler(): AdminSessionHandlerInterface
{
if (null === static::$handler) {
static::$handler = \Pimcore::getContainer()->get(AdminSessionHandler::class);
if (null === self::$handler) {
self::$handler = \Pimcore::getContainer()->get(AdminSessionHandler::class);
}

return static::$handler;
return self::$handler;
}

/**
* @deprecated
*/
public static function getHandler(): AdminSessionHandlerInterface
{
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. No alternative given.', __METHOD__));

return self::getSessionHandler();
}

/**
* @deprecated
*/
public static function setHandler(AdminSessionHandlerInterface $handler)
{
static::$handler = $handler;
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. No alternative given.', __METHOD__));

self::$handler = $handler;
}

/**
* @param callable $func
* @param string $namespace
*
* @return mixed
*
* @deprecated
*/
public static function useSession($func, string $namespace = 'pimcore_admin')
{
return static::getHandler()->useSessionAttributeBag($func, $namespace);
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. Use \Pimcore\Tool\Session::useBag instead.', __METHOD__));

return self::getSessionHandler()->useSessionAttributeBag($func, $namespace);
}

/**
* @return string
*
* @deprecated
*/
public static function getSessionId()
{
return static::getHandler()->getSessionId();
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. Use the Request SessionId instead.', __METHOD__));

return self::getSessionHandler()->getSessionId();
}

/**
* @return string
*
* @deprecated
*/
public static function getSessionName()
{
return static::getHandler()->getSessionName();
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. Use the Request SessionName instead.', __METHOD__));

return self::getSessionHandler()->getSessionName();
}

/**
* @return bool
*
* @deprecated
*/
public static function invalidate(): bool
{
return static::getHandler()->invalidate();
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. Use the Request invalidate instead.', __METHOD__));

return self::getSessionHandler()->invalidate();
}

/**
* @return bool
*
* @deprecated
*/
public static function regenerateId(): bool
{
return static::getHandler()->regenerateId();
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. Use the Request migrate instead.', __METHOD__));

return self::getSessionHandler()->regenerateId();
}

/**
* @param Request $request
* @param bool $checkRequestParams
*
* @return bool
*
* @deprecated
*/
public static function requestHasSessionId(Request $request, bool $checkRequestParams = false): bool
{
return static::getHandler()->requestHasSessionId($request, $checkRequestParams);
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. No alternative given, use Request Session instead.', __METHOD__));

return self::getSessionHandler()->requestHasSessionId($request, $checkRequestParams);
}

/**
* @param Request $request
* @param bool $checkRequestParams
*
* @return string
*
* @deprecated
*/
public static function getSessionIdFromRequest(Request $request, bool $checkRequestParams = false)
{
return static::getHandler()->getSessionIdFromRequest($request, $checkRequestParams);
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. Use the Request SessionId instead.', __METHOD__));

return self::getSessionHandler()->getSessionIdFromRequest($request, $checkRequestParams);
}

/**
Expand All @@ -114,10 +197,14 @@ public static function getSessionIdFromRequest(Request $request, bool $checkRequ
* @param string $namespace
*
* @return AttributeBagInterface|null
*
* @deprecated
*/
public static function get(string $namespace = 'pimcore_admin')
{
$bag = static::getHandler()->loadAttributeBag($namespace);
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. Use \Pimcore\Tool\Session::getSessionBag instead.', __METHOD__));

$bag = self::getSessionHandler()->loadAttributeBag($namespace);
if ($bag instanceof AttributeBagInterface) {
return $bag;
}
Expand All @@ -129,17 +216,25 @@ public static function get(string $namespace = 'pimcore_admin')
* @param string $namespace
*
* @return AttributeBagInterface
*
* @deprecated
*/
public static function getReadOnly(string $namespace = 'pimcore_admin'): AttributeBagInterface
{
return static::getHandler()->getReadOnlyAttributeBag($namespace);
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. No alternative given.', __METHOD__));

return self::getSessionHandler()->getReadOnlyAttributeBag($namespace);
}

/**
* Saves the session if it is the last admin session which was opene
* Saves the session if it is the last admin session which was open
*
* @deprecated
*/
public static function writeClose()
{
return static::getHandler()->writeClose();
trigger_deprecation('pimcore/pimcore', '10.6', sprintf('Usage of method %s is deprecated since version 10.6 and will be removed in Pimcore 11. No alternative given.', __METHOD__));

return self::getSessionHandler()->writeClose();
}
}

0 comments on commit 4d3f1e3

Please sign in to comment.