Changeset 8806
- Timestamp:
- 05/06/08 15:52:58 (5 months ago)
- Files:
-
- branches/1.1/lib/routing/sfPatternRouting.class.php (modified) (4 diffs)
- branches/1.1/lib/routing/sfRouting.class.php (modified) (1 diff)
- branches/1.1/test/unit/routing/sfPatternRoutingTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/routing/sfPatternRouting.class.php
r8093 r8806 595 595 public function parse($url) 596 596 { 597 if (null !== $routeInfo = $this->findRoute($url)) 598 { 599 // store the route name 600 $this->currentRouteName = $routeInfo['name']; 601 $this->currentRouteParameters = $routeInfo['parameters']; 602 $this->currentInternalUri = array(); 603 604 if ($this->options['logging']) 605 { 606 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Match route [%s] for "%s"', $routeInfo['name'], $routeInfo['route'])))); 607 } 608 } 609 else 610 { 611 throw new sfError404Exception(sprintf('No matching route found for "%s"', $url)); 612 } 613 614 return $this->currentRouteParameters; 615 } 616 617 618 /** 619 * Finds a matching route for given URL. 620 * Returned array contains: 621 * - name : name or alias of the route that matched 622 * - route : the actual matching route 623 * - parameters : array containing key value pairs of the request parameters including defaults 624 * 625 * @param string URL to be parsed 626 * 627 * @return array An array with routing information or null if no route matched 628 */ 629 public function findRoute($url) 630 { 597 631 // an URL should start with a '/', mod_rewrite doesn't respect that, but no-mod_rewrite version does. 598 632 if ('/' != $url[0]) … … 619 653 } 620 654 621 $ found = false;655 $routeInfo = null; 622 656 foreach ($this->routes as $routeName => $route) 623 657 { … … 629 663 630 664 $defaults = array_merge($defaults, $this->defaultParameters); 631 $found = true;632 665 $out = array(); 633 666 … … 651 684 } 652 685 653 // store the route name 654 $this->currentRouteName = $routeName; 655 $this->currentInternalUri = array(); 656 657 if ($this->options['logging']) 658 { 659 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Match route [%s] for "%s"', $routeName, $route)))); 660 } 661 686 $routeInfo['name'] = $routeName; 687 $routeInfo['route'] = $route; 688 $routeInfo['parameters'] = $this->fixDefaults($out); 689 if (!is_null($this->cache)) 690 { 691 $this->cacheChanged = true; 692 $this->cacheData[$cacheKey] = $routeInfo; 693 } 662 694 break; 663 695 } 664 696 665 // no route found 666 if (!$found) 667 { 668 throw new sfError404Exception(sprintf('No matching route found for "%s"', $url)); 669 } 670 671 $this->currentRouteParameters = $this->fixDefaults($out); 672 673 if (!is_null($this->cache)) 674 { 675 $this->cacheChanged = true; 676 $this->cacheData[$cacheKey] = $this->currentRouteParameters; 677 } 678 679 return $this->currentRouteParameters; 697 return $routeInfo; 680 698 } 681 699 branches/1.1/lib/routing/sfRouting.class.php
r8464 r8806 148 148 149 149 /** 150 * Parses a URL to find a matching route .150 * Parses a URL to find a matching route and sets internal state. 151 151 * 152 152 * Throws a sfError404Exception if no route match the URL. branches/1.1/test/unit/routing/sfPatternRoutingTest.php
r7901 r8806 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(1 29, new lime_output_color());13 $t = new lime_test(135, new lime_output_color()); 14 14 15 15 class sfPatternRoutingTest extends sfPatternRouting … … 453 453 $t->is($r->getCurrentInternalUri(false), 'foo/bar?id=2', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); 454 454 455 // regression for ticket #3423 occuring when cache is used. (for the test its enough to have it non null) 456 $rCached = new sfPatternRoutingTest(new sfEventDispatcher(),new sfNoCache()); 457 $rCached->connect('test', '/:module', array('action' => 'index')); 458 $rCached->connect('test2', '/', array()); 459 $rCached->parse('/'); 460 $t->is($rCached->getCurrentInternalUri(), 'default/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL using cache'); 461 $rCached->parse('/test'); 462 $t->is($rCached->getCurrentInternalUri(), 'test/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL using cache'); 463 $rCached->parse('/'); 464 $t->is($rCached->getCurrentInternalUri(), 'default/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL using cache'); 465 // findRoute was added to be the side effectless version to check an uri 466 $t->is($rCached->findRoute('/test'), 467 array('name' => 'test', 'route' => '/:module', 'parameters' => array('action' => 'index', 'module' => 'test')), 468 '->findRoute() returns information about matching route'); 469 $t->is($rCached->getCurrentInternalUri(), 'default/index', '->findRoute() does not change the internal URI of sfPatternRouting'); 470 $t->is($rCached->findRoute('/no/match/found'), null, '->findRoute() returns null on non-matching route'); 471 455 472 // defaults 456 473 $t->diag('defaults');