/**
  * {@inheritdoc}
  */
 public function identify(TrackingVisit $trackingVisit)
 {
     $userIdentifier = $trackingVisit->getParsedUID() > 0 ? $trackingVisit->getParsedUID() : $this->parse($trackingVisit->getUserIdentifier());
     if ($userIdentifier) {
         $result = ['parsedUID' => $userIdentifier, 'targetObject' => null];
         $channel = $trackingVisit->getTrackingWebsite()->getChannel();
         $target = $this->em->getRepository($this->getIdentityTarget())->findOneBy(['originId' => $userIdentifier, 'dataChannel' => $channel]);
         if ($target) {
             $result['targetObject'] = $target;
         }
         return $result;
     }
     return null;
 }
示例#2
0
 /**
  * @param TrackingVisit $visit
  * @param string        $ua
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * because of ternary operators which in current case is clear enough to replace it with 'if' statement.
  */
 protected function processUserAgentString(TrackingVisit $visit, $ua)
 {
     $device = $this->deviceDetector->getInstance($ua);
     $os = $device->getOs();
     if (is_array($os)) {
         $visit->setOs(isset($os['name']) ? $os['name'] : null);
         $visit->setOsVersion(isset($os['version']) ? $os['version'] : null);
     }
     $client = $device->getClient();
     if (is_array($client)) {
         $visit->setClient(isset($client['name']) ? $client['name'] : null);
         $visit->setClientType(isset($client['type']) ? $client['type'] : null);
         $visit->setClientVersion(isset($client['version']) ? $client['version'] : null);
     }
     $visit->setDesktop($device->isDesktop());
     $visit->setMobile($device->isMobile());
     $visit->setBot($device->isBot());
 }
 public function testIdentify()
 {
     $visit = new TrackingVisit();
     $visit->setUserIdentifier('id=118; email=test@test.com; visitor-id=89');
     $channel = new Channel();
     $website = new TestTrackingWebsite();
     $website->setChannel($channel);
     $visit->setTrackingWebsite($website);
     $result = new \stdClass();
     $repo = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->once())->method('getRepository')->willReturn($repo);
     $repo->expects($this->once())->method('findOneBy')->with(['originId' => 118, 'dataChannel' => $channel])->willReturn($result);
     $this->assertEquals(['parsedUID' => 118, 'targetObject' => $result], $this->provider->identify($visit));
 }
示例#4
0
 public function testId()
 {
     $this->assertNull($this->trackingVisit->getId());
 }