Esempio n. 1
0
 public function testLeafRouteTreeNode()
 {
     $matcher = $this->mock(AbstractMatcher::class);
     $contents = new MatchedRouteDataMap();
     $node = new RouteTreeNode([$matcher], $contents);
     $this->assertSame([$matcher], $node->getMatchers());
     $this->assertSame($matcher, $node->getFirstMatcher());
     $this->assertSame($contents, $node->getContents());
     $this->assertTrue($node->isLeafNode());
     $this->assertFalse($node->isParentNode());
 }
 /**
  * @param \Viserio\Routing\Generator\RouteTreeNode $node1
  * @param \Viserio\Routing\Generator\RouteTreeNode $node2
  *
  * @return \Viserio\Routing\Generator\RouteTreeNode|null
  */
 protected function extractCommonParentNode(RouteTreeNode $node1, RouteTreeNode $node2)
 {
     $matcherCompare = function (SegmentMatcherContract $matcher, SegmentMatcherContract $matcher2) {
         return strcmp($matcher->getHash(), $matcher2->getHash());
     };
     $commonMatchers = array_uintersect_assoc($node1->getMatchers(), $node2->getMatchers(), $matcherCompare);
     if (empty($commonMatchers)) {
         return;
     }
     $children = [];
     $nodes = [$node1, $node2];
     foreach ($nodes as $node) {
         $specificMatchers = array_udiff_assoc($node->getMatchers(), $commonMatchers, $matcherCompare);
         $duplicateMatchers = array_uintersect_assoc($node->getMatchers(), $commonMatchers, $matcherCompare);
         foreach ($duplicateMatchers as $segmentDepth => $matcher) {
             $commonMatchers[$segmentDepth]->mergeParameterKeys($matcher);
         }
         if (empty($specificMatchers) && $node->isParentNode()) {
             foreach ($node->getContents()->getChildren() as $childNode) {
                 $children[] = $childNode;
             }
         } else {
             $children[] = $node->update($specificMatchers, $node->getContents());
         }
     }
     return new RouteTreeNode($commonMatchers, new ChildrenNodeCollection($children));
 }