RouteCompiler.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Symfony\Tests\Component\Routing;
  3. use Symfony\Component\Routing\RouteCompiler as BaseRouteCompiler;
  4. use Symfony\Component\Routing\Route;
  5. class RouteCompiler extends BaseRouteCompiler
  6. {
  7. protected function tokenizeBufferBefore(&$buffer, &$tokens, &$afterASeparator, &$currentSeparator)
  8. {
  9. if ($afterASeparator && preg_match('#^=([\w\d_]+)#', $buffer, $match)) {
  10. // a labelled variable
  11. $this->tokens[] = array('label', $currentSeparator, $match[0], $match[1]);
  12. $currentSeparator = '';
  13. $buffer = substr($buffer, strlen($match[0]));
  14. $afterASeparator = false;
  15. } else {
  16. return false;
  17. }
  18. }
  19. protected function compileForLabel($separator, $name, $variable)
  20. {
  21. if (null === $requirement = $this->route->getRequirement($variable)) {
  22. $requirement = $this->options['variable_content_regex'];
  23. }
  24. $this->segments[] = preg_quote($separator, '#').$variable.$separator.'(?P<'.$variable.'>'.$requirement.')';
  25. $this->variables[$variable] = $name;
  26. if (!$this->route->getDefault($variable)) {
  27. $this->firstOptional = count($this->segments);
  28. }
  29. }
  30. protected function generateForLabel($optional, $tparams, $separator, $name, $variable)
  31. {
  32. if (!empty($tparams[$variable]) && (!$optional || !isset($this->defaults[$variable]) || $tparams[$variable] != $this->defaults[$variable])) {
  33. return $variable.'/'.urlencode($tparams[$variable]);
  34. }
  35. }
  36. }