{"id":36983030,"url":"https://github.com/dwendrich/expressive-session-middleware","last_synced_at":"2026-01-13T22:54:58.574Z","repository":{"id":56973572,"uuid":"89352737","full_name":"dwendrich/expressive-session-middleware","owner":"dwendrich","description":"Session handling middleware based on zend-session for use in zend expressive applications.","archived":false,"fork":false,"pushed_at":"2018-06-21T09:39:07.000Z","size":18,"stargazers_count":3,"open_issues_count":0,"forks_count":4,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-15T00:51:59.363Z","etag":null,"topics":["expressive","middleware","php","session","zend","zend-session"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwendrich.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-25T11:26:46.000Z","updated_at":"2021-05-01T22:11:51.000Z","dependencies_parsed_at":"2022-08-21T07:10:14.362Z","dependency_job_id":null,"html_url":"https://github.com/dwendrich/expressive-session-middleware","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/dwendrich/expressive-session-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwendrich%2Fexpressive-session-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwendrich%2Fexpressive-session-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwendrich%2Fexpressive-session-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwendrich%2Fexpressive-session-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwendrich","download_url":"https://codeload.github.com/dwendrich/expressive-session-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwendrich%2Fexpressive-session-middleware/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28400681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expressive","middleware","php","session","zend","zend-session"],"created_at":"2026-01-13T22:54:57.851Z","updated_at":"2026-01-13T22:54:58.568Z","avatar_url":"https://github.com/dwendrich.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# expressive-session-middleware\nSession handling middleware based on zend-session for use in zend expressive 3 applications.\n\n[![Build Status](https://travis-ci.org/dwendrich/expressive-session-middleware.svg?branch=master)](https://travis-ci.org/dwendrich/expressive-session-middleware)\n[![Coverage Status](https://img.shields.io/codecov/c/github/dwendrich/expressive-session-middleware.svg?style=flat)](https://codecov.io/gh/dwendrich/expressive-session-middleware)\n[![Latest Stable Version](http://img.shields.io/packagist/v/dwendrich/expressive-session-middleware.svg?style=flat)](https://packagist.org/packages/dwendrich/expressive-session-middleware)\n\n## PSR-15 Support\nThis version supports [PSR-15](https://www.php-fig.org/psr/psr-15) instead of http-interop/http-middleware interfaces,\nas currently implemented by zend expressive 3. For use with older versions of zend expressive, please refer to version\n0.1.9.\n\n## Requirements\n* PHP 7.1 or above\n* [zendframework/zend-session](https://docs.zendframework.com/zend-session/)\n\n## Installation\nInstall the latest version with composer. For information on how to get composer or how to use it, please refer to [getcomposer.org](http://getcomposer.org).\n```sh\n$ composer require dwendrich/expressive-session-middleware\n```\n\nIf during installation you are prompted to inject `Zend\\Session\\ConfigProvider` into your configuration, you can simply\nignore and continue without it. All relevant configuration is part of `SessionMiddleware\\ConfigProvider`.\n\nAs part of a zend-expressive application add `SessionMiddleware\\ConfigProvider::class` to `config/config.php`:\n```php\n$aggregator = new ConfigAggregator([\n \n    // enable SessionMiddleware\n    SessionMiddleware\\ConfigProvider::class,\n    \n    // ... other stuff goes here \n \n    // Load application config in a pre-defined order in such a way that local settings\n    // overwrite global settings. (Loaded as first to last):\n    //   - `global.php`\n    //   - `*.global.php`\n    //   - `local.php`\n    //   - `*.local.php`\n    new PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'),\n \n    // Load development config if it exists\n    new PhpFileProvider('config/development.config.php'),\n], $cacheConfig['config_cache_path']);\n```\n\nThere are two ways of integrating the session middleware into your application.\n\n#### 1. Add the middleware to the programmatic middlewarepipeline\nYou can add the middleware to the file `config/pipeline.php`:\n```php\n// Register session handling middleware\n$app-\u003epipe(SessionMiddleware::class);\n \n// Register the routing middleware in the middleware pipeline\n$app-\u003epipe(\\Zend\\Expressive\\Router\\Middleware\\RouteMiddleware::class);\n$app-\u003epipe(ImplicitHeadMiddleware::class);\n$app-\u003epipe(ImplicitOptionsMiddleware::class);\n$app-\u003epipe(UrlHelperMiddleware::class);\n```\nDepending on which middleware should get access to the session, you should prepend `SessionMiddleware` in the pipeline.\nCommonly before registering the routing middleware is a good way to go.\n\nThis way the middleware is invoked on every request to your application. Since session handling may produce some\noverhead, which isn't always needed, there is an alternative:\n\n#### 2. Add the middleware to a specific route\nAdd a route definition to either `config/routes.php` or a `RouteDelegator` as part of your application:\n```php\n$app-\u003eroute(\n    '/path-to-my-action',\n    [\n        SessionMiddleware::class,\n        MyApp\\Action\\MyAction::class\n    ],\n    ['GET'],\n    'path-to-my-action'\n);\n```\nThis way session handling is bound to a specific path in your application where it may be needed.\n\nFor further information on programmatic pipelines and routing in zend expressive please refer to the\n[documentation](https://docs.zendframework.com/zend-expressive/cookbook/autowiring-routes-and-pipelines/).\n\n## Basic usage\nOnce the session middleware is invoked it will start the session and adds the session manager object as attribute to the\ncurrent request. Any middleware which processes this request subsequently, can detect that session handling is started\nby testing against the request attribute:\n```php\n/**\n * Process an incoming server request and return a response, optionally delegating\n * to the next middleware component to create the response.\n *\n * @param ServerRequestInterface $request\n * @param DelegateInterface $delegate\n *\n * @return ResponseInterface\n */\npublic function process(ServerRequestInterface $request, DelegateInterface $delegate) : ResponseInterface\n{\n    $sessionManager = $request-\u003egetAttribute(SessionMiddleware::SESSION_ATTRIBUTE, false);\n    \n    if ($sessionManager) {\n        // sessionManager is present and can be used\n    }\n    \n    // further request processing goes here...\n}\n```\n\n### Storing and retrieving session data\nZend session component uses `Container` objects to access and store session data. For information on this concept please\nrefer to the [documentation](https://docs.zendframework.com/zend-session/container/).\n\nFollowing is a simple example on how to use a `Container`:\n```php\nuse Zend\\Session\\Container;\n \n$container = Container('my_namespace');\n \n// save 'foo' into the `item` key\n$container-\u003eitem = 'foo';\n```\n\nIn another part of the application you may want to access this data:\n```php\nuse Zend\\Session\\Container;\n \n$container = Container('my_namespace');\n \n// read the content from the `item` key\n$foo = $container-\u003eitem;\n```\n\n## Configuration\nThe session can be configured by adding a `session.global.php` to your `config/autoload` path, for example. You can\nuse `session.global.php.dist` file (see [session.global.php.dist](config/session.global.php.dist)) as template.\n```php\nreturn [\n    'session' =\u003e [\n        'config' =\u003e [\n            'options' =\u003e [\n                'name' =\u003e 'my_special_session_name',\n                'use_cookies' =\u003e true,\n                'cookie_secure' =\u003e false,\n            ],\n        ],\n    ],\n];\n```\nFor possible configuration options please refer to the documentation of\n[zend-session](https://docs.zendframework.com/zend-session/config/#standard-config) component.\n\nYou can override the session configuration instance with any instance or class implementing\n`Zend\\Session\\Config\\ConfigInterface`. Simply specify it in session configuration:\n```php\nreturn [\n    'session' =\u003e [\n        'class' =\u003e Zend\\Session\\Config\\StandardConfig::class,\n        'options' =\u003e [\n            'name' =\u003e 'my_app',\n        ],\n    ],\n];\n```\n\nFor using a certain session storage adapter you can override it in the config, as well. Therefore it has to implement\n`Zend\\Session\\Storage\\StorageInterface`:\n```php\nreturn [\n    'session' =\u003e [\n        'storage' =\u003e new MyApp\\Session\\StorageAdapter::class,\n    ],\n];\n```\n\nTo add validators to the session manager, you cann define them in the config, too, for example:\n```php\nreturn [\n    'session' =\u003e [\n        'validators' =\u003e [\n            Session\\Validator\\RemoteAddr::class,\n            Session\\Validator\\HttpUserAgent::class,\n        ],\n    ],\n];\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwendrich%2Fexpressive-session-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwendrich%2Fexpressive-session-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwendrich%2Fexpressive-session-middleware/lists"}