Skip to content

Commit 0dfdf18

Browse files
committed
feat: LoaderInterface::supports
1 parent 4467dbc commit 0dfdf18

File tree

6 files changed

+52
-10
lines changed

6 files changed

+52
-10
lines changed

src/Loader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ class Loader
1616
*/
1717
public static function load(string $path)
1818
{
19-
if (file_exists($path . '/vendor/autoload.php') && file_exists($path . '/bootstrap/app.php')) {
19+
if (LaravelLoader::supports($path)) {
2020
return new LaravelLoader($path);
2121
}
2222

23-
if (file_exists($path . '/vendor/autoload.php') && file_exists($path . '/symfony.lock') && file_exists($path . '/src/Kernel.php')) {
23+
if (SymfonyLoader::supports($path)) {
2424
return new SymfonyLoader($path);
2525
}
2626

27-
if (file_exists($path . '/wp-load.php')) {
27+
if (WordPressLoader::supports($path)) {
2828
return new WordPressLoader($path);
2929
}
3030

31-
if (file_exists($path . '/vendor/autoload.php')) {
31+
if (ComposerLoader::supports($path)) {
3232
return new ComposerLoader($path);
3333
}
3434

3535
return null;
3636
}
37-
}
37+
}

src/Loaders/ComposerLoader.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
class ComposerLoader extends BaseLoader
66
{
7+
/**
8+
* @param string $path
9+
* @return bool
10+
*/
11+
public static function supports(string $path): bool
12+
{
13+
return file_exists($path . '/vendor/autoload.php');
14+
}
15+
716
/**
817
* @param string $path
918
*/
@@ -24,4 +33,4 @@ public function version(): string
2433
{
2534
return "";
2635
}
27-
}
36+
}

src/Loaders/LaravelLoader.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ class LaravelLoader extends ComposerLoader
88
{
99
private $app;
1010

11+
/**
12+
* @param string $path
13+
* @return bool
14+
*/
15+
public static function supports(string $path): bool
16+
{
17+
return file_exists($path . '/vendor/autoload.php') && file_exists($path . '/bootstrap/app.php');
18+
}
19+
1120
/**
1221
* @param string $path
1322
*/
@@ -47,4 +56,4 @@ public function version(): string
4756
{
4857
return $this->app->version();
4958
}
50-
}
59+
}

src/Loaders/LoaderInterface.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
interface LoaderInterface
66
{
7+
/**
8+
* @param string $path
9+
* @return bool
10+
*/
11+
public static function supports(string $path): bool;
12+
713
/**
814
* @return string
915
*/
@@ -24,4 +30,4 @@ public function init();
2430
* @return void
2531
*/
2632
public function execute(string $code);
27-
}
33+
}

src/Loaders/SymfonyLoader.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ class SymfonyLoader extends ComposerLoader
66
{
77
private $kernel;
88

9+
/**
10+
* @param string $path
11+
* @return bool
12+
*/
13+
public static function supports(string $path): bool
14+
{
15+
return file_exists($path . '/vendor/autoload.php') && file_exists($path . '/symfony.lock') && file_exists($path . '/src/Kernel.php');
16+
}
17+
918
/**
1019
* @param string $path
1120
*/
@@ -57,4 +66,4 @@ public function version(): string
5766
{
5867
return \Symfony\Component\HttpKernel\Kernel::VERSION;
5968
}
60-
}
69+
}

src/Loaders/WordPressLoader.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
class WordPressLoader extends BaseLoader
88
{
9+
/**
10+
* @param string $path
11+
* @return bool
12+
*/
13+
public static function supports(string $path): bool
14+
{
15+
return file_exists($path . '/wp-load.php');
16+
}
17+
918
/**
1019
* @param string $path
1120
*/
@@ -34,4 +43,4 @@ public function version(): string
3443

3544
return "";
3645
}
37-
}
46+
}

0 commit comments

Comments
 (0)