예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function getIndexableRulesByUserAgentToken(UserAgentTokenizedToken $token)
 {
     $this->loadRules();
     $rules = new \SplObjectStorage();
     /** @var NodeInterface $node */
     foreach ($token->getData() as $node) {
         if (isset($this->rules['indexable'][$node->getValue()][0])) {
             foreach ($this->rules['indexable'][$node->getValue()][0] as $rule) {
                 if (!$rules->contains($rule)) {
                     $rules->attach($rule);
                 }
             }
         }
     }
     $rules->rewind();
     return $rules;
 }
예제 #2
0
 function it_find_occurrences(RepositoryInterface $repository, ComparerInterface $comparer, UserAgentTokenizedToken $token, Rule $rule)
 {
     $this->beConstructedWith($repository, $comparer);
     $node1 = new Node('chrome', 0, Node::TYPE_TEXT);
     $node2 = new Node('/', 1, Node::TYPE_TEXT);
     $node3 = new Node('12.05b', 2, Node::TYPE_TEXT);
     $token->getData()->shouldBeCalled()->willReturn(array($node1, $node2, $node3));
     $condition = new Condition();
     $condition->setPosition(0);
     $conditions = new \ArrayIterator(array($condition));
     $rule->getConditions()->shouldBeCalled()->willReturn($conditions);
     $repository->getIndexableRulesByUserAgentToken(Argument::exact($token->getWrappedObject()))->shouldBeCalled()->willReturn(array($rule));
     $comparer->areEquals(Argument::exact($node1), Argument::exact($condition))->shouldBeCalled()->willReturn(true);
     $comparer->areEquals(Argument::exact($node2), Argument::exact($condition))->shouldBeCalled()->willReturn(false);
     $comparer->areEquals(Argument::exact($node3), Argument::exact($condition))->shouldBeCalled()->willReturn(true);
     $occurrences = $this->find($token);
     $occurrences->shouldBeAnInstanceOf('DeviceDetectorIO\\DeviceDetector\\Rule\\Occurrence\\Occurrences');
     $firstOccurrences = $occurrences->getFirstOccurrences();
     $firstOccurrences->shouldHaveCount(2);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function find(UserAgentTokenizedToken $token)
 {
     $nodes = $token->getData();
     $rules = $this->repository->getIndexableRulesByUserAgentToken($token);
     $occurences = new Occurrences();
     /** @var RuleInterface $rule */
     foreach ($rules as $rule) {
         /** @var NodeInterface $node */
         foreach ($nodes as $node) {
             $conditions = $rule->getConditions();
             $conditions->rewind();
             /** @var ConditionInterface $condition */
             foreach ($conditions as $condition) {
                 if ($this->comparer->areEquals($node, $condition)) {
                     $occurences->add(new Occurrence($rule, $condition, $node));
                 }
             }
         }
     }
     return $occurences;
 }
 function it_return_indexable_rules(UserAgentTokenizedToken $token)
 {
     $node = new Node('chrome', 0, Node::TYPE_TEXT);
     $token->getData()->shouldBeCalled()->willReturn(array($node));
     $this->getIndexableRulesByUserAgentToken($token)->shouldBeAnInstanceOf('\\Iterator');
 }