TemplateNameParser.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. use Symfony\Component\Templating\TemplateReferenceInterface;
  12. use Symfony\Component\Templating\TemplateReference;
  13. /**
  14. * TemplateNameParser is the default implementation of TemplateNameParserInterface.
  15. *
  16. * This implementation takes everything as the template name
  17. * and the extension for the engine.
  18. *
  19. * @author Fabien Potencier <fabien@symfony.com>
  20. *
  21. * @api
  22. */
  23. class TemplateNameParser implements TemplateNameParserInterface
  24. {
  25. /**
  26. * Parses a template to an array of parameters.
  27. *
  28. * @param string $name A template name
  29. *
  30. * @return TemplateReferenceInterface A template
  31. *
  32. * @api
  33. */
  34. public function parse($name)
  35. {
  36. if ($name instanceof TemplateReferenceInterface) {
  37. return $name;
  38. }
  39. $engine = null;
  40. if (false !== $pos = strrpos($name, '.')) {
  41. $engine = substr($name, $pos + 1);
  42. }
  43. return new TemplateReference($name, $engine);
  44. }
  45. }