PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php

https://github.com/casoetan/ServerGroveLiveChat
PHP | 82 lines | 51 code | 7 blank | 24 comment | 1 complexity | 693a79e98c9ff3d66b193bb3c7822ab6 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, ISC, BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Bundle\FrameworkBundle\Templating;
  11. use Symfony\Component\Templating\TemplateNameParser as BaseTemplateNameParser;
  12. use Symfony\Component\HttpKernel\KernelInterface;
  13. /**
  14. * TemplateNameParser parsers template name from the short notation
  15. * "bundle:section:template.engine.format" to an array of
  16. * template parameters.
  17. *
  18. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  19. */
  20. class TemplateNameParser extends BaseTemplateNameParser
  21. {
  22. protected $kernel;
  23. /**
  24. * Constructor.
  25. *
  26. * @param KernelInterface $kernel A KernelInterface instance
  27. */
  28. public function __construct(KernelInterface $kernel)
  29. {
  30. $this->kernel = $kernel;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function parse($name)
  36. {
  37. if (is_array($name)) {
  38. return $name;
  39. }
  40. // normalize name
  41. $name = str_replace(':/' , ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')));
  42. if (false !== strpos($name, '..')) {
  43. throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
  44. }
  45. $parts = explode(':', $name);
  46. if (3 !== count($parts)) {
  47. throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.engine.format").', $name));
  48. }
  49. $elements = explode('.', $parts[2]);
  50. if (3 !== count($elements)) {
  51. throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.engine.format").', $name));
  52. }
  53. $parameters = array(
  54. 'bundle' => $parts[0],
  55. 'controller' => $parts[1],
  56. 'name' => $elements[0],
  57. 'format' => $elements[1],
  58. 'engine' => $elements[2],
  59. );
  60. if ($parameters['bundle']) {
  61. try {
  62. $this->kernel->getBundle($parameters['bundle']);
  63. } catch (\Exception $e) {
  64. throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
  65. }
  66. }
  67. return $parameters;
  68. }
  69. }