Changeset 24021
- Timestamp:
- 11/16/09 16:31:23 (4 years ago)
- Files:
-
- branches/1.3/lib/routing/sfRoute.class.php (modified) (5 diffs)
- branches/1.4/lib/routing/sfRoute.class.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.3/lib/routing/sfRoute.class.php
r23995 r24021 29 29 $options = array(), 30 30 $pattern = null, 31 $staticPrefix = null, 31 32 $regex = null, 32 33 $variables = array(), … … 98 99 } 99 100 100 if (!preg_match($this->regex, $url, $matches)) 101 // check the static prefix uf the URL first. Only use the more expensive preg_match when it matches 102 if (0 !== strpos($url, $this->staticPrefix) || !preg_match($this->regex, $url, $matches)) 101 103 { 102 104 return false; … … 451 453 } 452 454 453 $this->regex = "#^ \n".implode("\n", $this->segments)."\n".preg_quote($separator, '#')."$#x";455 $this->regex = "#^".implode("", $this->segments)."".preg_quote($separator, '#')."$#x"; 454 456 } 455 457 … … 477 479 $this->segments[$i] = (0 == $i ? '/?' : '').str_repeat(' ', $i - $this->firstOptional).'(?:'.$this->segments[$i]; 478 480 $this->segments[] = str_repeat(' ', $max - $i - 1).')?'; 481 } 482 483 $this->staticPrefix = ''; 484 foreach ($this->tokens as $token) 485 { 486 switch ($token[0]) 487 { 488 case 'separator': 489 // separator is static 490 $this->staticPrefix .= $token[2]; 491 break; 492 case 'text': 493 if ($token[2] !== '*') 494 { 495 // non-star text is static 496 $this->staticPrefix .= $token[2]; 497 break; 498 } 499 default: 500 // everything else indicates variable parts. break switch and for loop 501 break 2; 502 } 479 503 } 480 504 } … … 789 813 $this->compile(); 790 814 // sfPatternRouting will always re-set defaultParameters, so no need to serialize them 791 return serialize(array($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this-> regex, $this->variables, $this->defaults, $this->requirements, $this->suffix));815 return serialize(array($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this->staticPrefix, $this->regex, $this->variables, $this->defaults, $this->requirements, $this->suffix)); 792 816 } 793 817 794 818 public function unserialize($data) 795 819 { 796 list($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this-> regex, $this->variables, $this->defaults, $this->requirements, $this->suffix) = unserialize($data);820 list($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this->staticPrefix, $this->regex, $this->variables, $this->defaults, $this->requirements, $this->suffix) = unserialize($data); 797 821 $this->compiled = true; 798 822 } branches/1.4/lib/routing/sfRoute.class.php
r23995 r24021 29 29 $options = array(), 30 30 $pattern = null, 31 $staticPrefix = null, 31 32 $regex = null, 32 33 $variables = array(), … … 98 99 } 99 100 100 if (!preg_match($this->regex, $url, $matches)) 101 // check the static prefix uf the URL first. Only use the more expensive preg_match when it matches 102 if (0 !== strpos($url, $this->staticPrefix) || !preg_match($this->regex, $url, $matches)) 101 103 { 102 104 return false; … … 451 453 } 452 454 453 $this->regex = "#^ \n".implode("\n", $this->segments)."\n".preg_quote($separator, '#')."$#x";455 $this->regex = "#^".implode("", $this->segments)."".preg_quote($separator, '#')."$#x"; 454 456 } 455 457 … … 477 479 $this->segments[$i] = (0 == $i ? '/?' : '').str_repeat(' ', $i - $this->firstOptional).'(?:'.$this->segments[$i]; 478 480 $this->segments[] = str_repeat(' ', $max - $i - 1).')?'; 481 } 482 483 $this->staticPrefix = ''; 484 foreach ($this->tokens as $token) 485 { 486 switch ($token[0]) 487 { 488 case 'separator': 489 // separator is static 490 $this->staticPrefix .= $token[2]; 491 break; 492 case 'text': 493 if ($token[2] !== '*') 494 { 495 // non-star text is static 496 $this->staticPrefix .= $token[2]; 497 break; 498 } 499 default: 500 // everything else indicates variable parts. break switch and for loop 501 break 2; 502 } 479 503 } 480 504 } … … 789 813 $this->compile(); 790 814 // sfPatternRouting will always re-set defaultParameters, so no need to serialize them 791 return serialize(array($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this-> regex, $this->variables, $this->defaults, $this->requirements, $this->suffix));815 return serialize(array($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this->staticPrefix, $this->regex, $this->variables, $this->defaults, $this->requirements, $this->suffix)); 792 816 } 793 817 794 818 public function unserialize($data) 795 819 { 796 list($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this-> regex, $this->variables, $this->defaults, $this->requirements, $this->suffix) = unserialize($data);820 list($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this->staticPrefix, $this->regex, $this->variables, $this->defaults, $this->requirements, $this->suffix) = unserialize($data); 797 821 $this->compiled = true; 798 822 }