Home > Backend Development > PHP Tutorial > #年福利# Pseudo implementation of some core classes of Phalcon framework

#年福利# Pseudo implementation of some core classes of Phalcon framework

WBOY
Release: 2016-07-25 08:48:58
Original
1076 people have browsed it
Since seeing the open source framework Phalcon in Open Source China and reading its development documentation, I feel that its documentation is not just about its framework, nor is it just explaining the PHP language, but to a greater extent. How to design a framework and how to develop software efficiently and elegantly.

Interested children’s shoes are strongly recommended to read: Link above: http://docs.phalconphp.com/en/latest/index.html

But because the Phalcon framework is an extension written in C, there is no PHP related information. The source code, but its development ideas are worth learning, referencing, and learning from, so I implemented some of the core classes according to its ideas and share them here. Purpose:

1. Independently implement Phalcon partial classification through the great ideas of Phalcon, deepen your understanding of it, and your own coding capabilities;
2. As a common core class, it can be appropriately applied to future projects after implementation;
3 , standardize your own development process (testing + examples + generating release code);

Only two classes are currently implemented, classified into DI (Dependency Injection) class and Loader class (Universal Class Loader), which may be implemented later when there is time others. Interested students can also try it~

Attachment list:
1. All file compression packages (source code, release code, examples, tests)
2. Screenshots of running effects
3. FDI sample code (for viewing Convenient, you can also view it in the download code)

PS: The editor used the autoloading class FLoader I just wrote to replace the autoloading class of the existing project. It can be replaced perfectly without any error. I am very happy~~~ ~ #年福利# Pseudo implementation of some core classes of Phalcon framework #年福利# Pseudo implementation of some core classes of Phalcon framework #年福利# Pseudo implementation of some core classes of Phalcon framework #年福利# Pseudo implementation of some core classes of Phalcon framework
  1. require dirname(__FILE__) . '/../release/FDI.php';
  2. /**------------------ Creation and Settings ------------------ **/
  3. //Get FDI
  4. $fdi = FDI::getInstance ();
  5. //Demo key
  6. $key = 'demoKey';
  7. /**------------------ set up ------------------ **/
  8. //Assignable types: direct assignment, class name assignment, anonymous function
  9. $fdi- >set($key, 'Hello FDI!');
  10. $fdi->set($key, 'Simple');
  11. $fdi->set($key, function(){
  12. return new Simple( );
  13. });
  14. //Setting method: In addition to the set() above, you can also assign values ​​like this
  15. $fdi->setDemoKey('Hello FDI!');
  16. $fdi->demoKey = 'Hello FDI!';
  17. $fdi['demoKey'] = 'Hello FDI!';
  18. /**------------------ Obtain ------------------ **/
  19. //So you can get the value like this
  20. echo $fdi->get(' demoKey'), "n";
  21. echo $fdi->getDemoKey(), "n";
  22. echo $fdi->demoKey, "n";
  23. echo $fdi['demoKey']. "n";
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template