-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacing the use of the
globalOptions
method with middleware
- Loading branch information
1 parent
615e356
commit f743d80
Showing
4 changed files
with
58 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,19 @@ | |
|
||
return [ | ||
'global' => [ | ||
'user_agent' => env( | ||
'APP_USER_AGENT', | ||
sprintf( | ||
'%s / %s - %s | %s', | ||
env('APP_NAME', 'Laravel'), | ||
Version::detect(), | ||
env('APP_URL', 'http://localhost'), | ||
env('MAIL_FROM_ADDRESS', '[email protected]') | ||
'user_agent' => [ | ||
'enabled' => (bool)env('APP_USER_AGENT_ENABLED', true), | ||
|
||
'value' => env( | ||
'APP_USER_AGENT', | ||
sprintf( | ||
'%s / %s - %s | %s', | ||
env('APP_NAME', 'Laravel'), | ||
Version::detect(), | ||
env('APP_URL', 'http://localhost'), | ||
env('MAIL_FROM_ADDRESS', '[email protected]') | ||
) | ||
) | ||
), | ||
], | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DragonCode\LaravelHttpUserAgent\Middlewares; | ||
|
||
use Psr\Http\Message\RequestInterface; | ||
|
||
use function config; | ||
|
||
class SetHeaderMiddleware | ||
{ | ||
public function __invoke(RequestInterface $request): RequestInterface | ||
{ | ||
if ($this->enabled()) { | ||
return $request->withHeader('User-Agent', $this->value()); | ||
} | ||
|
||
return $request; | ||
} | ||
|
||
protected function enabled(): bool | ||
{ | ||
return config('http.global.user_agent.enabled'); | ||
} | ||
|
||
protected function value(): string | ||
{ | ||
return config('http.global.user_agent.value'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters