Vous êtes connecté en tant que anonymous Se Deconnecter
Browse code

Application modulaire fonctionnelle !

Emmanuel ROY authored on 12/08/2019 15:10:25
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,361 +0,0 @@
1
-<?php declare(strict_types=1);
2
-/**
3
- * Part of Windwalker project.
4
- *
5
- * @copyright  Copyright (C) 2019 LYRASOFT.
6
- * @license    LGPL-2.0-or-later
7
- */
8
-
9
-namespace Windwalker\Renderer;
10
-
11
-use Illuminate\Events\Dispatcher;
12
-use Illuminate\Filesystem\Filesystem;
13
-use Illuminate\View\Compilers\BladeCompiler;
14
-use Illuminate\View\Engines\CompilerEngine;
15
-use Illuminate\View\Engines\EngineResolver;
16
-use Illuminate\View\Factory as BladeEnvironment;
17
-use Illuminate\View\FileViewFinder;
18
-use Windwalker\Renderer\Blade\BladeExtending;
19
-use Windwalker\Renderer\Blade\GlobalContainer;
20
-
21
-/**
22
- * The BladeRenderer class.
23
- *
24
- * @since  2.0
25
- */
26
-class BladeRenderer extends AbstractEngineRenderer
27
-{
28
-    /**
29
-     * Property blade.
30
-     *
31
-     * @var  BladeEnvironment
32
-     */
33
-    protected $engine = null;
34
-
35
-    /**
36
-     * Property filesystem.
37
-     *
38
-     * @var Filesystem
39
-     */
40
-    protected $filesystem;
41
-
42
-    /**
43
-     * Property finder.
44
-     *
45
-     * @var FileViewFinder
46
-     */
47
-    protected $finder;
48
-
49
-    /**
50
-     * Property resolver.
51
-     *
52
-     * @var EngineResolver
53
-     */
54
-    protected $resolver;
55
-
56
-    /**
57
-     * Property dispatcher.
58
-     *
59
-     * @var Dispatcher
60
-     */
61
-    protected $dispatcher;
62
-
63
-    /**
64
-     * Property compiler.
65
-     *
66
-     * @var CompilerEngine
67
-     */
68
-    protected $compiler;
69
-
70
-    /**
71
-     * Property customCompiler.
72
-     *
73
-     * @var  callable[]
74
-     */
75
-    protected $customCompilers = [];
76
-
77
-    /**
78
-     * render
79
-     *
80
-     * @param string $file
81
-     * @param array  $data
82
-     *
83
-     * @return  string
84
-     */
85
-    public function render($file, $data = [])
86
-    {
87
-        if ($data instanceof \Traversable) {
88
-            $data = iterator_to_array($data);
89
-        }
90
-
91
-        if (is_object($data)) {
92
-            $data = get_object_vars($data);
93
-        }
94
-
95
-        return $this->getEngine()->make($file, (array) $data)->render();
96
-    }
97
-
98
-    /**
99
-     * Method to get property Blade
100
-     *
101
-     * @param bool $new
102
-     *
103
-     * @return  BladeEnvironment
104
-     */
105
-    public function getEngine($new = false)
106
-    {
107
-        if (!$this->engine || $new) {
108
-            $this->engine = new BladeEnvironment($this->getResolver(), $this->getFinder(), $this->getDispatcher());
109
-
110
-            /** @var BladeCompiler $bladeCompiler */
111
-            $bladeCompiler = $this->getCompiler()->getCompiler();
112
-
113
-            foreach (GlobalContainer::getCompilers() as $name => $callback) {
114
-                BladeExtending::extend($bladeCompiler, $name, $callback);
115
-            }
116
-
117
-            foreach ($this->getCustomCompilers() as $name => $callback) {
118
-                BladeExtending::extend($bladeCompiler, $name, $callback);
119
-            }
120
-
121
-            foreach (GlobalContainer::getExtensions() as $name => $callback) {
122
-                $bladeCompiler->extend($callback);
123
-            }
124
-
125
-            // B/C for 4.* and 5.*
126
-            if (($rawTags = GlobalContainer::getRawTags()) && is_callable([$bladeCompiler, 'setRawTags'])) {
127
-                $bladeCompiler->setRawTags($rawTags[0], $rawTags[1]);
128
-            }
129
-
130
-            if ($tags = GlobalContainer::getContentTags()) {
131
-                $bladeCompiler->setContentTags($tags[0], $tags[1]);
132
-            }
133
-
134
-            if ($tags = GlobalContainer::getEscapedTags()) {
135
-                $bladeCompiler->setEscapedContentTags($tags[0], $tags[1]);
136
-            }
137
-        }
138
-
139
-        return $this->engine;
140
-    }
141
-
142
-    /**
143
-     * Method to set property blade
144
-     *
145
-     * @param   BladeEnvironment $blade
146
-     *
147
-     * @return  static  Return self to support chaining.
148
-     */
149
-    public function setEngine($blade)
150
-    {
151
-        if (!($blade instanceof BladeEnvironment)) {
152
-            throw new \InvalidArgumentException('Engine object should be Illuminate\View\Environment.');
153
-        }
154
-
155
-        $this->engine = $blade;
156
-
157
-        return $this;
158
-    }
159
-
160
-    /**
161
-     * Method to get property Filesystem
162
-     *
163
-     * @return  Filesystem
164
-     */
165
-    public function getFilesystem()
166
-    {
167
-        if (!$this->filesystem) {
168
-            $this->filesystem = new Filesystem();
169
-        }
170
-
171
-        return $this->filesystem;
172
-    }
173
-
174
-    /**
175
-     * Method to set property filesystem
176
-     *
177
-     * @param   Filesystem $filesystem
178
-     *
179
-     * @return  static  Return self to support chaining.
180
-     */
181
-    public function setFilesystem($filesystem)
182
-    {
183
-        $this->filesystem = $filesystem;
184
-
185
-        return $this;
186
-    }
187
-
188
-    /**
189
-     * Method to get property Finder
190
-     *
191
-     * @return  FileViewFinder
192
-     */
193
-    public function getFinder()
194
-    {
195
-        if (!$this->finder) {
196
-            $this->finder = new FileViewFinder($this->getFilesystem(), $this->dumpPaths());
197
-        }
198
-
199
-        return $this->finder;
200
-    }
201
-
202
-    /**
203
-     * Method to set property finder
204
-     *
205
-     * @param   FileViewFinder $finder
206
-     *
207
-     * @return  static  Return self to support chaining.
208
-     */
209
-    public function setFinder($finder)
210
-    {
211
-        $this->finder = $finder;
212
-
213
-        return $this;
214
-    }
215
-
216
-    /**
217
-     * Method to get property Resolver
218
-     *
219
-     * @return  EngineResolver
220
-     */
221
-    public function getResolver()
222
-    {
223
-        if (!$this->resolver) {
224
-            $self = $this;
225
-
226
-            $this->resolver = new EngineResolver();
227
-
228
-            $this->resolver->register(
229
-                'blade',
230
-                function () use ($self) {
231
-                    return $self->getCompiler();
232
-                }
233
-            );
234
-        }
235
-
236
-        return $this->resolver;
237
-    }
238
-
239
-    /**
240
-     * Method to set property resolver
241
-     *
242
-     * @param   EngineResolver $resolver
243
-     *
244
-     * @return  static  Return self to support chaining.
245
-     */
246
-    public function setResolver($resolver)
247
-    {
248
-        $this->resolver = $resolver;
249
-
250
-        return $this;
251
-    }
252
-
253
-    /**
254
-     * Method to get property Dispatcher
255
-     *
256
-     * @return  Dispatcher
257
-     */
258
-    public function getDispatcher()
259
-    {
260
-        if (!$this->dispatcher) {
261
-            $this->dispatcher = new Dispatcher();
262
-        }
263
-
264
-        return $this->dispatcher;
265
-    }
266
-
267
-    /**
268
-     * Method to set property dispatcher
269
-     *
270
-     * @param   Dispatcher $dispatcher
271
-     *
272
-     * @return  static  Return self to support chaining.
273
-     */
274
-    public function setDispatcher($dispatcher)
275
-    {
276
-        $this->dispatcher = $dispatcher;
277
-
278
-        return $this;
279
-    }
280
-
281
-    /**
282
-     * Method to get property Compiler
283
-     *
284
-     * @return  CompilerEngine
285
-     */
286
-    public function getCompiler()
287
-    {
288
-        if (!$this->compiler) {
289
-            $cachePath = $this->config->get('cache_path') ?: GlobalContainer::getCachePath();
290
-
291
-            if (!$cachePath) {
292
-                throw new \InvalidArgumentException('Please set cache_path into config.');
293
-            }
294
-
295
-            if (!is_dir($cachePath)) {
296
-                mkdir($cachePath, 0755, true);
297
-            }
298
-
299
-            $this->compiler = new CompilerEngine(new BladeCompiler($this->getFilesystem(), $cachePath));
300
-        }
301
-
302
-        return $this->compiler;
303
-    }
304
-
305
-    /**
306
-     * Method to set property compiler
307
-     *
308
-     * @param   CompilerEngine $compiler
309
-     *
310
-     * @return  static  Return self to support chaining.
311
-     */
312
-    public function setCompiler($compiler)
313
-    {
314
-        $this->compiler = $compiler;
315
-
316
-        return $this;
317
-    }
318
-
319
-    /**
320
-     * addCustomCompiler
321
-     *
322
-     * @param   string   $name
323
-     * @param   callable $compiler
324
-     *
325
-     * @return  static
326
-     */
327
-    public function addCustomCompiler($name, $compiler)
328
-    {
329
-        if (!is_callable($compiler)) {
330
-            throw new \InvalidArgumentException('Compiler should be callable.');
331
-        }
332
-
333
-        $this->customCompilers[$name] = $compiler;
334
-
335
-        return $this;
336
-    }
337
-
338
-    /**
339
-     * Method to get property CustomCompiler
340
-     *
341
-     * @return  \callable[]
342
-     */
343
-    public function getCustomCompilers()
344
-    {
345
-        return $this->customCompilers;
346
-    }
347
-
348
-    /**
349
-     * Method to set property customCompiler
350
-     *
351
-     * @param   \callable[] $customCompilers
352
-     *
353
-     * @return  static  Return self to support chaining.
354
-     */
355
-    public function setCustomCompilers(array $customCompilers)
356
-    {
357
-        $this->customCompilers = $customCompilers;
358
-
359
-        return $this;
360
-    }
361
-}
Browse code

initial commit

Emmanuel ROY authored on 09/08/2019 08:39:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,361 @@
1
+<?php declare(strict_types=1);
2
+/**
3
+ * Part of Windwalker project.
4
+ *
5
+ * @copyright  Copyright (C) 2019 LYRASOFT.
6
+ * @license    LGPL-2.0-or-later
7
+ */
8
+
9
+namespace Windwalker\Renderer;
10
+
11
+use Illuminate\Events\Dispatcher;
12
+use Illuminate\Filesystem\Filesystem;
13
+use Illuminate\View\Compilers\BladeCompiler;
14
+use Illuminate\View\Engines\CompilerEngine;
15
+use Illuminate\View\Engines\EngineResolver;
16
+use Illuminate\View\Factory as BladeEnvironment;
17
+use Illuminate\View\FileViewFinder;
18
+use Windwalker\Renderer\Blade\BladeExtending;
19
+use Windwalker\Renderer\Blade\GlobalContainer;
20
+
21
+/**
22
+ * The BladeRenderer class.
23
+ *
24
+ * @since  2.0
25
+ */
26
+class BladeRenderer extends AbstractEngineRenderer
27
+{
28
+    /**
29
+     * Property blade.
30
+     *
31
+     * @var  BladeEnvironment
32
+     */
33
+    protected $engine = null;
34
+
35
+    /**
36
+     * Property filesystem.
37
+     *
38
+     * @var Filesystem
39
+     */
40
+    protected $filesystem;
41
+
42
+    /**
43
+     * Property finder.
44
+     *
45
+     * @var FileViewFinder
46
+     */
47
+    protected $finder;
48
+
49
+    /**
50
+     * Property resolver.
51
+     *
52
+     * @var EngineResolver
53
+     */
54
+    protected $resolver;
55
+
56
+    /**
57
+     * Property dispatcher.
58
+     *
59
+     * @var Dispatcher
60
+     */
61
+    protected $dispatcher;
62
+
63
+    /**
64
+     * Property compiler.
65
+     *
66
+     * @var CompilerEngine
67
+     */
68
+    protected $compiler;
69
+
70
+    /**
71
+     * Property customCompiler.
72
+     *
73
+     * @var  callable[]
74
+     */
75
+    protected $customCompilers = [];
76
+
77
+    /**
78
+     * render
79
+     *
80
+     * @param string $file
81
+     * @param array  $data
82
+     *
83
+     * @return  string
84
+     */
85
+    public function render($file, $data = [])
86
+    {
87
+        if ($data instanceof \Traversable) {
88
+            $data = iterator_to_array($data);
89
+        }
90
+
91
+        if (is_object($data)) {
92
+            $data = get_object_vars($data);
93
+        }
94
+
95
+        return $this->getEngine()->make($file, (array) $data)->render();
96
+    }
97
+
98
+    /**
99
+     * Method to get property Blade
100
+     *
101
+     * @param bool $new
102
+     *
103
+     * @return  BladeEnvironment
104
+     */
105
+    public function getEngine($new = false)
106
+    {
107
+        if (!$this->engine || $new) {
108
+            $this->engine = new BladeEnvironment($this->getResolver(), $this->getFinder(), $this->getDispatcher());
109
+
110
+            /** @var BladeCompiler $bladeCompiler */
111
+            $bladeCompiler = $this->getCompiler()->getCompiler();
112
+
113
+            foreach (GlobalContainer::getCompilers() as $name => $callback) {
114
+                BladeExtending::extend($bladeCompiler, $name, $callback);
115
+            }
116
+
117
+            foreach ($this->getCustomCompilers() as $name => $callback) {
118
+                BladeExtending::extend($bladeCompiler, $name, $callback);
119
+            }
120
+
121
+            foreach (GlobalContainer::getExtensions() as $name => $callback) {
122
+                $bladeCompiler->extend($callback);
123
+            }
124
+
125
+            // B/C for 4.* and 5.*
126
+            if (($rawTags = GlobalContainer::getRawTags()) && is_callable([$bladeCompiler, 'setRawTags'])) {
127
+                $bladeCompiler->setRawTags($rawTags[0], $rawTags[1]);
128
+            }
129
+
130
+            if ($tags = GlobalContainer::getContentTags()) {
131
+                $bladeCompiler->setContentTags($tags[0], $tags[1]);
132
+            }
133
+
134
+            if ($tags = GlobalContainer::getEscapedTags()) {
135
+                $bladeCompiler->setEscapedContentTags($tags[0], $tags[1]);
136
+            }
137
+        }
138
+
139
+        return $this->engine;
140
+    }
141
+
142
+    /**
143
+     * Method to set property blade
144
+     *
145
+     * @param   BladeEnvironment $blade
146
+     *
147
+     * @return  static  Return self to support chaining.
148
+     */
149
+    public function setEngine($blade)
150
+    {
151
+        if (!($blade instanceof BladeEnvironment)) {
152
+            throw new \InvalidArgumentException('Engine object should be Illuminate\View\Environment.');
153
+        }
154
+
155
+        $this->engine = $blade;
156
+
157
+        return $this;
158
+    }
159
+
160
+    /**
161
+     * Method to get property Filesystem
162
+     *
163
+     * @return  Filesystem
164
+     */
165
+    public function getFilesystem()
166
+    {
167
+        if (!$this->filesystem) {
168
+            $this->filesystem = new Filesystem();
169
+        }
170
+
171
+        return $this->filesystem;
172
+    }
173
+
174
+    /**
175
+     * Method to set property filesystem
176
+     *
177
+     * @param   Filesystem $filesystem
178
+     *
179
+     * @return  static  Return self to support chaining.
180
+     */
181
+    public function setFilesystem($filesystem)
182
+    {
183
+        $this->filesystem = $filesystem;
184
+
185
+        return $this;
186
+    }
187
+
188
+    /**
189
+     * Method to get property Finder
190
+     *
191
+     * @return  FileViewFinder
192
+     */
193
+    public function getFinder()
194
+    {
195
+        if (!$this->finder) {
196
+            $this->finder = new FileViewFinder($this->getFilesystem(), $this->dumpPaths());
197
+        }
198
+
199
+        return $this->finder;
200
+    }
201
+
202
+    /**
203
+     * Method to set property finder
204
+     *
205
+     * @param   FileViewFinder $finder
206
+     *
207
+     * @return  static  Return self to support chaining.
208
+     */
209
+    public function setFinder($finder)
210
+    {
211
+        $this->finder = $finder;
212
+
213
+        return $this;
214
+    }
215
+
216
+    /**
217
+     * Method to get property Resolver
218
+     *
219
+     * @return  EngineResolver
220
+     */
221
+    public function getResolver()
222
+    {
223
+        if (!$this->resolver) {
224
+            $self = $this;
225
+
226
+            $this->resolver = new EngineResolver();
227
+
228
+            $this->resolver->register(
229
+                'blade',
230
+                function () use ($self) {
231
+                    return $self->getCompiler();
232
+                }
233
+            );
234
+        }
235
+
236
+        return $this->resolver;
237
+    }
238
+
239
+    /**
240
+     * Method to set property resolver
241
+     *
242
+     * @param   EngineResolver $resolver
243
+     *
244
+     * @return  static  Return self to support chaining.
245
+     */
246
+    public function setResolver($resolver)
247
+    {
248
+        $this->resolver = $resolver;
249
+
250
+        return $this;
251
+    }
252
+
253
+    /**
254
+     * Method to get property Dispatcher
255
+     *
256
+     * @return  Dispatcher
257
+     */
258
+    public function getDispatcher()
259
+    {
260
+        if (!$this->dispatcher) {
261
+            $this->dispatcher = new Dispatcher();
262
+        }
263
+
264
+        return $this->dispatcher;
265
+    }
266
+
267
+    /**
268
+     * Method to set property dispatcher
269
+     *
270
+     * @param   Dispatcher $dispatcher
271
+     *
272
+     * @return  static  Return self to support chaining.
273
+     */
274
+    public function setDispatcher($dispatcher)
275
+    {
276
+        $this->dispatcher = $dispatcher;
277
+
278
+        return $this;
279
+    }
280
+
281
+    /**
282
+     * Method to get property Compiler
283
+     *
284
+     * @return  CompilerEngine
285
+     */
286
+    public function getCompiler()
287
+    {
288
+        if (!$this->compiler) {
289
+            $cachePath = $this->config->get('cache_path') ?: GlobalContainer::getCachePath();
290
+
291
+            if (!$cachePath) {
292
+                throw new \InvalidArgumentException('Please set cache_path into config.');
293
+            }
294
+
295
+            if (!is_dir($cachePath)) {
296
+                mkdir($cachePath, 0755, true);
297
+            }
298
+
299
+            $this->compiler = new CompilerEngine(new BladeCompiler($this->getFilesystem(), $cachePath));
300
+        }
301
+
302
+        return $this->compiler;
303
+    }
304
+
305
+    /**
306
+     * Method to set property compiler
307
+     *
308
+     * @param   CompilerEngine $compiler
309
+     *
310
+     * @return  static  Return self to support chaining.
311
+     */
312
+    public function setCompiler($compiler)
313
+    {
314
+        $this->compiler = $compiler;
315
+
316
+        return $this;
317
+    }
318
+
319
+    /**
320
+     * addCustomCompiler
321
+     *
322
+     * @param   string   $name
323
+     * @param   callable $compiler
324
+     *
325
+     * @return  static
326
+     */
327
+    public function addCustomCompiler($name, $compiler)
328
+    {
329
+        if (!is_callable($compiler)) {
330
+            throw new \InvalidArgumentException('Compiler should be callable.');
331
+        }
332
+
333
+        $this->customCompilers[$name] = $compiler;
334
+
335
+        return $this;
336
+    }
337
+
338
+    /**
339
+     * Method to get property CustomCompiler
340
+     *
341
+     * @return  \callable[]
342
+     */
343
+    public function getCustomCompilers()
344
+    {
345
+        return $this->customCompilers;
346
+    }
347
+
348
+    /**
349
+     * Method to set property customCompiler
350
+     *
351
+     * @param   \callable[] $customCompilers
352
+     *
353
+     * @return  static  Return self to support chaining.
354
+     */
355
+    public function setCustomCompilers(array $customCompilers)
356
+    {
357
+        $this->customCompilers = $customCompilers;
358
+
359
+        return $this;
360
+    }
361
+}