[Li Jingshan php] every day laravel-20161109| viewserviceprovider.php

Source: Internet
Author: User

<?phpnamespace illuminate\view;use illuminate\view\engines\phpengine;use illuminate\support\ Serviceprovider;use illuminate\view\engines\compilerengine;use illuminate\view\engines\ engineresolver;use illuminate\view\compilers\bladecompiler;// cool namespaceclass  Viewserviceprovider extends serviceprovider{// viewserviceprovider extends something     /**     * register the service provider.      *     *  @return  void      */    public function register ()     {// a  register group function         $this Registerengineresolver ();// engine resolver         $this- >registerviewfinder ();//VIEW&NBSP;FINDER&NBSP;&NBSP;&NBsp;      $this->registerfactory ();// factory    }     /**     * Register the engine resolver  instance.     *     *  @return  void      */    public function registerengineresolver ()      {// register the engine resolver instance          $this->app->singleton (' view.engine.resolver ', function  ()  {              $resolver  = new EngineResolver;             // Next we will  register the various engines with the resolver so that the             // environment can resolve the engines it  needs for various views based             // on the extension of view files. We call a  method for each engines.             foreach  ([' php ',  ' blade '] as  $engine)  {                  $this->{' Register '. ucfirst ($engine). ' Engine '} ($resolver);             }// foreach  this array            return $ Resolver;// a anonymous function        });// a  wrap function ,    }    /**     * register the php  engine implementation.     *     *  @param    \Illuminate\View\Engines\EngineResolver   $resolver      *  @return  void     */    public function registerphpengine ( $resolver)     {         $resolver->register (' php ', function  ()  {            return  new phpengine;        });     }//use  resolver register ,type and instance    /**      * Register the Blade engine implementation.      *     *  @param   \Illuminate\View\Engines\EngineResolver   $resolver       *  @return  void     */    public  Function registerbladeengine ($resolver)     {//register the blade  engine implementation         $app  =  $this->app;//  set app        // The Compiler engine  requires an instance of the compilerinterface, which in         // this case will be the blade compiler,  so we ' ll first create the compiler         // instance to pass into the engine so it can compile  the views properly.         $app->singleton (' Blade.compiler ', function  ($ App)  {             $cache  =  $app [' Config ' [' view.compiled '];            return  New bladecompiler ($app [' files '],  $cache);         })//The  compiler engine require an instance of the compilerinterface,which  in       //this case will be the blade  Compiler, so we ' ll first create the compiler        // instance to pass into the engine so it can compile  the views properly.         $resolver->register (' Blade ', &NBSP;FUNCTION&NBsp; ()  use  ($app)  {             Return new compilerengine ($app [' Blade.compiler ']);         }) ;// use this register to register blade    }     /**     * Register the view finder  implementation.     *     *  @return  void      */    public function registerviewfinder ()      {         $this->app->bind (' View.finder ',  function  ($app)  {             $paths  =  $app [' config '] [' view.paths '];             return new fileviewfinder ($app [' filEs '],  $paths);         });// bind something i  hate this type to trans parameters    }//register the  View finder implementation    /**     * register  the view environment.     *     * @ return void     */    public function  Registerfactory ()     {//register the view environment        // like register Factory          $this->app->singleton (' View ', function  ($app)  {             // next we need to grab the engine  resolver instance that will be used by the             // environment. the resolver will be used by an environment  to get each of            //  the various engine implementations such as plain PHP or  blade engine.             $resolver  =   $app [' View.engine.resolver '];           //  next we need to grab           //  get the engine resolver              $finder  =  $app [' view.finder '];// get finder              $env  = new factory ($resolver,  $finder,  $app [' Events '];// instance  Factory            // we will also  set the container instance on this view environment since  the            // view composers  may be classes registered in the container, which allows             // for great testable,  flexible composers for the application developer.              $env->setcontainer ($app);//set container              $env->share (' app ',  $app);// share something            // we will also set the container  instance on this view environment since the view            // composers may be classes registered  in the container, which allows            // for great testable, flexible composers for the  application developer.           // a  good composers            return  $env;         });     }}


This article is from the "focus on PHP group number: 414194301" blog, Please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1847096

[Li Jingshan php] every day laravel-20161109| viewserviceprovider.php

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.