Skip to content

Commit

Permalink
Fix Octane Event using handle instead of asListener (lorisleiva#235)
Browse files Browse the repository at this point in the history
* Fix lorisleiva#136 Octane Event use handle instead of asListener

* Create the ActionManager as a scoped singleton instance
  • Loading branch information
dmason30 authored and jaulz committed Jul 27, 2023
1 parent 96ea7e8 commit 25423c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/ActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Application as Artisan;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Foundation\Application;
use Illuminate\Routing\Router;
use Lorisleiva\Actions\Concerns\AsCommand;
use Lorisleiva\Actions\Concerns\AsController;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function getDesignPatternsMatching(array $usedTraits): array
return array_filter($this->getDesignPatterns(), $filter);
}

public function extend(string $abstract): void
public function extend(Application $app, string $abstract): void
{
if ($this->isExtending($abstract)) {
return;
Expand All @@ -88,7 +89,7 @@ public function extend(string $abstract): void
return;
}

app()->extend($abstract, function ($instance) {
$app->extend($abstract, function ($instance) {
return $this->identifyAndDecorate($instance);
});

Expand Down
30 changes: 18 additions & 12 deletions src/ActionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lorisleiva\Actions;

use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Lorisleiva\Actions\Console\MakeActionCommand;
use Lorisleiva\Actions\DesignPatterns\CommandDesignPattern;
Expand All @@ -12,14 +13,15 @@ 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);
$this->app->scoped(ActionManager::class, function () {
return new ActionManager([
new ControllerDesignPattern(),
new ListenerDesignPattern(),
new CommandDesignPattern(),
]);
});

$this->extendActions();
}

public function boot()
Expand All @@ -37,9 +39,13 @@ public function boot()
}
}

protected function extendActions(ActionManager $manager)
protected function extendActions()
{
$this->app->beforeResolving(function ($abstract) use ($manager) {
$this->app->beforeResolving(function ($abstract, $parameters, Application $app) {
if ($abstract === ActionManager::class) {
return;
}

try {
// Fix conflict with package: barryvdh/laravel-ide-helper.
// @see https://github.com/lorisleiva/laravel-actions/issues/142
Expand All @@ -48,11 +54,11 @@ protected function extendActions(ActionManager $manager)
return;
}

if (! $classExists || app()->resolved($abstract)) {
if (! $classExists || $app->resolved($abstract)) {
return;
}

$manager->extend($abstract);
$app->make(ActionManager::class)->extend($app, $abstract);
});
}
}

0 comments on commit 25423c5

Please sign in to comment.