Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Octane Event using handle instead of asListener #235

Merged
merged 2 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -69,7 +70,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 @@ -79,7 +80,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);
});
}
}