Skip to content

Commit aec1d04

Browse files
committed
Clean-up view service provider.
1 parent b0d7cad commit aec1d04

File tree

1 file changed

+51
-55
lines changed

1 file changed

+51
-55
lines changed

src/Illuminate/View/ViewServiceProvider.php

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,51 @@ class ViewServiceProvider extends ServiceProvider
1818
*/
1919
public function register()
2020
{
21-
$this->registerEngineResolver();
21+
$this->registerFactory();
2222

2323
$this->registerViewFinder();
2424

25-
$this->registerFactory();
25+
$this->registerEngineResolver();
26+
}
27+
28+
/**
29+
* Register the view environment.
30+
*
31+
* @return void
32+
*/
33+
public function registerFactory()
34+
{
35+
$this->app->singleton('view', function ($app) {
36+
// Next we need to grab the engine resolver instance that will be used by the
37+
// environment. The resolver will be used by an environment to get each of
38+
// the various engine implementations such as plain PHP or Blade engine.
39+
$resolver = $app['view.engine.resolver'];
40+
41+
$finder = $app['view.finder'];
42+
43+
$env = new Factory($resolver, $finder, $app['events']);
44+
45+
// We will also set the container instance on this view environment since the
46+
// view composers may be classes registered in the container, which allows
47+
// for great testable, flexible composers for the application developer.
48+
$env->setContainer($app);
49+
50+
$env->share('app', $app);
51+
52+
return $env;
53+
});
54+
}
55+
56+
/**
57+
* Register the view finder implementation.
58+
*
59+
* @return void
60+
*/
61+
public function registerViewFinder()
62+
{
63+
$this->app->bind('view.finder', function ($app) {
64+
return new FileViewFinder($app['files'], $app['config']['view.paths']);
65+
});
2666
}
2767

2868
/**
@@ -35,9 +75,9 @@ public function registerEngineResolver()
3575
$this->app->singleton('view.engine.resolver', function () {
3676
$resolver = new EngineResolver;
3777

38-
// Next we will register the various engines with the resolver so that the
39-
// environment can resolve the engines it needs for various views based
40-
// on the extension of view files. We call a method for each engines.
78+
// Next, we will register the various view engines with the resolver so that the
79+
// environment will resolve the engines needed for various views based on the
80+
// extension of view file. We call a method for each of the view's engines.
4181
foreach (['file', 'php', 'blade'] as $engine) {
4282
$this->{'register'.ucfirst($engine).'Engine'}($resolver);
4383
}
@@ -80,61 +120,17 @@ public function registerPhpEngine($resolver)
80120
*/
81121
public function registerBladeEngine($resolver)
82122
{
83-
$app = $this->app;
84-
85123
// The Compiler engine requires an instance of the CompilerInterface, which in
86124
// this case will be the Blade compiler, so we'll first create the compiler
87125
// instance to pass into the engine so it can compile the views properly.
88-
$app->singleton('blade.compiler', function ($app) {
89-
$cache = $app['config']['view.compiled'];
90-
91-
return new BladeCompiler($app['files'], $cache);
92-
});
93-
94-
$resolver->register('blade', function () use ($app) {
95-
return new CompilerEngine($app['blade.compiler']);
126+
$this->app->singleton('blade.compiler', function () {
127+
return new BladeCompiler(
128+
$this->app['files'], $this->app['config']['view.compiled']
129+
);
96130
});
97-
}
98-
99-
/**
100-
* Register the view finder implementation.
101-
*
102-
* @return void
103-
*/
104-
public function registerViewFinder()
105-
{
106-
$this->app->bind('view.finder', function ($app) {
107-
$paths = $app['config']['view.paths'];
108-
109-
return new FileViewFinder($app['files'], $paths);
110-
});
111-
}
112-
113-
/**
114-
* Register the view environment.
115-
*
116-
* @return void
117-
*/
118-
public function registerFactory()
119-
{
120-
$this->app->singleton('view', function ($app) {
121-
// Next we need to grab the engine resolver instance that will be used by the
122-
// environment. The resolver will be used by an environment to get each of
123-
// the various engine implementations such as plain PHP or Blade engine.
124-
$resolver = $app['view.engine.resolver'];
125-
126-
$finder = $app['view.finder'];
127131

128-
$env = new Factory($resolver, $finder, $app['events']);
129-
130-
// We will also set the container instance on this view environment since the
131-
// view composers may be classes registered in the container, which allows
132-
// for great testable, flexible composers for the application developer.
133-
$env->setContainer($app);
134-
135-
$env->share('app', $app);
136-
137-
return $env;
132+
$resolver->register('blade', function () {
133+
return new CompilerEngine($this->app['blade.compiler']);
138134
});
139135
}
140136
}

0 commit comments

Comments
 (0)