Ei kuvausta

PhpMatcherDumper.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Routing\Matcher\Dumper;
  11. @trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.3, use "CompiledUrlMatcherDumper" instead.', PhpMatcherDumper::class), \E_USER_DEPRECATED);
  12. /**
  13. * PhpMatcherDumper creates a PHP class able to match URLs for a given set of routes.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. * @author Tobias Schultze <http://tobion.de>
  17. * @author Arnaud Le Blanc <arnaud.lb@gmail.com>
  18. * @author Nicolas Grekas <p@tchwork.com>
  19. *
  20. * @deprecated since Symfony 4.3, use CompiledUrlMatcherDumper instead.
  21. */
  22. class PhpMatcherDumper extends CompiledUrlMatcherDumper
  23. {
  24. /**
  25. * Dumps a set of routes to a PHP class.
  26. *
  27. * Available options:
  28. *
  29. * * class: The class name
  30. * * base_class: The base class name
  31. *
  32. * @param array $options An array of options
  33. *
  34. * @return string A PHP class representing the matcher class
  35. */
  36. public function dump(array $options = [])
  37. {
  38. $options = array_replace([
  39. 'class' => 'ProjectUrlMatcher',
  40. 'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
  41. ], $options);
  42. $code = parent::dump();
  43. $code = preg_replace('#\n ([^ ].*?) // \$(\w++)$#m', "\n \$this->$2 = $1", $code);
  44. $code = str_replace(",\n $", ";\n $", $code);
  45. $code = substr($code, strpos($code, '$this') - 4, -5).";\n";
  46. $code = preg_replace('/^ \$this->\w++ = (?:null|false|\[\n \]);\n/m', '', $code);
  47. $code = str_replace("\n ", "\n ", "\n".$code);
  48. return <<<EOF
  49. <?php
  50. use Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherTrait;
  51. use Symfony\Component\Routing\RequestContext;
  52. /**
  53. * This class has been auto-generated
  54. * by the Symfony Routing Component.
  55. */
  56. class {$options['class']} extends {$options['base_class']}
  57. {
  58. use CompiledUrlMatcherTrait;
  59. public function __construct(RequestContext \$context)
  60. {
  61. \$this->context = \$context;{$code} }
  62. }
  63. EOF;
  64. }
  65. }