1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,59 +0,0 @@ |
1 |
-<?php declare(strict_types=1); |
|
2 |
-/** |
|
3 |
- * Part of Windwalker project. |
|
4 |
- * |
|
5 |
- * @copyright Copyright (C) 2019 LYRASOFT. |
|
6 |
- * @license GNU General Public License version 2 or later. |
|
7 |
- */ |
|
8 |
- |
|
9 |
-namespace Windwalker\Renderer\Blade; |
|
10 |
- |
|
11 |
-use Illuminate\View\Compilers\BladeCompiler; |
|
12 |
- |
|
13 |
-/** |
|
14 |
- * The Extending class to support both Blade 4.* and 5.*. |
|
15 |
- * |
|
16 |
- * @since 2.1.1 |
|
17 |
- */ |
|
18 |
-class BladeExtending |
|
19 |
-{ |
|
20 |
- /** |
|
21 |
- * extend |
|
22 |
- * |
|
23 |
- * @param BladeCompiler $blade |
|
24 |
- * @param string $name |
|
25 |
- * @param callable $closure |
|
26 |
- * |
|
27 |
- * @return void |
|
28 |
- */ |
|
29 |
- public static function extend(BladeCompiler $blade, $name, $closure) |
|
30 |
- { |
|
31 |
- // For 5.0 after |
|
32 |
- if (is_callable([$blade, 'directive'])) { |
|
33 |
- $blade->directive($name, $closure); |
|
34 |
- |
|
35 |
- return; |
|
36 |
- } |
|
37 |
- |
|
38 |
- // For 4.x before |
|
39 |
- $blade->extend( |
|
40 |
- function ($view, BladeCompiler $compiler) use ($name, $closure) { |
|
41 |
- $pattern = $compiler->createMatcher($name); |
|
42 |
- |
|
43 |
- return preg_replace_callback( |
|
44 |
- $pattern, |
|
45 |
- function ($matches) use ($closure) { |
|
46 |
- if (empty($matches[2])) { |
|
47 |
- return $matches[0]; |
|
48 |
- } |
|
49 |
- |
|
50 |
- return $matches[1] . $closure($matches[2]); |
|
51 |
- }, |
|
52 |
- $view |
|
53 |
- ); |
|
54 |
- } |
|
55 |
- ); |
|
56 |
- |
|
57 |
- return; |
|
58 |
- } |
|
59 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,59 @@ |
1 |
+<?php declare(strict_types=1); |
|
2 |
+/** |
|
3 |
+ * Part of Windwalker project. |
|
4 |
+ * |
|
5 |
+ * @copyright Copyright (C) 2019 LYRASOFT. |
|
6 |
+ * @license GNU General Public License version 2 or later. |
|
7 |
+ */ |
|
8 |
+ |
|
9 |
+namespace Windwalker\Renderer\Blade; |
|
10 |
+ |
|
11 |
+use Illuminate\View\Compilers\BladeCompiler; |
|
12 |
+ |
|
13 |
+/** |
|
14 |
+ * The Extending class to support both Blade 4.* and 5.*. |
|
15 |
+ * |
|
16 |
+ * @since 2.1.1 |
|
17 |
+ */ |
|
18 |
+class BladeExtending |
|
19 |
+{ |
|
20 |
+ /** |
|
21 |
+ * extend |
|
22 |
+ * |
|
23 |
+ * @param BladeCompiler $blade |
|
24 |
+ * @param string $name |
|
25 |
+ * @param callable $closure |
|
26 |
+ * |
|
27 |
+ * @return void |
|
28 |
+ */ |
|
29 |
+ public static function extend(BladeCompiler $blade, $name, $closure) |
|
30 |
+ { |
|
31 |
+ // For 5.0 after |
|
32 |
+ if (is_callable([$blade, 'directive'])) { |
|
33 |
+ $blade->directive($name, $closure); |
|
34 |
+ |
|
35 |
+ return; |
|
36 |
+ } |
|
37 |
+ |
|
38 |
+ // For 4.x before |
|
39 |
+ $blade->extend( |
|
40 |
+ function ($view, BladeCompiler $compiler) use ($name, $closure) { |
|
41 |
+ $pattern = $compiler->createMatcher($name); |
|
42 |
+ |
|
43 |
+ return preg_replace_callback( |
|
44 |
+ $pattern, |
|
45 |
+ function ($matches) use ($closure) { |
|
46 |
+ if (empty($matches[2])) { |
|
47 |
+ return $matches[0]; |
|
48 |
+ } |
|
49 |
+ |
|
50 |
+ return $matches[1] . $closure($matches[2]); |
|
51 |
+ }, |
|
52 |
+ $view |
|
53 |
+ ); |
|
54 |
+ } |
|
55 |
+ ); |
|
56 |
+ |
|
57 |
+ return; |
|
58 |
+ } |
|
59 |
+} |