-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFilterableServiceProvider.php
More file actions
54 lines (48 loc) 路 1.53 KB
/
Copy pathFilterableServiceProvider.php
File metadata and controls
54 lines (48 loc) 路 1.53 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
<?php
namespace Filterable\Providers;
use Filterable\Console\MakeFilterCommand;
use Illuminate\Http\Request;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
class FilterableServiceProvider extends PackageServiceProvider
{
/**
* {@inheritdoc}
*/
public function configurePackage(Package $package): void
{
$package->name('filterable')
->hasConfigFile('filterable')
->hasCommand(MakeFilterCommand::class);
}
/**
* {@inheritdoc}
*/
public function packageRegistered(): void
{
$this->registerFilterBindings();
}
/**
* Register global bindings for Filter dependencies.
*
* This ensures that when a Filter subclass is resolved from the DI container,
* it receives the current HTTP request instance rather than an empty Request.
*/
protected function registerFilterBindings(): void
{
// Bind Request class to resolve to the current request from the container.
// This ensures Filter subclasses get the active HTTP request instead of an empty one.
// Using bindIf() ensures we don't override any existing Request bindings.
// Tests can still override this by calling $app->instance(Request::class, $request).
$this->app->bindIf(Request::class, function ($app) {
return $app['request'];
});
}
/**
* {@inheritdoc}
*/
protected function getPackageBaseDir(): string
{
return dirname(__DIR__, 2);
}
}