Exemple #1
0
 public function testParent()
 {
     $parentroute = new GitPHP_Route('parent/:parent', array('parent' => 'parentvalue'), array('parentparam' => 'parentvalue'));
     $childroute = new GitPHP_Route('child/:child', array('child' => 'childvalue'), array('childparam' => 'childvalue'), $parentroute);
     $this->assertEquals('parent/:parent/child/:child', $childroute->GetPath());
     $params = array('child' => 'childvalue');
     $this->assertFalse($childroute->Valid($params));
     $params['parent'] = 'parentvalue';
     $this->assertTrue($childroute->Valid($params));
     $usedparams = $childroute->GetUsedParameters();
     $this->assertCount(4, $usedparams);
     $this->assertContains('parent', $usedparams);
     $this->assertContains('child', $usedparams);
     $this->assertContains('parentparam', $usedparams);
     $this->assertContains('childparam', $usedparams);
     $routeparams = $childroute->Match('parent/parentvalue/child/childvalue');
     $this->assertCount(4, $routeparams);
     $this->assertEquals('parentvalue', $routeparams['parent']);
     $this->assertEquals('childvalue', $routeparams['child']);
     $this->assertEquals('parentvalue', $routeparams['parentparam']);
     $this->assertEquals('childvalue', $routeparams['childparam']);
     $this->assertEquals('parent/parentvalue/child/childvalue', $childroute->Build($params));
 }
Exemple #2
0
 /**
  * Compare routes for precedence
  *
  * @param GitPHP_Route $a route a
  * @param GitPHP_Route $b route b
  */
 public static function CompareRoute($a, $b)
 {
     $apath = $a->GetPath();
     $bpath = $b->GetPath();
     $acount = substr_count($apath, ':');
     $bcount = substr_count($bpath, ':');
     if ($acount == $bcount) {
         $acount2 = substr_count($apath, '/');
         $bcount2 = substr_count($bpath, '/');
         if ($acount2 == $bcount2) {
             return 0;
         }
         return $acount2 < $bcount2 ? 1 : -1;
     }
     return $acount < $bcount ? 1 : -1;
 }