How To Create A Framework-Agnostic Application In PHP?
Building a framework agnostic application is possible no matter what toolset you use. PHP developers have been talking a lot lately about Domain-Driven Design hexagonal architecture and similar patterns. Their main goal is to separate the business logic from the framework, storage and third-party related code.
Framework-agnostic application in PHP
Why separate application business logic from other elements?
Domain code scattered across framework-related classes can be easily broken during migration. Tests won’t help you because you’ll have to rewrite them all and you might break them too. Any potential issues will be related to the new tools without accidentally changing the app’s behavior. Unless the business logic models are separated from the repository libraries, this is usually a very time-consuming task. Keeping everything separate will even allow you to use two different storage implementations and check which one suits your needs better.
Runner application
It is a very simple web application that helps a runner manage the run of the competition they are participating in. We have a run that has its name, start date, length and type. We also have a runner who can participate in a run and if they complete it, their result will be saved. Instead, we need to focus on business requirements, their rules and goals. Other things are not so important at this moment.
Register Runner to Run with the following rules
⦁ if the run has already started, the runner cannot be registered.
⦁ if a runner is already registered for a run, it cannot be done a second time.
⦁ Save a runner’s result in a run.
⦁ if the runner did not participate in the run, his result cannot be saved.
⦁ if the result has expired, it cannot be saved.
⦁ if the runner has reached the time limit for the run, his result cannot be saved.
⦁ if the result for the runner is already saved, it cannot be done a second time.
Conclusion
PHP frameworks can be a time-saving choice for many projects, knowing how to build a framework-agnostic application equips you with a valuable skill set and the ability to approach unique challenges in the world of web development.