|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Templating; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Templating\TemplateReferenceInterface; |
|
|
15 |
use Symfony\Component\Templating\TemplateReference; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* TemplateNameParser is the default implementation of TemplateNameParserInterface. |
|
|
19 |
* |
|
|
20 |
* This implementation takes everything as the template name |
|
|
21 |
* and the extension for the engine. |
|
|
22 |
* |
|
|
23 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
24 |
* |
|
|
25 |
* @api |
|
|
26 |
*/ |
|
|
27 |
class TemplateNameParser implements TemplateNameParserInterface |
|
|
28 |
{ |
|
|
29 |
/** |
|
|
30 |
* Parses a template to an array of parameters. |
|
|
31 |
* |
|
|
32 |
* @param string $name A template name |
|
|
33 |
* |
|
|
34 |
* @return TemplateReferenceInterface A template |
|
|
35 |
* |
|
|
36 |
* @api |
|
|
37 |
*/ |
|
|
38 |
public function parse($name) |
|
|
39 |
{ |
|
|
40 |
if ($name instanceof TemplateReferenceInterface) { |
|
|
41 |
return $name; |
|
|
42 |
} |
|
|
43 |
|
|
|
44 |
$engine = null; |
|
|
45 |
if (false !== $pos = strrpos($name, '.')) { |
|
|
46 |
$engine = substr($name, $pos + 1); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
return new TemplateReference($name, $engine); |
|
|
50 |
} |
|
|
51 |
} |