@@ -18,11 +18,51 @@ class ViewServiceProvider extends ServiceProvider
18
18
*/
19
19
public function register ()
20
20
{
21
- $ this ->registerEngineResolver ();
21
+ $ this ->registerFactory ();
22
22
23
23
$ this ->registerViewFinder ();
24
24
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
+ });
26
66
}
27
67
28
68
/**
@@ -35,9 +75,9 @@ public function registerEngineResolver()
35
75
$ this ->app ->singleton ('view.engine.resolver ' , function () {
36
76
$ resolver = new EngineResolver ;
37
77
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.
41
81
foreach (['file ' , 'php ' , 'blade ' ] as $ engine ) {
42
82
$ this ->{'register ' .ucfirst ($ engine ).'Engine ' }($ resolver );
43
83
}
@@ -80,61 +120,17 @@ public function registerPhpEngine($resolver)
80
120
*/
81
121
public function registerBladeEngine ($ resolver )
82
122
{
83
- $ app = $ this ->app ;
84
-
85
123
// The Compiler engine requires an instance of the CompilerInterface, which in
86
124
// this case will be the Blade compiler, so we'll first create the compiler
87
125
// 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
+ );
96
130
});
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 ' ];
127
131
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 ' ]);
138
134
});
139
135
}
140
136
}
0 commit comments