44
55use Illuminate \Container \Container ;
66use Illuminate \Contracts \Container \Container as ContainerInterface ;
7+ use Illuminate \Contracts \Foundation \Application ;
78use Illuminate \Contracts \View \Factory as FactoryContract ;
89use Illuminate \Contracts \View \View ;
910use Illuminate \Events \Dispatcher ;
1011use Illuminate \Filesystem \Filesystem ;
12+ use Illuminate \Support \Facades \Facade ;
1113use Illuminate \View \Compilers \BladeCompiler ;
1214use Illuminate \View \Factory ;
1315use Illuminate \View \ViewServiceProvider ;
1416
1517class Blade implements FactoryContract
1618{
1719 /**
18- * @var Container
20+ * @var Application
1921 */
2022 protected $ container ;
2123
@@ -34,16 +36,12 @@ public function __construct($viewPaths = null, string $cachePath = null, Contai
3436 $ this ->container = $ container ?: new Container ;
3537
3638 if ($ viewPaths != null && $ cachePath != null ) {
37- $ this ->setupContainer ((array ) $ viewPaths , $ cachePath );
38- (new ViewServiceProvider ($ this ->container ))->register ();
39-
40- $ this ->factory = $ this ->container ->get ('view ' );
41- $ this ->compiler = $ this ->container ->get ('blade.compiler ' );
39+ $ this ->configure ($ viewPaths , $ cachePath );
4240 }
4341 }
4442
4543 /**
46- * Configuation for template and cache directories
44+ * Configure your view and cache directories
4745 */
4846 public function configure ($ viewPaths , $ cachePath )
4947 {
@@ -89,6 +87,11 @@ public function directive(string $name, callable $handler)
8987 $ this ->compiler ->directive ($ name , $ handler );
9088 }
9189
90+ public function if ($ name , callable $ callback )
91+ {
92+ $ this ->compiler ->if ($ name , $ callback );
93+ }
94+
9295 public function exists ($ view ): bool
9396 {
9497 return $ this ->factory ->exists ($ view );
@@ -149,5 +152,7 @@ protected function setupContainer(array $viewPaths, string $cachePath)
149152 'view.compiled ' => $ cachePath ,
150153 ];
151154 }, true );
155+
156+ Facade::setFacadeApplication ($ this ->container );
152157 }
153158}
0 commit comments