Ejemplo n.º 1
0
 /**
  * Client
  *
  * @param string $product
  * @param float|int|string|null $version
  * @param int|null $statusCode
  * @return UserAgentClient
  */
 public function client($product = self::USER_AGENT, $version = null, $statusCode = null)
 {
     $userAgentString = $version === null ? $product : $product . '/' . $version;
     $match = $userAgentString;
     if (!isset($this->handler[$userAgentString])) {
         // User-agent does not match any rule sets
         $userAgentParser = new UserAgentStringParser($product, $version);
         if (($match = $userAgentParser->getMostSpecific($this->getUserAgents())) === false) {
             $match = self::USER_AGENT;
         }
     }
     return new UserAgentClient($this->handler[$match], $this->base, $statusCode, $product);
 }
Ejemplo n.º 2
0
 /**
  * Delay client
  *
  * @param string $baseUri
  * @param string $userAgent
  * @param float|int $delay
  * @return Client\Delay\ClientInterface
  * @throws DatabaseException
  */
 public function delayClient($baseUri, $userAgent, $delay)
 {
     $parser = new UserAgentParser($userAgent);
     $userAgent = strtolower($parser->getProduct());
     switch ($this->driver) {
         case self::DRIVER_MYSQL:
             $this->initialCheck(self::TABLE_DELAY);
             return new Client\Delay\MySQL\Client($this->pdo, $baseUri, $userAgent, $delay);
     }
     throw new DatabaseException('Unsupported database. ' . $this->config[self::TABLE_DELAY]['readme']);
 }
Ejemplo n.º 3
0
 /**
  * Find the most rule-matching User-Agent
  *
  * @return string
  */
 protected function matchUserAgent()
 {
     $userAgentParser = new UserAgentParser($this->userAgent);
     $this->userAgentMatch = ($match = $userAgentParser->getMostSpecific(array_keys($this->rules))) !== false ? $match : self::USER_AGENT;
     return $this->userAgentMatch;
 }