Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Session Bundle Laravel Package

bdupiol/session-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require theodo-evolution/session-bundle
    

    Add to config/bundles.php:

    return [
        // ...
        Theodo\Evolution\SessionBundle\TheodoEvolutionSessionBundle::class => ['all' => true],
    ];
    
  2. 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
    
  3. 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);
        }
    }
    

Implementation Patterns

Session Sharing Workflows

  1. Symfony 1.x Integration:

    • Use LegacySessionInterface to read/write legacy session data.
    • Example: Sync user roles between Symfony 1 and 2:
      $legacySession->set('user_roles', ['admin', 'editor']);
      $currentRoles = $legacySession->get('user_roles');
      
  2. CodeIgniter Integration:

    • Configure the session_path to point to CodeIgniter’s session storage (e.g., application/cache/sessions/).
    • Example: Migrate a CodeIgniter cart to Symfony:
      $cartItems = $legacySession->get('ci_cart');
      $this->session->set('sf_cart', $cartItems);
      
  3. Hybrid Session Handling:

    • Use dependency injection to switch between legacy and Symfony sessions dynamically:
      public function __construct(
          private LegacySessionInterface $legacySession,
          private SessionInterface $symfonySession
      ) {}
      

Common Use Cases

  • Authentication: Share login tokens between legacy and Symfony.
  • State Management: Preserve user preferences or workflow states during migration.
  • Analytics: Log legacy session events in Symfony for unified tracking.

Integration Tips

  • Middleware: Create middleware to auto-sync critical session data on request:
    public function handle(Request $request, Response $response, callable $next)
    {
        $legacySession->set('last_visited', time());
        return $next($request);
    }
    
  • Events: Listen to Symfony’s kernel.request event to trigger legacy session updates:
    $eventDispatcher->addListener(KernelEvents::REQUEST, function (RequestEvent $event) {
        $legacySession->touch(); // Refresh session expiry
    });
    

Gotchas and Tips

Pitfalls

  1. Session Path Permissions:

    • Ensure the session_path is writable by the PHP process. Use chmod -R 755 if needed.
    • Debugging: Check storage/logs/debug.log for Permission denied errors.
  2. Session Serialization:

    • Legacy sessions may use different serialization formats (e.g., PHP’s serialize() vs. JSON). The bundle assumes compatibility; test with your data.
    • Workaround: Manually deserialize legacy data if needed:
      $rawData = $legacySession->get('raw_key');
      $data = unserialize($rawData);
      
  3. Session Expiry:

    • Legacy sessions may have different expiry logic. Use legacySession->touch() to manually extend expiry if needed.
  4. Symfony 1.x Specifics:

    • If using Symfony 1.x, ensure the session_path points to the correct cache/ directory (default: /path/to/project/cache/).
    • The bundle does not handle Symfony 1.x’s sfSession object directly; use the LegacySessionInterface methods.

Debugging

  • Enable Debugging: Set debug: true in config/packages/theodo_evolution_session.yaml to log session operations:
    theodo_evolution_session:
        debug: true
    
  • Check Logs: Errors appear in var/log/dev.log (Symfony 2.8+) or app/logs/.

Extension Points

  1. 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
    
  2. 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
        }
    );
    

Configuration Quirks

  • Default Storage: If no legacy_session is configured, the bundle throws a RuntimeException. Always specify a storage driver.
  • Session ID Mismatch: Legacy and Symfony sessions may use different IDs. The bundle does not auto-sync IDs; handle this manually if needed:
    $legacySession->setId($this->session->getId());
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope