为了账号安全,请及时绑定邮箱和手机立即绑定

ViewServiceProvider.php

标签:
PHP

<?php

 

namespace 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 namespace

class 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 finder

 

        $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', function () 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;

        });

    }

}

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消