Weave 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

Route Based Session Configuration Bundle Laravel Package

phpmentors/route-based-session-configuration-bundle

Configures PHP session settings on a per-route basis in Symfony applications. Define session options per route to control cookie, storage, and lifetime behavior without global configuration.

View on GitHub
Deep Wiki
Context7

Getting Started

  • First, check the framework. RouteBasedSessionConfigurationBundle is a Symfony bundle (v1.1.0 targets Symfony >=2.8, 3.x, and now 4.x). It has no Laravel service provider, no facade, no config/session.php integration, and no auto-discovery. There is nothing to composer require and boot in a Laravel app.
  • What to read first: the bundle's DependencyInjection/Configuration.php (to see the config tree), the route-to-session-options mapping node in the bundle config, and the event listener/subscriber that mutates session options per request. That listener is the piece you will be re-implementing in Laravel.
  • First useful use case (Laravel translation): you want different session behaviour per route group — e.g. long-lived remember sessions on marketing pages vs. short-lifetime sessions on checkout/admin, or a separate cookie name per tenant/subdomain. That is the real-world need this package solves on Symfony.
  • Fastest path for a Laravel dev: don't install it. Read the listener (~30–60 lines), then implement the same idea as a middleware registered before StartSession in the web group. Budget under an hour.

Implementation Patterns

If you are actually in a Symfony app (v1.1.0):

  • Register the bundle in app/AppKernel.php (Symfony 2.8/3.x) or config/bundles.php (Symfony 4).
  • Declare route-pattern → session option maps in config.yml / config/packages/*.yaml; the listener applies the matching entry before the session starts.
  • Ordering is significant — treat the mapping as an ordered rule list, most specific first, with an explicit default/fallback entry.

The Laravel equivalent (recommended pattern):

// app/Http/Middleware/RouteSessionConfig.php
public function handle($request, Closure $next)
{
    $rules = config('session-routes'); // pattern => [cookie, lifetime, driver, ...]
    foreach ($rules as $pattern => $options) {
        if ($request->is($pattern)) {
            config(array_merge(config('session'), $options));
            break;
        }
    }
    return $next($request);
}
  • Register it in Kernel::$middlewareGroups['web'] above \Illuminate\Session\Middleware\StartSession::class. Middleware order in that array is execution order, so pushing it after StartSession silently does nothing.
  • For genuinely isolated sessions, prefer separate route groups with a distinct cookie name over mutating session config mid-request; session identity is derived from the cookie name.
  • Test with $this->withSession([...])->get(...) plus assertions on Set-Cookie headers, and add one negative test proving a non-matching route keeps default settings.

Gotchas and Tips

  • Hard blocker for Laravel: no laravel/framework support, no service provider, no published config. It cannot be the dependency; use it as a design reference only.
  • v1.1.0 constraint bump: the package now requires Symfony 2.8.0 | 3.0.0 | 4.0.0 or greater. Projects on Symfony ≤2.7 lost support — check composer.lock before upgrading a legacy app.
  • Symfony 4 registration is manual unless a Flex recipe exists: add the bundle to config/bundles.php; Symfony 3/2.8 use AppKernel. Mixing these up yields a "bundle not registered" error far from the root cause.
  • Config cache: in Symfony, changes to the route/session mapping require bin/console cache:clear; if the listener isn't cache-warmable you'll see stale behaviour in prod but not dev.
  • Session start ordering is the #1 pitfall in both frameworks. Once the session has started or the session cookie has been queued, changing the cookie name or driver has no effect for that request. Always configure before StartSession.
  • First-match-wins vs last-match-wins is rarely documented in small bundles — read the loop, don't assume, and add a wildcard fallback so an unmatched route is deterministic.
  • Maintenance risk: two merged PRs and a single maintainer (@iteman). Pin the version, and since you're only borrowing the concept for Laravel, vendor the idea into your own middleware rather than depending on it.
  • Extension point worth copying: keeping the mapping in configuration (not in PHP conditionals) lets ops change session policy per route without a deploy of code paths, which is the actual value of the package regardless of framework.
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.
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle