Example #1
0
 /**
  * @covers ::__construct
  * @covers ::setPattern
  * @covers ::getPattern
  */
 public function testPattern()
 {
     $dataSet = new DataSet('JUC (Linux; U; 2.3*) UCWEB8.4*');
     static::assertSame('JUC (Linux; U; 2.3*) UCWEB8.4*', $dataSet->getPattern());
 }
Example #2
0
 /**
  * @param DataSet $dataSet
  *
  * @throws ParserRuntimeException
  */
 protected function processBrowserData(DataSet $dataSet)
 {
     // Get properties and filter them
     $pattern = $dataSet->getPattern();
     $propertiesOriginal = $dataSet->getProperties();
     $properties = $propertiesOriginal;
     $propertyFilter = $this->getPropertyFilter();
     foreach ($properties as $propertyName => $propertyValue) {
         if ($propertyFilter->isFiltered($propertyName)) {
             unset($properties[$propertyName]);
         }
     }
     $browserId = $this->getNextId('browser');
     // Check for placeholders
     $hasBrowscapPlaceholders = strpos($pattern, '*') !== false || strpos($pattern, '?') !== false;
     // Parent patterns do not contain browscap placeholders, so we only need to save some of them for referencing.
     // (Use unmodified pattern here to find them later.)
     if ($hasBrowscapPlaceholders === false) {
         $this->addParentPattern($pattern, $browserId);
     }
     // Get parent id
     $parentId = $this->getParentPatternId($propertiesOriginal);
     // Get property ids (and generate new entries for new properties)
     $propertyIds = $this->getIdsForProperties($properties);
     // Filter the keywords from the pattern (all strings containing of the characters a-z,
     // with at least 4 characters) and count them to check for the most important keywords
     // later.
     if ($hasBrowscapPlaceholders === true) {
         $this->extractKeywordsFromPattern($pattern);
     }
     // Save browser entry
     $this->statements['browser']->execute(['id' => $browserId, 'parent' => $parentId, 'pattern' => $pattern]);
     // Optimization: Do not save patterns that are used as parents, assuming that every 'real' pattern
     // contains a browscap placeholder.
     //
     // We use the GLOB function in Sqlite, but this is case-sensitive. So we lower-case the pattern here
     // (and later, when searching for it).
     if ($hasBrowscapPlaceholders === true) {
         $this->statements['search']->execute(['id' => $browserId, 'length' => strlen(str_replace('*', '', $pattern)), 'pattern' => strtolower($pattern)]);
     }
     // Save all properties for the current pattern
     foreach ($propertyIds as $keyId => $valueId) {
         $this->statements['property']->execute(['id' => $browserId, 'key' => $keyId, 'value' => $valueId]);
     }
 }