TemplateNameParser.php 958 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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\Templating;
  11. /**
  12. * TemplateNameParser is the default implementation of TemplateNameParserInterface.
  13. *
  14. * This implementation takes everything as the template name
  15. * and the extension for the engine.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class TemplateNameParser implements TemplateNameParserInterface
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function parse($name)
  25. {
  26. if ($name instanceof TemplateReferenceInterface) {
  27. return $name;
  28. }
  29. $engine = null;
  30. if (false !== $pos = strrpos($name, '.')) {
  31. $engine = substr($name, $pos + 1);
  32. }
  33. return new TemplateReference($name, $engine);
  34. }
  35. }