Loading Modules Dynamically in Zend Framework 2

前端 未结 2 721

I have asked this question yesterday as well, but this one includes code.

Issue

My application have multiple modules and 2 types of user accounts, Some mod

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 10:28

    What you're asking can be done, but that doesn't mean you should.

    Suggesting an appropriate solution without knowing the complexity of the application you're building is difficult.

    Using guards will certainly help decouple your code, however using it alone doesn't address scalability and maintainability, if that's a concern?

    I'd suggest using stateless token-based authentication. Instead of maintaining the validation logic in every application, write the validation logic at one common place so that every request can make use of that logic irrespective of application. Choosing a reverse proxy server (Nginx) to maintain the validation logic (with the help of Lua) gives you the flexibility to develop your application in any language.

    More to the point, validating the credentials at the load balancer level essentially eliminates the need for the session state, you can have many separate servers, running on multiple platforms and domains, reusing the same token for authenticating the user.

    Identifying the user, account type and loading different modules then becomes a trivial task. By simply passing the token information via an environment variable, it can be read within your config/application.config.php file, without needing to access the database, cache or other services beforehand.

提交回复
热议问题