How to write your own PHP framework

Source: Internet
Author: User
Tags php framework
Use PHP for a while, OK, just use it.

Have not done large-scale projects, has only done a simple module development, have seen the Yii thinkphp CI and other open source framework.
However, only stay in the state of knowing it, very much want to make a framework, from the small see big 1.1 point to do a thing out, do not know where to start.

Ask the Great God to guide the maze.

Reply content:

Use PHP for a while, OK, just use it.

Have not done large-scale projects, has only done a simple module development, have seen the Yii thinkphp CI and other open source framework.
However, only stay in the state of knowing it, very much want to make a framework, from the small see big 1.1 point to do a thing out, do not know where to start.

Ask the Great God to guide the maze.

I didn't want to answer the question. But after thinking for a while, still have to spit down the trough.

First you need to understand why you are developing your own framework?

I don't think you have any idea. In order to write a frame, feel very cool, very powerful, or just to smooth,

Conform to their own habits.

The landlord himself or in the first hand stage, to several good framework principles are not clear, began to write the framework. I don't think it's very practical.

To When you understand the advantages and disadvantages of the present framework, the principle, feel is not very convenient, or feel that is not very consistent with their own ideas, habits and so on.

You're just going to develop it. Then you have the strength to understand deeply.

I was also doing a lot of projects, also used a lot of frameworks, feel that the framework is not very consistent with their own ideas. To try to write a match from

The framework of their own ideas.

The above is purely personal understanding. Words are not good places, please advise.

First Spit: The framework, like other programs, is used to solve problems. If you don't have a problem, why reinvent the wheel?

And say something serious:

Most web frameworks handle the following things:

    • Code reuse: Defines the placement and loading rules for packages, classes, functions, and recommends the direct integration of composer and its autoload features.
    • Request Distribution Management: This is the route, the rest wind framework like rewrite, the simple point of the framework mainly through the parameters to locate the module and the method is located.
    • Profile Management: Load and load configuration data dynamically
    • Error and Exception management: Exception snapping, error logging, and error code specification.
    • Layout and template engine: How to plan page layouts, how widgets are reused, how Ajax pages are combined, how to redirect expired sessions, how data and templates are rendered HTML, whether to compress and set expiration headers.
    • Database: How to integrate the controller, what kind of driver to support, consider the extensibility of master-slave separation, and whether to use ORM.

The core framework is basically these things. The periphery is the other common components, design good plug and play mechanism is good.

Large-scale framework to achieve more complex, you can find some simple framework to start, and then slowly experience the advantages of large-scale framework.

By the way I wrote a frame: https://github.com/easychen/lazyphp/tree/3.1

General framework single-entry -> route -> distribution -> rendering, add some extensibility, to routing, distribution and rendering with interface or abstract class, and then conveniently add composer, then good maintenance point Plus module, and then change the bug.
吐槽: General formal projects with a more mature open source framework is better, I have experienced the 自主开发框架 persecution of programmers t_t, except for the excellent autonomous framework.

The most basic part of the general PHP Framework is to include URL Routing and request distribution, database connection and operation, template engine, common string array operation, automatic loading and other functions and modules, can refer to some of the implementation of the less obscure framework learning, step by step implementation, But the quality of the framework is not the class library and function of the package, but also the organic reasonable to combine the above functional modules together to play a huge role.

Try to write a frame of your own, there is a good idea that you want to improve, you want to learn more knowledge.
Write a framework I think it is a summary of the knowledge or experience that you have learned, only when you have more understanding of PHP and Web applications and your own ideas, you have the goods to the framework of these ideas and experience to summarize.
Write an article we will write, why we can not become a writer?
So I don't think to write the framework, you want to make yourself better at understanding PHP and Web programs.
I recommend you should go to see Symfony author's blog http://fabien.potencier.org/here each article is very exciting, his style is very straightforward, easy to understand, and the teacher in class as the explanation of the technology has fruit.
You can try to read Sliex Https://github.com/fabpot/Silex source code, this is another simple framework developed by Symfony author, not as complex as symfony.
Finally attached to my own blog: http://www.tangrucheng.com I am also a beginner you can exchange and learn PHP

Find a frame and write it all over again.
And then you don't have to ask this question.

If your goal is to "do something", then the most reasonable/common thing is to write a blog program

    • There is no business writing framework that requires a lot of experience to do the groundwork (knowing the similarities and differences of various projects, developing pain points), while the blogging program is a real business
    • The flexibility of the blogging business can be almost infinitely bigger and more complex from a very small start. And it can involve almost all aspects of a web.
    • Blog for self-deployment on-line, at least 1 management users (themselves) and a number of tourists. and write the framework, but also around the "project no One" embarrassment

Ad Time-my PHP framework litphp

Although the 0.2 version is 10 lines long, 289 lines of code lines should still be the world's smallest PHP framework

http://litphp.github.io/

Take a look at the code for half an hour, look closely at the most, should be able to provide some ideas for writing framework.

The PHP community is already very mature, the various models and styles of the framework have been implemented, privately think, you go to develop a PHP framework, purely to repeat the fun of making wheels and sense of accomplishment. Of course, if you have enough time and experience, you can try to develop a framework that fits your own habits, while understanding framework design and exercising your abilities on the one hand. However, this is all after you have used, at least to understand a lot of different styles of the framework .

However, other emerging technologies, such as node. js, are still young, the packages and frameworks are not very mature, there are many gaps to fill, unlimited possibilities, and this is the time to develop a framework that makes sense for the community to contribute .

Send me a node. JS framework: Codekart, official website, Documentation manual

I do not agree, if I had just started before, certainly will have this idea. But now I will choose to use the mainstream open source framework.
Write their own framework, of course, can run, but have not experienced the test of time, after all, it is necessary to constantly re-construction!

You're not going to make it. PHP Evolution, PHP upgrades, framework upgrades will get you mad

The MVC framework of the web is too many, recommend landlord to some unpopular framework, such as Socket Server framework, asynchronous framework, mobile application framework, etc.

"It's been a while using PHP, OK, just use it." Use of time estimates are still a little short, contact PHP within three years recommended to familiar with some common PHP framework, ci,yii,thinkphp,laravel,symfony and so on, and so on, and then consider writing their own framework it. In fact, with the existing framework or the development of their own framework is justified. The premise is that you understand the advantages and disadvantages of other frameworks before you develop the framework so that you can develop a better framework. If you just want to quickly develop a product with a framework, we recommend using an existing framework.

The main benefit of developing your own framework is that it allows you to learn how the framework is written. If you want to ask how to write it, I suggest that you start by customizing a framework, change it to what you need or want, learn the main implementation process and what features are used in the language. Constantly customizing the changes until you finally get rid of his core code is what you want.

Of course, there are many things to think about and learn from, such as how to support multi-threaded, multi-process, asynchronous logs and so on, how to optimize for the CLI mode

Https://github.com/lloydzhou/router
Can see

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.