栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

ViewServiceProvider.php

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ViewServiceProvider.php

 

namespace IlluminateView;

 

use IlluminateViewEnginesPhpEngine;

use IlluminateSupportServiceProvider;

use IlluminateViewEnginesCompilerEngine;

use IlluminateViewEnginesEngineResolver;

use IlluminateViewCompilersBladeCompiler;

// cool namespace

class ViewServiceProvider extends ServiceProvider

{// ViewServiceProvider extends something

   

    public function register()

    {// a register group function

        $this->registerEngineResolver();// engine resolver

 

        $this->registerViewFinder();//view finder

 

        $this->registerFactory();// factory

    }

 

   

    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 ,

    }

 

   

    public function registerPhpEngine($resolver)

    {

        $resolver->register('php', function () {

            return new PhpEngine;

        });

    }//use resolver register ,type and instance

 

   

    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

    }

 

   

    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

 

   

    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;

        });

    }

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/229345.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号