Skip to content

Commit

Permalink
Updating the package
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Aug 30, 2020
1 parent ded41ac commit cb51a47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arcanedev/agent",
"description": "A PHP user agent parser based on Mobiledetect.",
"description": "Agent is a PHP/Laravel package for detecting devices/bots via the http request.",
"keywords": ["arcanedev", "laravel", "mobile", "detect", "detector", "devices", "user agent"],
"homepage": "https://github.com/ARCANEDEV/Agent",
"authors": [
Expand Down
28 changes: 26 additions & 2 deletions src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ protected function detectors(): array
return $this->app['config']['agent.detectors'];
}

/**
* Get the supported detectors
*
* @return array
*/
protected function supportedDetectors(): array
{
return array_keys($this->detectors());
}

/**
* @param string $key
*
Expand Down Expand Up @@ -124,13 +134,27 @@ public function parse(Request $request = null): AgentContract
$this->setRequest($request);
}

foreach ($this->detectors() as $key => $detector) {
$this->parsed[$key] = call_user_func_array([$this->app->make($detector['driver']), 'handle'], [$this->getRequest()]);
foreach ($this->supportedDetectors() as $detector) {
$this->parsed[$detector] = $this->detector($detector)->handle($this->getRequest());
}

return $this;
}

/**
* Make a detector.
*
* @param string $key
*
* @return \Arcanedev\Agent\Contracts\Detector
*/
public function detector(string $key): Detector
{
$detector = $this->detectors()[$key];

return $this->app->make($detector['driver']);
}

/* -----------------------------------------------------------------
| Check Methods
| -----------------------------------------------------------------
Expand Down

0 comments on commit cb51a47

Please sign in to comment.