Slim 4: classes and configurations in middleware

I put middleware for authentication in the middleware.php file (app->add(new MyAuth()). In MyAuth class, how do I:

  1. call the Logger class and the PDO class configured in the dependencies.php file?
  2. retrieve the key pair (used to decrypt data) that are defined in the settings.php file?

Am I doing this the right way?

Try something like this:

This is untested code though so you may have to tweak it to your needs.

1 Like

Use DI, of course … thanks for the help!