Not Wordpress alone
The CMS market has long been a place where Wordpress, Joomla, Drupal are the top three. These wonderful times are already gradually passing, although WP, slowing down in the dynamics of the emergence of new sites, is still leading. No wonder: an active community, a huge number of plugins. But, this article will not at all be devoted to the "rising stars" of the content management systems market (hello, solutions based on Laravel). Rather, even the object of our attention will be "black matter", which is somewhat off to the side. Namely - drum roll ...
Static sites
Who needs statics in 2k20?
Rational question! It would seem that the days of the telephone Internet and Windows95 have already passed, but the demand for static generation of html code is starting to gain momentum again. And the good corporation is to blame, of course. Google PageSpeed ​​is the very great and mighty Urfi ... In general, it is this web page performance meter that has become both the engine of the progress of the world Internet and the headache of all web developers, and even more so for freelancers. The measurement results of this tool are based on Google standards, and it is far known that these are the basis for ranking. And objectively, loading a page for more than three seconds automatically increases the number of bounces. Thus, statics becomes one of the alternative solutions to replace or in addition to the dynamic assembly of pages by the power of any CMS, framework or self-written options.
,
On duty, I am engaged in servicing many projects, among which there are parsers, but also solutions in the field of e-commerce. I'm not complaining about life, but a problem arose not from the category “2nd grade, primary school”. I, as a developer, and a manager (and managing your little business, as you know, requires skills from this area too), as it is in Polish “dostałem się do martwego kąta” (got into a remote corner, in a word). The condition is the following: you need to write a solution within a few days that should be easy to install and serve any number of static pages. Moreover, the administrator should be able to quickly remove and add such a solution to any project via FTP / SFTP connection, or even if he does not have access to FTP / SFTP. On the other hand, the condition was that the minimum version is PHP 5.6 and should be supported pretty well like every newer version.
The administrator should
- delete / add / change pages using the admin panel;
- globally and quickly search in the content of pages (taking into account different encodings, languages;
- search by file names;
- delete / insert / change the necessary elements on all pages with one click from the admin panel;
- the solution should be easy to install and uninstall.
The security should not allow using SQL injection or any other attempts to interfere with the work.
An additional obligation would be the ability to use the admin panel and all of its functions via the API. Roughly speaking, if there are such admin panels on 50+ domains, there should be access to them remotely by being able to make requests.
Czech Republic, evening, summer, coffee
Extremely calm evenings in the Giant Mountains only contribute to laziness. But, as the old proverb says, who does not work ...
Thus, having collected my thoughts and perked up my spirit and decisiveness, I began to design. The thing is very clear that the creation of a procedural solution cannot be something as successful as possible in this case. It is no secret that there is a prospect of supporting the system in the future, but at the same time you don't want to change everything too much.
And yes, damn it, I decided to transfer the already established approach in most frameworks - OOP and MVC concept to one file.
From the point of view of performance, proceduralism might be the best option, but:
- let's not forget about the aspect of growing client needs and the parallel need to add new capabilities to the interfaces of our web application;
- — , , ;
- — , “ ” , - -, -.
It was decided to abandon the bases for the time being due to the lack of any need, therefore the term “model” in everything that is above is an unrealized concept in my architecture. The lack of implementation here did a good job, because SQL injection is no longer possible in principle.
Structuring
Proceeding from the fact that we have one file and there is a main rule - only one file should be added and after that you can immediately work and maintain the directory to which you have added it, it is clear that even classes will not save you from "devil's leg".
What's the solution?
Intuitively: we split the file into structural parts of the view: the base system classes are at the very top, the controllers are lower, the views are even lower, but the entire ballet is closed by routes. Each part received a header from the comments with an explanation, so as not to forget after a while that here:
/*
* This is the part for routing
*Additional information...
*/
Functional naming - class methods were named according to camelCase practice and correspond to a functional role, for example “checkAdminCredentials” is a more than understandable formulation for a method.
An attempt to describe everything that is possible - I will not say that I corresponded to this intention until the very end of development, in the end, I maneuvered between speed and readability of the code, but I managed to accompany the key decisions with comments like // to get static html.
How is routing done?
The need for a more or less clear separation of interfaces was immediately accepted by me as a key need. This component, if not properly implemented, can become the “spike” of the application due to the confusion over which route which controller is calling.
Based on the problem mentioned above, I made the class for routing rather primitive, but functional. Routing works using GET requests - of course, not entirely aesthetically pleasing, but the immediate need for fast implementation is 100% solves. The router has become the only entry point for a web application (i.e. for the admin panel), which, in my opinion, is an ideal solution for ease of development. In this class, the front-end and back-end of the web application are assembled and the generated HTML is output by return.
Question: did I write the bike?
I am inclined to suspect that similar solutions have already been written in the past, but as of July 2020, neither English, nor Polish, nor Czech, nor Russian with Ukrainian helped me find something worthwhile and applicable to my case. That is why the creator “turned on” in me, and from the bottom of my heart I designed the solution of urgent business problems. After all, if there is a problem, it must be solved as quickly and economically as possible, and besides, the quality must not be forgotten.
A clear example of performance
One very famous CMS, whose name is not usually called:
My solution:
Obviously, the speed of getting the first byte is slightly higher, like all other indicators related to the download speed, I will not even demonstrate the number of requests to the front-end in classic CMS and in this mini solution.
Will there be a sequel?
Now the system is mostly written and has seen several updates. In the near future I plan to prepare documentation in one form or another, but to release this solution on the open voyage, although I must say that he solves internal problems every day perfectly. There are some more interesting and entertaining moments from the section of file search and content search in html files, which were implemented bypassing PHP capabilities, which made the execution of these requests much faster. I promise to write about these topics in the near future.