preface

For PHP frameworks, whether they are Yichi, Symfony or Laravel, everyone has been working on them. The vendor folder and the entry file (index. PHP or app. PHP) that reside in the framework are also met daily. But are you really familiar with these files/folders? How does a complete project evolve from a clean framework? What is the role of each part in the framework of the building?

Third, symfony

Always say the server side deletes the cache, in the end deletes really what?

3.1 Entry file

. $loader = require_once __DIR__.'/.. /app/autoload.php'; require_once __DIR__.'/.. /app/bootstrap.php.cache'; $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $kernel->setRequest($request); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); .

When we look at this file, we see that we have to bring in the autoload file first. Much of the previous article focused on a problem with dependency files. We have to take this dependency.

Let’s focus on AppKernel and Application

Let’s take a look at the boot method in AppKernel.php. This method is the bootstrap method of the entire Appker class and is the core. It does the following things.

  • instantiationBundle
  • Instantiation container
  • Instantiate the Biz class
  • Boot each Bundle
public function boot() { if (true === $this->booted) { return; } if ($this->loadClassCache) { $this->doLoadClassCache($this->loadClassCache[0], $this->loadClassCache[1]); } /** * instantiate Bundles. */ $this->initializeBundles(); / * * * according to the cache/Jianmo/appDevDebugProjectContainer in PHP. The meta exists, the file content (serialization) consistent with the configuration file content is * To determine whether to need to generate cache/Jianmo appDevDebugProjectContainer. PHP files and relevant files which appDevDebugProjectContainer. * PHP content below * Initialize appDevDebugProjectContainer class (including methodMap object is "class to instantiate the class methods' table) * initialization complete, $this->>getContainer->get($methodMapClassName) */ $this-> InitializeContainer (); $this-> InitializeContainer (); / * * * call appDevDebugProjectContainer - > getBizService Biz class * * instantiated () method of the initialization parameters by the app/config/Biz yml with * / $this->initializeBiz(); /** * AppKernel is an important file * In Console command line mode/browser request mode, $this->initializeServiceKernel(); $this->initializeServiceKernel(); $this->initializeServiceKernel(); foreach ($this->getBundles() as $bundle) { $bundle->setContainer($this->container); $bundle->boot(); } $this->booted = true; }

3.1.2 Instantiate the Bundle

3.1.2 Instantiate Containers

This method is written in the vendor/symfony/symfony/SRC/symfony/Component/HttpKernel/Kernel. The underlying PHP is a write in the symfony method, we will in this detailed say his function and form.

protected function initializeContainer() { $class = $this->getContainerClass(); $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug); $fresh = true; if (! $cache->isFresh()) { $container = $this->buildContainer(); $container->compile(); $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass()); $fresh = false; } require_once $cache->getPath(); / * * * has just generated app [Dev | Prod]] DebugProjectContainer class to instantiate. $this->container = new $class(); $this->container = new $class(); $this->container->set('kernel', $this); if (! $fresh && $this->container->has('cache_warmer')) { $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir')); }}

If at this time we open the app/cache / [prod | dev] / Jianmo/app/dev | prod]] DebugProjectContainer. PHP file we shall find that he was in the __construct (), Write all the class names and methods to be loaded into a large array. The code is as follows. If we want to initialize the biz class, we simply call the getBizService method. This method is also in the current file.

. public function __construct() { ... $this->methodMap = array( 'annotation_reader' => 'getAnnotationReaderService', 'app.locale_listener' => 'getApp_LocaleListenerService', 'biz' => 'getBizService' ... ) ; }