Smarty Front-end template engine-the PHP open source framework I've seen

Source: Internet
Author: User
Tags php language

Smarty

Smarty can be said to be the first open source framework that I have contacted with the PHP language, and with the help of Smarty, the project was well developed and the MVC pattern was well followed. But later, slowly found that many people are very familiar with smarty, but do not want to use it. The probable reason is: slow.

Originally thought Smarty is very magical, to later discovered also through PHP to realize. And then other people reflect the use of smarty will affect performance, so also want to learn more about its source code, see how it is implemented, is it really slow?

In fact, Smarty just used PHP to make a middle layer, to the custom template tags into the PHP language, which involves the syntax tree schema and the automatic generation of PHP code. The Art of computers, however, lies in this: any problem can be accomplished through a middle tier, but it can also cause performance problems. Therefore , it is this layer of the middle tier, affecting the performance. But Smarty also tried to fill the void by caching. But for good project layering, separating front-end and back-end, Smarty does have a good role in development practice, which requires a tradeoff between the cost of the project and the cost of the server.

UML Static Structure-part

Smarty really good outside, but smarty inside the structure and code level, personally, it seems a bit messy. The following is a partial UML structure diagram, others to add.


Analysis and summary

Similarly, due to the failure to record in real time, here are some key classes:

Smarty_internal_compilebase (compiled tags, such as: loops, assignments, interrupts, etc.)

Smarty_cacheresource (cache, such as: Key-value cache, custom cache, etc., there should also be a reference cache)

_smarty_parsetree (Syntax tree parser, including: text, tags, code, etc.)

Smarty_template_source, Smarty_resource (various resources: code, file contains, string, compile/non-compile)

From this the extension

Adding the middle layer to realize the parsing of the template will affect the performance, but this provides a good support for humanized development. More importantly, the concept of template engine has many other frameworks that can also be seen as references. If you feel smarty slow or do not meet your own project requirements, you can implement a set of template engine rules to resolve. For example, thinkphp support for templates, for more information, see: Http://doc.thinkphp.cn/manual/view.html.

There can be a deeper transformation, the use of the syntax tree pattern, which should involve a specific domain language DSL (more information can be seen in this book: "Domain-specific language"). Its role is to achieve some of the most difficult things through our familiar language . For example, we feel that it is painful for front-end HTML developers to use the PHP language to output data, so we provide tags like

Further down the layer, for example, we (PHP developers) feel that it is painful or difficult to develop PHP extensions in C + +, and we can use Zephir to write.

Here's a little bit of Zephir,zephir is by Phalcon (about the Phalcon open source framework, which will be said later, it's a very good open source framework!). The team provides a language that can be used to develop PHP extensions, and official documentation is available at: http://zephir-lang.com/index.html. Its mechanism is also through its own parser to Zephir code into C code, in order to realize the development of PHP extension.

Before, I tried to experience a bit of zephir, feeling good, here is an example of an attempt at the time: [Zephir Development practice] to write PHP extension practice with Zephir http://my.oschina.net/u/256338/blog/284540






Smarty Front-end template engine-the PHP open source framework I've seen

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.