Author: Dave Olsen, http://dmolsen.com
Inheritance: implements BrowscapPHP\Util\Logfile\ReaderInterface
コード例 #1
0
 /**
  * @expectedException \BrowscapPHP\Exception\ReaderException
  * @expectedExceptionMessage Cannot extract user agent string from line "Test"
  */
 public function testReadNotSuccessFull()
 {
     $reader = $this->getMock('\\BrowscapPHP\\Util\\Logfile\\ApacheCommonLogFormatReader', array('test', 'read'), array(), '', false);
     $reader->expects(self::once())->method('test')->will(self::returnValue(false));
     $reader->expects(self::never())->method('read')->will(self::returnValue('TestUA'));
     $this->object->addReader($reader);
     $this->object->read('Test');
 }
コード例 #2
0
 /**
  * @expectedException \BrowscapPHP\Exception\ReaderException
  * @expectedExceptionMessage Cannot extract user agent string from line "Test"
  */
 public function testReadNotSuccessFull()
 {
     $reader = $this->getMockBuilder(\BrowscapPHP\Util\Logfile\ApacheCommonLogFormatReader::class)->disableOriginalConstructor()->setMethods(['test', 'read'])->getMock();
     $reader->expects(self::once())->method('test')->will(self::returnValue(false));
     $reader->expects(self::never())->method('read')->will(self::returnValue('TestUA'));
     $this->object->addReader($reader);
     $this->object->read('Test');
 }
コード例 #3
0
 /**
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param \BrowscapPHP\Util\Logfile\ReaderCollection        $collection
  * @param \BrowscapPHP\Browscap                             $browscap
  * @param int                                               $line
  *
  * @throws UnknownBrowserException
  * @throws UnknownBrowserTypeException
  * @throws UnknownDeviceException
  * @throws UnknownEngineException
  * @throws UnknownPlatformException
  * @throws \Exception
  */
 private function handleLine(OutputInterface $output, ReaderCollection $collection, Browscap $browscap, $line)
 {
     $userAgentString = '';
     try {
         $userAgentString = $collection->read($line);
         try {
             $this->getResult($browscap->getBrowser($userAgentString));
         } catch (\Exception $e) {
             $this->undefinedClients[] = $userAgentString;
             throw $e;
         }
         $type = '.';
         ++$this->countOk;
     } catch (ReaderException $e) {
         $type = 'E';
         ++$this->countNok;
     } catch (UnknownBrowserTypeException $e) {
         $type = 'T';
         ++$this->countNok;
     } catch (UnknownBrowserException $e) {
         $type = 'B';
         ++$this->countNok;
     } catch (UnknownPlatformException $e) {
         $type = 'P';
         ++$this->countNok;
     } catch (UnknownDeviceException $e) {
         $type = 'D';
         ++$this->countNok;
     } catch (UnknownEngineException $e) {
         $type = 'N';
         ++$this->countNok;
     } catch (\Exception $e) {
         $type = 'U';
         ++$this->countNok;
     }
     $this->outputProgress($output, $type);
     // count all useragents
     if (isset($this->uas[$userAgentString])) {
         ++$this->uas[$userAgentString];
     } else {
         $this->uas[$userAgentString] = 1;
     }
     if ('.' !== $type && 'E' !== $type) {
         // count all undetected useragents grouped by detection error
         if (!isset($this->uasWithType[$type])) {
             $this->uasWithType[$type] = [];
         }
         if (isset($this->uasWithType[$type][$userAgentString])) {
             ++$this->uasWithType[$type][$userAgentString];
         } else {
             $this->uasWithType[$type][$userAgentString] = 1;
         }
     }
 }