Skip to content

Commit a38eff9

Browse files
authored
Merge pull request #20 from tweakphp/feature/add-plain-php-loader
Add support for plain PHP projects
2 parents ef6094c + b895455 commit a38eff9

5 files changed

Lines changed: 40 additions & 2 deletions

File tree

index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
}
1414

1515
$customLoader = Cli::getArgument('loader');
16-
$loader = Loader::load($arguments[1], $customLoader);
16+
$loader = Loader::load($arguments[1], $customLoader ?: null);
1717

1818
if ($loader === null) {
19-
echo 'Invalid path'.PHP_EOL;
19+
echo 'No supported project found. Make sure the path contains a Composer project (vendor/autoload.php).'.PHP_EOL;
2020
exit(1);
2121
}
2222

src/Loader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use TweakPHP\Client\Loaders\LaravelLoader;
77
use TweakPHP\Client\Loaders\LoaderInterface;
88
use TweakPHP\Client\Loaders\PimcoreLoader;
9+
use TweakPHP\Client\Loaders\PlainPhpLoader;
910
use TweakPHP\Client\Loaders\SymfonyLoader;
1011
use TweakPHP\Client\Loaders\WordPressLoader;
1112

@@ -44,6 +45,10 @@ public static function load(string $path, ?string $encodedLoader = null)
4445
return new ComposerLoader($path);
4546
}
4647

48+
if (PlainPhpLoader::supports($path)) {
49+
return new PlainPhpLoader($path);
50+
}
51+
4752
return null;
4853
}
4954

src/Loaders/BaseLoader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public function execute(string $code): array
4141
return $this->tinker->execute($code);
4242
}
4343

44+
public function executeStreaming(string $code): void
45+
{
46+
$this->tinker->executeStreaming($code);
47+
}
48+
4449
public function casters(): array
4550
{
4651
return [];

src/Loaders/LoaderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public function init(): void;
1414

1515
public function execute(string $code): array;
1616

17+
public function executeStreaming(string $code): void;
18+
1719
public function casters(): array;
1820
}

src/Loaders/PlainPhpLoader.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace TweakPHP\Client\Loaders;
4+
5+
class PlainPhpLoader extends BaseLoader
6+
{
7+
public static function supports(string $path): bool
8+
{
9+
return is_dir($path);
10+
}
11+
12+
public function __construct(string $path)
13+
{
14+
chdir($path);
15+
}
16+
17+
public function name(): string
18+
{
19+
return 'PHP';
20+
}
21+
22+
public function version(): string
23+
{
24+
return '';
25+
}
26+
}

0 commit comments

Comments
 (0)