Immediately I want to temper your ardor towards the headline: I have long experienced a school age and know what I'm talking about. Therefore, let us be tolerant of each other and give me the opportunity to present my idea before you criticize it.
We all know well the existing popular engines for PHP. You can also mention almost anyone unknown, which are developed by amateurs. But all of them are united by one big “BUT” in terms of ideas, which in fact has always bothered me. Why no one uses CMS in the development of high-loaded projects? The fact is that each of them is designed in such a way as to hinder in every way the development of any non-specific functionality, not to mention some particular situations.
This idea came to me as long as I started programming. Since then, many years have passed, a lot of experience gained, practice. In general, there is something to compare. An almost perfect example for me is Django in Python. But for the end user it takes a lot of time to polish the interface, basic functions and other things. And I thought: would it not be better for me to write the core of the system, etc., under the strict guidance of the public, which would provide maximum constructive criticism in favor of my developments?
Basic programming patterns
The most common programming pattern, in my experience, is currently MVC and its modifications. Many times I tried to write, following the pattern, but the result always drove me to madness. It is not so easy to take and share everything on the Model-View-Controller. Of course, I could be wrong, and actually because you are reading this.
')
Let's take as an example simple work with API and synchronization with model data for example User. For the engine, the framework (as it is convenient for someone) - Symfony. I am sure that the people experienced in this matter have already understood how everything will start and how it will end.
I cannot call my alternative an ideal, but I like it very much. The essence of this is that any operations with system data, calculated data, data of other services are positioned as a
Service . The service is essentially a regular PHP package with classes and its own namespace. But who prevents us from putting the configuration file, the basic templates of the View part or the cached data there? After all, all these things belong to him, and should we clutter up the common folder for templates / configs?
- Only Service / Service will have access to the database.
- The service may contain classes, traits, configuration and cache files, basic templates.
- Access to the service will be carried out using a single object method from the controller area
- Service necessarily has its own namespace
This solution greatly simplifies the modulation of the entire system. When your controller does not have access to the database at all, you will need to edit, for example, the traits of the service in order to obtain the necessary data. But on the other hand, it will greatly help to organize the code correctly and not to interfere with one another.
If you think carefully, then this is the same MVC, only here the role of the model is fulfilled by our Service, which, as we see, is significantly different from the well-established stereotypical ORM models.
As a result, the front class of the User service can contain work with its local data, its own files on the server, work with the API, and so on. The unification of such a large area of ​​development makes it possible to very effectively implement the final result.
I would really like to know your opinion.