-
Notifications
You must be signed in to change notification settings - Fork 554
/
LaravelAwareRectorRule.php
44 lines (34 loc) · 1.11 KB
/
LaravelAwareRectorRule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace A17\Twill\Rector;
use Illuminate\Foundation\Application;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Rector\AbstractRector;
abstract class LaravelAwareRectorRule extends AbstractRector implements ConfigurableRectorInterface
{
protected Application $app;
public function configure(array $configuration): void
{
$this->app ??= $this->bootstrapLaravel(
$configuration['path'] ?? getcwd(),
);
}
private function bootstrapLaravel(string $basePath): Application
{
$app = new Application($basePath);
$app->singleton(
\Illuminate\Contracts\Http\Kernel::class,
\App\Http\Kernel::class
);
$app->singleton(
\Illuminate\Contracts\Console\Kernel::class,
\App\Console\Kernel::class
);
$app->singleton(
\Illuminate\Contracts\Debug\ExceptionHandler::class,
\App\Exceptions\Handler::class
);
$kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
return $app;
}
}