| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace UserAgentParser\Provider\Http; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use GuzzleHttp\Client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use GuzzleHttp\Psr7\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use stdClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use UserAgentParser\Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use UserAgentParser\Model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Abstraction of neutrinoapi.com | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author Martin Keckeis <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @license MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @see https://51degrees.com | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class FiftyOneDegreesCom extends AbstractHttpProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * Name of the provider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     protected $name = 'FiftyOneDegreesCom'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * Homepage of the provider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     protected $homepage = 'https://51degrees.com'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     protected $detectionCapabilities = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         'browser' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             'name'    => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             'version' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         'renderingEngine' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             'name'    => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             'version' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         'operatingSystem' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             'name'    => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             'version' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         'device' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             'model'    => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             'brand'    => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             'type'     => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             'isMobile' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             'isTouch'  => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         'bot' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             'isBot' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             'name'  => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             'type'  => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     protected $defaultValues = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         'general' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             '/^Unknown$/i', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     private static $uri = 'https://cloud.51degrees.com/api/v1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     private $apiKey; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 18 |  |     public function __construct(Client $client, $apiKey) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 18 |  |         parent::__construct($client); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 18 |  |         $this->apiKey = $apiKey; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 18 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @param  string                     $userAgent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @param  array                      $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @return stdClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @throws Exception\RequestException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 11 |  |     protected function getResult($userAgent, array $headers) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |          * an empty UserAgent makes no sense | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 11 |  |         if ($userAgent == '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 1 |  |             throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 10 |  |         $headers['User-Agent'] = $userAgent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 10 |  |         $parameters = '/' . $this->apiKey; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 10 |  |         $parameters .= '/match?'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 10 |  |         $headerString = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 10 |  |         foreach ($headers as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 10 |  |             $headerString[] = $key . '=' . rawurlencode($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 10 |  |         $parameters .= implode('&', $headerString); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 10 |  |         $uri = self::$uri . $parameters; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 10 |  |         $request = new Request('GET', $uri); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 | 10 |  |             $response = $this->getResponse($request); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 2 |  |         } catch (Exception\RequestException $ex) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             /* @var $prevEx \GuzzleHttp\Exception\ClientException */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 2 |  |             $prevEx = $ex->getPrevious(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 2 |  |             if ($prevEx->hasResponse() === true && $prevEx->getResponse()->getStatusCode() === 403) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 1 |  |                 throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName(), null, $ex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 1 |  |             throw $ex; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |          * no json returned? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 8 |  |         $contentType = $response->getHeader('Content-Type'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 | 8 |  |         if (! isset($contentType[0]) || $contentType[0] != 'application/json; charset=utf-8') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 1 |  |             throw new Exception\RequestException('Could not get valid "application/json; charset=utf-8" response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 | 7 |  |         $content = json_decode($response->getBody()->getContents()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |          * No result | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 | 7 |  |         if (isset($content->MatchMethod) && $content->MatchMethod == 'None') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 | 1 |  |             throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |          * Missing data? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 | 6 |  |         if (! $content instanceof stdClass || ! isset($content->Values)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 | 1 |  |             throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Data is missing "' . $response->getBody()->getContents() . '"'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |          * Convert the values, to something useable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 | 5 |  |         $values              = new \stdClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 5 |  |         $values->MatchMethod = $content->MatchMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 5 |  |         foreach ($content->Values as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 | 5 |  |             if (is_array($value) && count($value) === 1 && isset($value[0])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 | 5 |  |                 $values->{$key} = $value[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 | 5 |  |         foreach ($values as $key => $value) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 | 5 |  |             if ($value === 'True') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 | 2 |  |                 $values->{$key} = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 | 5 |  |             } elseif ($value === 'False') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 | 5 |  |                 $values->{$key} = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 5 |  |         return $values; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * @param Model\Bot $bot | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * @param stdClass  $resultRaw | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 1 |  |     private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 | 1 |  |         $bot->setIsBot(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      * @param Model\Browser $browser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      * @param stdClass      $resultRaw | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 | 4 |  |     private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 | 4 |  |         if (isset($resultRaw->BrowserName)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 | 1 |  |             $browser->setName($this->getRealResult($resultRaw->BrowserName)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 | 4 |  |         if (isset($resultRaw->BrowserVersion)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 | 1 |  |             $browser->getVersion()->setComplete($this->getRealResult($resultRaw->BrowserVersion)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |      * @param Model\RenderingEngine $engine | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |      * @param stdClass              $resultRaw | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 204 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 205 | 4 |  |     private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) | 
            
                                                                        
                            
            
                                    
            
            
                | 206 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 207 | 4 |  |         if (isset($resultRaw->LayoutEngine)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 208 | 1 |  |             $engine->setName($this->getRealResult($resultRaw->LayoutEngine)); | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 210 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |      * @param Model\OperatingSystem $os | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |      * @param stdClass              $resultRaw | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 | 4 |  |     private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 | 4 |  |         if (isset($resultRaw->PlatformName)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 | 1 |  |             $os->setName($this->getRealResult($resultRaw->PlatformName)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 | 4 |  |         if (isset($resultRaw->PlatformVersion)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 | 1 |  |             $os->getVersion()->setComplete($this->getRealResult($resultRaw->PlatformVersion)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |      * @param Model\Device $device | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |      * @param stdClass     $resultRaw | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 | 4 |  |     private function hydrateDevice(Model\Device $device, stdClass $resultRaw) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 | 4 |  |         if (isset($resultRaw->HardwareVendor)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 | 1 |  |             $device->setBrand($this->getRealResult($resultRaw->HardwareVendor)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 | 4 |  |         if (isset($resultRaw->HardwareFamily)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 | 1 |  |             $device->setModel($this->getRealResult($resultRaw->HardwareFamily)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 | 4 |  |         if (isset($resultRaw->DeviceType)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 | 1 |  |             $device->setType($this->getRealResult($resultRaw->DeviceType)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 | 4 |  |         if (isset($resultRaw->IsMobile)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 | 1 |  |             $device->setIsMobile($this->getRealResult($resultRaw->IsMobile)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 | 11 |  |     public function parse($userAgent, array $headers = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 | 11 |  |         $resultRaw = $this->getResult($userAgent, $headers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |          * Hydrate the model | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 | 5 |  |         $result = new Model\UserAgent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 | 5 |  |         $result->setProviderResultRaw($resultRaw); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |          * Bot detection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 | 5 |  |         if (isset($resultRaw->IsCrawler) && $resultRaw->IsCrawler === true) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 | 1 |  |             $this->hydrateBot($result->getBot(), $resultRaw); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 | 1 |  |             return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |          * hydrate the result | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 | 4 |  |         $this->hydrateBrowser($result->getBrowser(), $resultRaw); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 | 4 |  |         $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 | 4 |  |         $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 | 4 |  |         $this->hydrateDevice($result->getDevice(), $resultRaw); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 | 4 |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 278 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 279 |  |  |  |