22
33namespace Leaf ;
44
5- use Illuminate \Contracts \Container \Container as ContainerInterface ;
6- use Illuminate \Contracts \View \Factory as FactoryContract ;
7- use Illuminate \Contracts \View \View ;
8- use Illuminate \Events \Dispatcher ;
9- use Illuminate \Filesystem \Filesystem ;
10- use Illuminate \Support \Facades \Facade ;
11- use Illuminate \View \Compilers \BladeCompiler ;
12- use Illuminate \View \Factory ;
13- use Illuminate \View \ViewServiceProvider ;
14-
15- class Blade implements FactoryContract
5+ class Blade
166{
17- /**
18- * @var BladeContainer
19- */
20- protected $ container ;
21-
22- /**
23- * @var Factory
24- */
25- private $ factory ;
7+ protected $ blade ;
268
27- /**
28- * @var BladeCompiler
29- */
30- private $ compiler ;
31-
32- public function __construct ($ viewPaths = null , string $ cachePath = null , ContainerInterface $ container = null )
9+ public function __construct (string $ viewPaths = null , string $ cachePath = null )
3310 {
34- $ this ->container = $ container ?: new \Leaf \BladeContainer ();
35-
36- if ($ viewPaths != null && $ cachePath != null ) {
37- $ this ->configure ($ viewPaths , $ cachePath );
38- }
11+ // Just to maintain compatibility with the original Leaf Blade
3912 }
4013
4114 /**
4215 * Configure your view and cache directories
4316 */
44- public function configure ($ viewPaths , $ cachePath )
17+ public function configure (string $ viewPaths , string $ cachePath )
4518 {
46- $ this ->setupContainer ((array ) $ viewPaths , $ cachePath );
47- (new ViewServiceProvider ($ this ->container ))->register ();
48-
49- $ this ->factory = $ this ->container ->get ('view ' );
50- $ this ->compiler = $ this ->container ->get ('blade.compiler ' );
19+ $ this ->blade = new \Jenssegers \Blade \Blade ($ viewPaths , $ cachePath );
5120 }
5221
5322 /**
@@ -56,9 +25,9 @@ public function configure($viewPaths, $cachePath)
5625 * A shorter version of the original `make` command.
5726 * You can optionally pass data into the view as a second parameter
5827 */
59- public function render (string $ view , array $ data = [], array $ mergeData = []): string
28+ public function render (string $ view , $ data = [], $ mergeData = [])
6029 {
61- return $ this ->make ($ view , $ data , $ mergeData )-> render () ;
30+ return $ this ->make ($ view , $ data , $ mergeData );
6231 }
6332
6433 /**
@@ -67,90 +36,25 @@ public function render(string $view, array $data = [], array $mergeData = []): s
6736 * You can optionally pass data into the view as a second parameter.
6837 * Don't forget to chain the `render` method
6938 */
70- public function make ($ view , $ data = [], $ mergeData = []): View
71- {
72- return $ this ->factory ->make ($ view , $ data , $ mergeData );
73- }
74-
75- public function compiler (): BladeCompiler
39+ public function make (string $ view , $ data = [], $ mergeData = []): string
7640 {
77- return $ this ->compiler ;
41+ return $ this ->blade -> make ( $ view , $ data , $ mergeData )-> render () ;
7842 }
7943
8044 /**
81- * Create your own custom directive
45+ * Add a new namespace to the loader
8246 */
8347 public function directive (string $ name , callable $ handler )
8448 {
85- $ this ->compiler ->directive ($ name , $ handler );
86- }
87-
88- public function if ($ name , callable $ callback )
89- {
90- $ this ->compiler ->if ($ name , $ callback );
91- }
92-
93- public function exists ($ view ): bool
94- {
95- return $ this ->factory ->exists ($ view );
96- }
97-
98- public function file ($ path , $ data = [], $ mergeData = []): View
99- {
100- return $ this ->factory ->file ($ path , $ data , $ mergeData );
101- }
102-
103- public function share ($ key , $ value = null )
104- {
105- return $ this ->factory ->share ($ key , $ value );
106- }
107-
108- public function composer ($ views , $ callback ): array
109- {
110- return $ this ->factory ->composer ($ views , $ callback );
111- }
112-
113- public function creator ($ views , $ callback ): array
114- {
115- return $ this ->factory ->creator ($ views , $ callback );
116- }
117-
118- public function addNamespace ($ namespace , $ hints ): self
119- {
120- $ this ->factory ->addNamespace ($ namespace , $ hints );
121-
122- return $ this ;
123- }
124-
125- public function replaceNamespace ($ namespace , $ hints ): self
126- {
127- $ this ->factory ->replaceNamespace ($ namespace , $ hints );
128-
129- return $ this ;
130- }
131-
132- public function __call (string $ method , array $ params )
133- {
134- return call_user_func_array ([$ this ->factory , $ method ], $ params );
49+ $ this ->blade ->directive ($ name , $ handler );
13550 }
13651
137- protected function setupContainer (array $ viewPaths , string $ cachePath )
52+ /**
53+ * Summary of blade
54+ * @return \Jenssegers\Blade\Blade
55+ */
56+ public function blade ()
13857 {
139- $ this ->container ->bindIf ('files ' , function () {
140- return new Filesystem ;
141- }, true );
142-
143- $ this ->container ->bindIf ('events ' , function () {
144- return new Dispatcher ;
145- }, true );
146-
147- $ this ->container ->bindIf ('config ' , function () use ($ viewPaths , $ cachePath ) {
148- return new BladeConfig ([
149- 'view.paths ' => $ viewPaths ,
150- 'view.compiled ' => $ cachePath ,
151- ]);
152- }, true );
153-
154- Facade::setFacadeApplication ($ this ->container );
58+ return $ this ->blade ;
15559 }
15660}
0 commit comments