Thin frame structure outside Slim

My Slim project is organized as follows:

- app
-- Acme
--- Auth
---- Auth.php (handles authentication)
-- config
--- development.php
--- production.php
-- routes
-- views
- public
- vendor

I configure my application in the usual way.

$app = new \Slim\Slim([
    'view' => new \Slim\Views\Twig(),
    'mode' => 'development'
]);

And injecting dependencies like this.

$app->auth = function($app) {
    return new Codecourse\Auth\Auth($app->user);
};

What is the best way to let my auth class see my configuration? I was originally going to pass it as a dependency, but access to the Slim configuration keys is like $app->config('key')that, so I would have to go into $appthat, which would be bad.

I know that my authentication can be used as middleware, but I would like to have access to configurations all over the world.

Perhaps it would be better to use a package like noodlehaus / config ( https://github.com/noodlehaus/config ) to handle the configuration outside Slim?

+4
1

Slim\Slim Slim\Slim::getInstance() ( , Auth), config('key') (.. Slim get/ ). .

, , (, noodlehaus/config) Slim... , Slim Auth Slim.

+1

Source: https://habr.com/ru/post/1570727/


All Articles