Skip to content

Commit

Permalink
feat: Add UserAgentCheck constructor accepting an array of user agents
Browse files Browse the repository at this point in the history
This commit refactors the `UserAgentCheck` class by adding a constructor that accepts an array of user agents. The constructor now loops through the user agents and adds them to the respective arrays (`browsers` or `bots`) based on their type. This change improves the convenience of the `UserAgentCheck` class.
  • Loading branch information
secondtruth committed May 17, 2024
1 parent a29fccb commit 0cf672c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/Check/UserAgentCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ class UserAgentCheck extends AbstractCheck
*/
protected $bots = [];

/**
* Constructor.
*
* @param UserAgentInterface[] $userAgents The UserAgent objects to use
*
* @throws \InvalidArgumentException If an unsupported user agent type is given.
*/
public function __construct(array $userAgents = [])
{
foreach ($userAgents as $userAgent) {
if ($userAgent instanceof BrowserInterface) {
$this->browsers[] = $userAgent;
} elseif ($userAgent instanceof BotInterface) {
$this->bots[] = $userAgent;
} else {
throw new \InvalidArgumentException('Unsupported user agent type');
}
}
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 0cf672c

Please sign in to comment.