Skip to content

Commit a760b04

Browse files
authored
fix: larastan unable to recognize macro (#30)
1 parent 78b609a commit a760b04

1 file changed

Lines changed: 12 additions & 23 deletions

File tree

src/ServiceProvider.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Intervention\Image\Laravel;
66

7-
use Illuminate\Contracts\Routing\ResponseFactory;
87
use Illuminate\Support\Facades\Response as ResponseFacade;
98
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
109
use Intervention\Image\ImageManager;
@@ -28,17 +27,19 @@ public function boot()
2827
__DIR__ . '/../config/image.php' => config_path(Facades\Image::BINDING . '.php')
2928
]);
3029

31-
$this->app->afterResolving(ResponseFactory::class, function (): void {
32-
// register response macro "image"
33-
if ($this->shouldCreateResponseMacro()) {
34-
ResponseFacade::macro(Facades\Image::BINDING, function (
35-
ImageInterface $image,
36-
null|string|Format|MediaType|FileExtension $format = null,
37-
mixed ...$options,
38-
): Response {
39-
return ImageResponseFactory::make($image, $format, ...$options);
40-
});
30+
// register response macro "image"
31+
ResponseFacade::resolved(function ($factory): void {
32+
if ($factory::hasMacro(Facades\Image::BINDING)) {
33+
return;
4134
}
35+
36+
$factory::macro(Facades\Image::BINDING, function (
37+
ImageInterface $image,
38+
null|string|Format|MediaType|FileExtension $format = null,
39+
mixed ...$options,
40+
): Response {
41+
return ImageResponseFactory::make($image, $format, ...$options);
42+
});
4243
});
4344
}
4445

@@ -64,16 +65,4 @@ public function register()
6465
);
6566
});
6667
}
67-
68-
/**
69-
* Determine if response macro should be created
70-
*/
71-
private function shouldCreateResponseMacro(): bool
72-
{
73-
if (!$this->app->runningUnitTests() && $this->app->runningInConsole()) {
74-
return false;
75-
}
76-
77-
return !ResponseFacade::hasMacro(Facades\Image::BINDING);
78-
}
7968
}

0 commit comments

Comments
 (0)