Installation:
composer require theodo-evolution/session-bundle
Add to config/bundles.php:
return [
// ...
Theodo\Evolution\SessionBundle\TheodoEvolutionSessionBundle::class => ['all' => true],
];
Configuration:
Edit config/packages/theodo_evolution_session.yaml (auto-generated) to define legacy session storage (e.g., symfony1, codeigniter).
Example:
theodo_evolution_session:
legacy_session: symfony1
symfony1:
session_path: /path/to/symfony1/sessions
codeigniter:
session_path: /path/to/codeigniter/sessions
First Use Case: Access legacy session data in a Symfony controller:
use Theodo\Evolution\SessionBundle\Session\LegacySessionInterface;
class MyController extends AbstractController
{
public function index(LegacySessionInterface $legacySession)
{
$legacyData = $legacySession->get('legacy_key');
$this->session->set('symfony_key', $legacyData);
return new Response('Legacy session data: ' . $legacyData);
}
}
Symfony 1.x Integration:
LegacySessionInterface to read/write legacy session data.$legacySession->set('user_roles', ['admin', 'editor']);
$currentRoles = $legacySession->get('user_roles');
CodeIgniter Integration:
session_path to point to CodeIgniter’s session storage (e.g., application/cache/sessions/).$cartItems = $legacySession->get('ci_cart');
$this->session->set('sf_cart', $cartItems);
Hybrid Session Handling:
public function __construct(
private LegacySessionInterface $legacySession,
private SessionInterface $symfonySession
) {}
public function handle(Request $request, Response $response, callable $next)
{
$legacySession->set('last_visited', time());
return $next($request);
}
kernel.request event to trigger legacy session updates:
$eventDispatcher->addListener(KernelEvents::REQUEST, function (RequestEvent $event) {
$legacySession->touch(); // Refresh session expiry
});
Session Path Permissions:
session_path is writable by the PHP process. Use chmod -R 755 if needed.storage/logs/debug.log for Permission denied errors.Session Serialization:
serialize() vs. JSON). The bundle assumes compatibility; test with your data.$rawData = $legacySession->get('raw_key');
$data = unserialize($rawData);
Session Expiry:
legacySession->touch() to manually extend expiry if needed.Symfony 1.x Specifics:
session_path points to the correct cache/ directory (default: /path/to/project/cache/).sfSession object directly; use the LegacySessionInterface methods.debug: true in config/packages/theodo_evolution_session.yaml to log session operations:
theodo_evolution_session:
debug: true
var/log/dev.log (Symfony 2.8+) or app/logs/.Custom Storage Handlers:
Extend Theodo\Evolution\SessionBundle\Session\Storage\LegacySessionStorage to support new legacy systems (e.g., WordPress, custom PHP apps).
Example:
class CustomSessionStorage extends LegacySessionStorage
{
protected function loadSessionData()
{
// Custom logic to read from your storage
return file_get_contents('/custom/path/session_' . session_id());
}
}
Register in services.yaml:
services:
Theodo\Evolution\SessionBundle\Session\LegacySessionInterface:
class: App\Custom\CustomSessionStorage
Session Data Transformers: Use Symfony’s event system to transform legacy data before use:
$eventDispatcher->addListener(
'legacy_session.load',
function ($data) {
return json_decode($data, true); // Auto-decode JSON
}
);
legacy_session is configured, the bundle throws a RuntimeException. Always specify a storage driver.$legacySession->setId($this->session->getId());
How can I help you explore Laravel packages today?