How to get zend-expressive-session running with ext-session?

So, I thought I have correctly registered zend-expressive-session and zend-expressive-session-ext in my application but I can’t seem to get it running properly.

I’m getting an InvalidMiddlewareException with this message “Lazy-loaded middleware “Zend\Expressive\Session\SessionMiddleware” is neither invokable nor implements Interop\Http\ServerMiddleware\MiddlewareInterface”.

I began with the skeleton application and included both packages via Composer. During the installation I chose to aggregate their configuration. I can narrow it down to the class “Zend\Expressive\Session\SessionMiddleware” that is being considered not callable.

These are the package versions that Composer loaded starting from the skeleton application. Up until adding the session packages it worked.

zendframework/zend-authentication 2.6.0
zendframework/zend-code 3.3.0
zendframework/zend-component-installer 1.1.1
zendframework/zend-config-aggregator 1.1.1
zendframework/zend-diactoros 1.8.2
zendframework/zend-escaper 2.6.0
zendframework/zend-eventmanager 3.2.1
zendframework/zend-expressive 2.2.1
zendframework/zend-expressive-fastroute 2.2.1
zendframework/zend-expressive-helpers 4.2.0
zendframework/zend-expressive-platesrenderer 1.4.0
zendframework/zend-expressive-router 2.4.1
zendframework/zend-expressive-session 1.0.0
zendframework/zend-expressive-session-ext 1.1.1
zendframework/zend-expressive-template 1.0.4
zendframework/zend-expressive-tooling 0.4.7
zendframework/zend-servicemanager 3.3.2
zendframework/zend-session 2.8.5
zendframework/zend-stdlib 3.2.0
zendframework/zend-stratigility 2.2.2
zfcampus/zf-composer-autoloading 2.1.0
zfcampus/zf-development-mode 3.2.0

You are mixing up a few versions here. zendframework/zend-expressive-session 1.0.0 has support for PSR-15 Psr\Http\Server\MiddlewareInterface. It doesn’t support Interop\Http\ServerMiddleware\MiddlewareInterface anymore. I think you need zendframework/zend-expressive-session 0.1 for that.

I wrote a blog post about utilizing zend-expressive-session-ext at https://samsonasik.wordpress.com/2018/01/12/create-login-functionality-in-expressive-3/

When did you create the new project and what command did you use? As of march 15, it should install zend-expressive 3.

To all of you: Thanks for dedicating your time to this issue! You are amazing!

@xtreamwayz I was thinking into this direction. I just recently started the project from scratch but I somehow ended up not using the latest Expressive version. As an Expressive noob I just thought that I fetched the latest stable using the Skeleton application. If I remember correctly I was following the instructions given on the Expressive docs startpage, i.e. this command:

https://docs.zendframework.com/zend-expressive/

This yields this output:

netbrothers-tr@themachine:~/projects$ composer create-project zendframework/zend-expressive-skeleton expressive
Installing zendframework/zend-expressive-skeleton (2.2.0)
  - Installing zendframework/zend-expressive-skeleton (2.2.0): Loading from cache
[...]
  - Installing zendframework/zend-expressive (2.2.1): Loading from cache
Created project in expressive
> ExpressiveInstaller\OptionalPackages::install
Setting up optional packages
Setup data and cache dir
Removing installer development dependencies

  What type of installation would you like?
  [1] Minimal (no default middleware, templates, or assets; configuration only)
  [2] Flat (flat source code structure; default selection)
  [3] Modular (modular source code structure; recommended)
  Make your selection (2): ^C

So, without giving any additional arguments, this instruction from the original documentation leads to an older Expressive version.

@samsonasik Thank you for the link to your blog post!

My conclusion is, that I will try to ugprade the whole project to Expressive 3 and then write my findings here for others who will run into the same blind alley.

There is something wrong with your composer installation.

~\projects\sandbox> composer create-project zendframework/zend-expressive-skeleton test
Installing zendframework/zend-expressive-skeleton (3.1.0)
  - Installing zendframework/zend-expressive-skeleton (3.1.0): Loading from cache

Be sure to work with the latest version of composer by running composer self-update.
Try clearing Composer’s cache by running composer clear-cache.

@xtreamwayz I did, what you proposed. I even downloaded and used the very latest composer binary (version 1.6.5). I used all the defaults (flat, Zend ServiceManager, FastRoute, no template engine, Whoops) proposed in the installer script and got versions zend-expressive-skeleton (2.2.0) and zendframework/zend-expressive (2.2.1). I tried several non-defaults in the hope this would change anything, but it didn’t. Is there any else, I can do? Are you using the standard packagist repository or an enterprise version?

@netbrothers-tr What PHP version are you using? Expressive 3 requires PHP version 7.1.

1 Like

That has been the problem! I’m on Ubuntu 16.04 with PHP 7.0.8. Time to upgrade! Thanks @xtreamwayz!

1 Like