File tree Expand file tree Collapse file tree 2 files changed +67
-2
lines changed Expand file tree Collapse file tree 2 files changed +67
-2
lines changed Original file line number Diff line number Diff line change 5
5
use TweakPHP \Client \Loaders \ComposerLoader ;
6
6
use TweakPHP \Client \Loaders \LaravelLoader ;
7
7
use TweakPHP \Client \Loaders \LoaderInterface ;
8
+ use TweakPHP \Client \Loaders \SymfonyLoader ;
8
9
use TweakPHP \Client \Loaders \WordPressLoader ;
9
10
10
11
class Loader
@@ -19,14 +20,18 @@ public static function load(string $path)
19
20
return new LaravelLoader ($ path );
20
21
}
21
22
22
- if (file_exists ($ path . '/vendor/autoload.php ' )) {
23
- return new ComposerLoader ($ path );
23
+ if (file_exists ($ path . '/vendor/autoload.php ' ) && file_exists ( $ path . ' /symfony.lock ' ) && file_exists ( $ path . ' /src/Kernel.php ' ) ) {
24
+ return new SymfonyLoader ($ path );
24
25
}
25
26
26
27
if (file_exists ($ path . '/wp-load.php ' )) {
27
28
return new WordPressLoader ($ path );
28
29
}
29
30
31
+ if (file_exists ($ path . '/vendor/autoload.php ' )) {
32
+ return new ComposerLoader ($ path );
33
+ }
34
+
30
35
return null ;
31
36
}
32
37
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace TweakPHP \Client \Loaders ;
4
+
5
+ class SymfonyLoader extends ComposerLoader
6
+ {
7
+ private $ kernel ;
8
+
9
+ /**
10
+ * @param string $path
11
+ */
12
+ public function __construct (string $ path )
13
+ {
14
+ parent ::__construct ($ path );
15
+
16
+ // Include the Composer autoloader
17
+ require_once $ path . '/vendor/autoload.php ' ;
18
+
19
+ // Initialize the Symfony Kernel
20
+ $ env = $ _SERVER ['APP_ENV ' ] ?? 'dev ' ;
21
+ $ debug = ($ _SERVER ['APP_DEBUG ' ] ?? '1 ' ) === '1 ' ;
22
+
23
+ $ kernelClass = $ this ->findKernelClass ($ path );
24
+ $ this ->kernel = new $ kernelClass ($ env , $ debug );
25
+ $ this ->kernel ->boot ();
26
+ }
27
+
28
+ /**
29
+ * Find the application's Kernel class dynamically.
30
+ *
31
+ * @param string $path
32
+ * @return string
33
+ */
34
+ private function findKernelClass (string $ path ): string
35
+ {
36
+ $ kernelFile = $ path . '/src/Kernel.php ' ;
37
+ if (!file_exists ($ kernelFile )) {
38
+ throw new \RuntimeException ('Kernel.php file not found in the src directory. ' );
39
+ }
40
+
41
+ require_once $ kernelFile ;
42
+ return 'App \\Kernel ' ;
43
+ }
44
+
45
+ /**
46
+ * @return string
47
+ */
48
+ public function name (): string
49
+ {
50
+ return 'Symfony ' ;
51
+ }
52
+
53
+ /**
54
+ * @return string
55
+ */
56
+ public function version (): string
57
+ {
58
+ return \Symfony \Component \HttpKernel \Kernel::VERSION ;
59
+ }
60
+ }
You can’t perform that action at this time.
0 commit comments