Search by

drago-ex / sessions

accgit

Helper class for accessing Nette session and session sections outside presenters.

Package info

github.com/drago-ex/sessions

pkg:composer/drago-ex/sessions

Statistics

Installs: 442

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.3 2026-10-15 14:57 UTC

This package is auto-updated.

Last update: 2026-10-19 06:50:57 UTC


README

A helper package for managing sessions outside the presenter in Nette Framework.

License: MIT PHP version Tests Coding Style

Requirements

  • PHP >= 8.3, < 9
  • Nette Framework
  • Composer

Installation

composer require drago-ex/sessions

Service Registration

Register an ExtraSession service for the session section you need in your neon configuration:

services:
	- Drago\Http\ExtraSession(section: cart)

The Nette\Http\Session argument is autowired. When you need several sections, register named services and disable autowiring, so the right one is chosen explicitly:

services:
	cartSession:
		create: Drago\Http\ExtraSession(section: cart)
		autowired: false

	wishlistSession:
		create: Drago\Http\ExtraSession(section: wishlist)
		autowired: false

	- App\Model\CartService(@cartSession)

Examples

use Drago\Http\ExtraSession;

final class CartService
{
	public function __construct(
		private readonly ExtraSession $session,
	) {
	}


	public function add(int $productId): void
	{
		$section = $this->session->getSessionSection();
		$items = $section->get(items) ?? [];
		$items[] = $productId;
		$section->set(items, $items);
	}
}

Features

  • Provides access to Nette sessions and session sections outside the presenter.
  • Ideal for managing session data in services or components within a Nette application.

Knowledge