Skip to content

Commit 6a50af1

Browse files
committed
Add symfony
1 parent fea8502 commit 6a50af1

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

src/Loader.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use TweakPHP\Client\Loaders\ComposerLoader;
66
use TweakPHP\Client\Loaders\LaravelLoader;
77
use TweakPHP\Client\Loaders\LoaderInterface;
8+
use TweakPHP\Client\Loaders\SymfonyLoader;
89
use TweakPHP\Client\Loaders\WordPressLoader;
910

1011
class Loader
@@ -19,14 +20,18 @@ public static function load(string $path)
1920
return new LaravelLoader($path);
2021
}
2122

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);
2425
}
2526

2627
if (file_exists($path . '/wp-load.php')) {
2728
return new WordPressLoader($path);
2829
}
2930

31+
if (file_exists($path . '/vendor/autoload.php')) {
32+
return new ComposerLoader($path);
33+
}
34+
3035
return null;
3136
}
3237
}

src/Loaders/SymfonyLoader.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
}

0 commit comments

Comments
 (0)