Skip to content

Commit

Permalink
Simplify the detectors' parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Nov 30, 2020
1 parent af15ca3 commit 956bc7c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Detectors/DeviceDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,20 @@ class DeviceDetector implements Detector
*/
public function handle(Request $request): Detector
{
$userAgent = $request->server('HTTP_USER_AGENT');
return $this->fromUserAgent(
$request->server('HTTP_USER_AGENT')
);
}

/**
* Handle from the given user agent.
*
* @param string $userAgent
*
* @return $this
*/
public function fromUserAgent(string $userAgent): Detector
{
$this->detector = tap(new BaseDetector($userAgent), function (BaseDetector $detector) {
$detector->parse();
});
Expand Down
15 changes: 14 additions & 1 deletion src/Detectors/LanguageDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,22 @@ public function keys(): array
* @return $this
*/
public function handle(Request $request): Detector
{
return $this->fromAcceptLanguage(
$request->server('HTTP_ACCEPT_LANGUAGE')
);
}

/**
* Handle from the given accept language.
*
* @param string $acceptLanguage
*
* @return $this
*/
public function fromAcceptLanguage(string $acceptLanguage): Detector
{
$this->languages = [];
$acceptLanguage = $request->server('HTTP_ACCEPT_LANGUAGE');

if ( ! empty($acceptLanguage)) {
$this->parse($acceptLanguage);
Expand Down

0 comments on commit 956bc7c

Please sign in to comment.