-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathActionServiceProvider.php
51 lines (43 loc) · 1.46 KB
/
ActionServiceProvider.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
45
46
47
48
49
50
51
<?php
namespace Lorisleiva\Actions;
use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Lorisleiva\Actions\Console\MakeActionCommand;
use Lorisleiva\Actions\DesignPatterns\CommandDesignPattern;
use Lorisleiva\Actions\DesignPatterns\ControllerDesignPattern;
use Lorisleiva\Actions\DesignPatterns\ListenerDesignPattern;
class ActionServiceProvider extends ServiceProvider
{
public function register()
{
$manager = new ActionManager([
new ControllerDesignPattern(),
new ListenerDesignPattern(),
new CommandDesignPattern(),
]);
$this->app->instance(ActionManager::class, $manager);
$this->extendActions($manager);
}
public function boot()
{
if ($this->app->runningInConsole()) {
// publish Stubs File
$this->publishes([
__DIR__ . '/Console/stubs/action.stub' => base_path('stubs/action.stub'),
], 'stubs');
// Register the make:action generator command.
$this->commands([
MakeActionCommand::class,
]);
}
}
protected function extendActions(ActionManager $manager)
{
$this->app->beforeResolving(function ($abstract, $parameters, Application $app) use ($manager) {
if (! class_exists($abstract) || $app->resolved($abstract)) {
return;
}
$manager->extend($abstract);
});
}
}