Answer the question
In order to leave comments, you need to log in
Should I write my own php framework in order to improve my OOP knowledge and learn the MVC pattern?
In general, everything is said in the title of the post :)
What is the reason for the question?
Since childhood, I have been interested in programming (or rather, at first it was a simple HTML page with photos with bananas, pictures right in the text that knocked down the whole format, etc. :)). Now I am studying HTML, CSS, JS (and with it jQuery), PHP (and many other things in general, but I only listed the technologies related to the question). This question is about PHP. I believe that I know him at some level - just above the plinth. Of course, this is a relative indicator, but at least now, reading questions on stackoverflow.com on these topics, some of them make me smile (and if the topic of the question is a misunderstanding of how to compare 2 variable values and signed in CodeIgniter or Zend Framework, then rzhach), and not my questions make someone smile.
There are several projects created by me (or rather, a series of sites with similar topics, similar target audience) - these are not huge portals, but simple sites with low traffic (again, a very target audience), but they fulfill their task. The websites are built using pure PHP. The engine was written from scratch (not a framework, not a CMS) by me.
Now I have to support these projects and I often come across the fact that everything is somehow not very convenient. The point is that all processing, SQL queries, screen outputs, logic are all in one heap. I would like to share it somehow. Here we come to the point.
Frameworks were created just for this - in order to make life easier for the programmer (built-in functions, modules, framework plugins) + in order to separate screen output from logic and from working with the database. Correctly? Correctly.
I believe that in order to understand something, you need to do it yourself, and then also teach someone what you yourself understood. I'm thinking about creating something like this myself (no, no one is going to argue with Zend or Yii, God forbid): first, to learn the MVC approach; secondly, to expand knowledge in the field of OOP; Thirdly, get some experience. Create such a framework and, for example, write a portfolio on it (after all, it would be time already).
So the question is: is it worth creating your own bike or is it "just" "stupid" to take some ready-made solution and deal with it?
I want to hear your opinion and, maybe, your furious stories from childhood with HTML pages :)
PS: I hope you did not fall asleep while reading it :)
PPS: I tried to present the question not as "purely holy"
Answer the question
In order to leave comments, you need to log in
Reading your question, I remembered myself 5 years ago :) At that time, my background consisted of a dozen sites on various CMS and one startup, which, of course, did not take off. By that time, I had been hatching for a long time a plan for the rehabilitation of one frozen project (sports portal), which I had developed with my comrades back in my student years. Initially, there was no task to write your own engine, but ... it all started with the development of a template engine with a syntax a la CMS MODx. I read a lot about the fact that this implementation stands out from the background of other competitors, in fact being the visiting card of the latter. In fact, it turned out that this is just a syntactic abstraction over Smarty, with all the consequences in terms of performance. For example, my implementation has alternative native php template support
for those who can't stand syntactic abstractions (Smarty, Twing, Fenom and others.) because of their low performance and other religious reasons.
As time went on, the code base grew. From Singleton pattern to DI (Dependency Injection), to Service Locator. A lot of things have been cut out for the sake of existing solutions. Over the past 2 years, with the help of Composer, there have been many times more ready-made solutions, and several for the implementation of a specific task. For example, from the latter, its own file manager (manipulation with the file system) was replaced with the Flysystem library , because the latter, among other things, can "run" to the clouds. Cool ;) The only thing in my implementation was the ability to search for a regexp pattern, I had to write an abstraction.
Here is an anti-example. A fairly popular data validation library is Respect Validation . It was required to implement the internationalization of messages, it was not possible to display the hierarchy of errors thrown during validation in one large array, and I also wanted to return, for example, only the first error (first) or the last (last). I had to fork, because it is simply impossible to abstract.
If you still decide to write your own framework, then rely on existing solutions. Choose for yourself one or two popular frameworks and study how this or that functionality is implemented in them, at least visually, thanks to the documentation in bulk. Start with the MVC model. Look at how actions are implemented, namely access to them, filtering at the entrance and exit in the action. For example, I am not a supporter of the implementation of pseudo-annotations, as in Symfony, because there is no support for native annotations in PHP yet, and everything else is a pitiful semblance through slow Reflections, even if everything is cached. So the author of the AOP paradigm for PHP understands all this, but still continues to develop his Go project! . The implementation is certainly interesting, but I will get by with the event model (Observer or PubSub).
Take a look at how routing works, because it is fundamental to the implementation of SOAP and REST. For example, my solution was influenced by Lavarel Routing regarding the use of groups. Nowadays, due to the prevalence of mobile platforms, REST is increasingly used not only based on url, but also based on custom headers (X-<pragma name>).
Pay attention to how errors/exceptions are handled. For example, Yii has long been criticized for the fact that there is no way to correctly identify this or that exception. It is better for each individual task (for example, FileManager) to have its own Exception class, which is inherited from the base one:
class Exception extends BaseException
{
const FILE_EXISTS = 'File exists: {path}';
public function __construct(
$level = self::ERROR,
$msg = null,
array $dataReplace = null,
\Exception $handler = null
) {
return parent::__construct($level, $msg, $dataReplace, $handler);
}
}
you, apparently, while writing maolo thought.
1. If you set a goal to make money on this, then this is a rather worthless means of earning money: it is unlikely that you will be able to create a "masterpiece", if someone dares to use it, who will support it? For the end client, who needs all this to make money, there is absolutely no need to be interested in picking the code or looking for the reason for the hack. He will try to find specialists and products in proportion to the amount he is willing to pay. Therefore, then it’s better to strain your efforts towards a specific product that other people are competitively pushing. Or most competitively push. But sitting on two chairs is usually not enough seat.
2. If all the same, in order to "understand how it still spins," then of course a good solution. But it would be much more profitable to poke around on some kind of oDEsk for money (albeit not big ones).
3. In one language (although php is a scripting language) it is not possible to "expand OOP knowledge". You need at least a couple more, to dig a torus. To understand the advantages and disadvantages of designs, differences and functionality.
It’s not worth it, it’s better to take a few popular frameworks and pick them up properly
I had the same thoughts about 6 years ago. And yet, he began to make his own framework working with php for only about a year at that time. The matter did not reach its logical conclusion, it was done: working with the database, processing pages, access control, something like a media library, pagination and other very basics.
Now it is difficult to look at your code of that time without shame and fear, but at that time knowledge was well advanced. Only time I then had a carriage.
The author, if you have time for this, and you don’t feel sorry for him, then I would advise you to do not just a framework, but separate module files for everyday needs. And improve them over time.
From my own experience, I can advise you to work with something ready-made, and when it comes to understanding that something does not suit you here and there, when there are enough arguments in favor of writing your own, start writing or fork an existing project. You probably don’t realize now how much of a huge piece of work it is to make a framework that is reliable, convenient, fast and extensible enough. It will most likely be a waste of a lot of time. If you first work with ready-made ones, there will be an understanding of how others solve problems, and ideas will appear on how to do better.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question