-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathWorkbenchServiceProvider.php
More file actions
70 lines (59 loc) · 2.57 KB
/
WorkbenchServiceProvider.php
File metadata and controls
70 lines (59 loc) · 2.57 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Orchestra\Workbench;
use Composer\InstalledVersions;
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Http\Kernel as HttpKernel;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Support\Composer;
use Illuminate\Support\ServiceProvider;
use Orchestra\Canvas\Core\PresetManager;
use Orchestra\Testbench\Foundation\Events\ServeCommandEnded;
use Orchestra\Testbench\Foundation\Events\ServeCommandStarted;
use function Orchestra\Sidekick\Filesystem\join_paths;
class WorkbenchServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$this->app->bind('workbench.composer', static fn () => new Composer(new Filesystem));
$this->app->singleton(Contracts\RecipeManager::class, static fn (Application $app) => new RecipeManager($app));
$this->callAfterResolving(PresetManager::class, static function ($manager) {
$manager->extend('workbench', fn (Application $app) => new GeneratorPreset($app));
$manager->setDefaultDriver('workbench');
});
AboutCommand::add('Workbench', static fn () => array_filter([
'Version' => InstalledVersions::getPrettyVersion('orchestra/workbench'),
]));
}
/**
* Bootstrap services.
*/
public function boot(): void
{
$this->booted(function () {
$this->loadRoutesFrom((string) realpath(join_paths(__DIR__, '..', 'routes', 'workbench.php')));
});
/** @phpstan-ignore method.notFound */
$this->app->make(HttpKernel::class)->pushMiddleware(Http\Middleware\CatchDefaultRoute::class);
if ($this->app->runningInConsole()) {
$this->commands([
Console\BuildCommand::class,
Console\CreateSqliteDbCommand::class,
Console\DropSqliteDbCommand::class,
Console\InstallCommand::class,
Console\DevToolCommand::class,
Console\PurgeSkeletonCommand::class,
Console\ScheduleWorkCommand::class,
Console\SyncSkeletonCommand::class,
]);
tap($this->app->make('events'), static function (EventDispatcher $event) {
$event->listen(ServeCommandStarted::class, [Listeners\AddAssetSymlinkFolders::class, 'handle']);
$event->listen(ServeCommandEnded::class, [Listeners\RemoveAssetSymlinkFolders::class, 'handle']);
});
}
}
}