Projekt

Obecné

Profil

Stáhnout (3.62 KB) Statistiky
| Větev: | Revize:
1
<?php
2

    
3
namespace Illuminate\View;
4

    
5
use Illuminate\View\Engines\PhpEngine;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\View\Engines\CompilerEngine;
8
use Illuminate\View\Engines\EngineResolver;
9
use Illuminate\View\Compilers\BladeCompiler;
10

    
11
class ViewServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Register the service provider.
15
     *
16
     * @return void
17
     */
18
    public function register()
19
    {
20
        $this->registerEngineResolver();
21

    
22
        $this->registerViewFinder();
23

    
24
        $this->registerFactory();
25
    }
26

    
27
    /**
28
     * Register the engine resolver instance.
29
     *
30
     * @return void
31
     */
32
    public function registerEngineResolver()
33
    {
34
        $this->app->singleton('view.engine.resolver', function () {
35
            $resolver = new EngineResolver;
36

    
37
            // Next we will register the various engines with the resolver so that the
38
            // environment can resolve the engines it needs for various views based
39
            // on the extension of view files. We call a method for each engines.
40
            foreach (['php', 'blade'] as $engine) {
41
                $this->{'register'.ucfirst($engine).'Engine'}($resolver);
42
            }
43

    
44
            return $resolver;
45
        });
46
    }
47

    
48
    /**
49
     * Register the PHP engine implementation.
50
     *
51
     * @param  \Illuminate\View\Engines\EngineResolver  $resolver
52
     * @return void
53
     */
54
    public function registerPhpEngine($resolver)
55
    {
56
        $resolver->register('php', function () {
57
            return new PhpEngine;
58
        });
59
    }
60

    
61
    /**
62
     * Register the Blade engine implementation.
63
     *
64
     * @param  \Illuminate\View\Engines\EngineResolver  $resolver
65
     * @return void
66
     */
67
    public function registerBladeEngine($resolver)
68
    {
69
        $app = $this->app;
70

    
71
        // The Compiler engine requires an instance of the CompilerInterface, which in
72
        // this case will be the Blade compiler, so we'll first create the compiler
73
        // instance to pass into the engine so it can compile the views properly.
74
        $app->singleton('blade.compiler', function ($app) {
75
            $cache = $app['config']['view.compiled'];
76

    
77
            return new BladeCompiler($app['files'], $cache);
78
        });
79

    
80
        $resolver->register('blade', function () use ($app) {
81
            return new CompilerEngine($app['blade.compiler']);
82
        });
83
    }
84

    
85
    /**
86
     * Register the view finder implementation.
87
     *
88
     * @return void
89
     */
90
    public function registerViewFinder()
91
    {
92
        $this->app->bind('view.finder', function ($app) {
93
            $paths = $app['config']['view.paths'];
94

    
95
            return new FileViewFinder($app['files'], $paths);
96
        });
97
    }
98

    
99
    /**
100
     * Register the view environment.
101
     *
102
     * @return void
103
     */
104
    public function registerFactory()
105
    {
106
        $this->app->singleton('view', function ($app) {
107
            // Next we need to grab the engine resolver instance that will be used by the
108
            // environment. The resolver will be used by an environment to get each of
109
            // the various engine implementations such as plain PHP or Blade engine.
110
            $resolver = $app['view.engine.resolver'];
111

    
112
            $finder = $app['view.finder'];
113

    
114
            $env = new Factory($resolver, $finder, $app['events']);
115

    
116
            // We will also set the container instance on this view environment since the
117
            // view composers may be classes registered in the container, which allows
118
            // for great testable, flexible composers for the application developer.
119
            $env->setContainer($app);
120

    
121
            $env->share('app', $app);
122

    
123
            return $env;
124
        });
125
    }
126
}
(6-6/7)