-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPhptalResolver.php
60 lines (43 loc) · 1.38 KB
/
PhptalResolver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace Neni\PhptalBundle\Phptal;
use Neni\PhptalBundle\Phptal\PhptalResolverInterface;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Templating\TemplateReferenceInterface;
class PhptalResolver implements PhptalResolverInterface
{
protected $parser;
protected $locator;
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser)
{
$this->locator = $locator;
$this->parser = $parser;
}
public function resolve($name)
{
$source = $this->parser->parse($name);
try{
$file = $this->locator->locate($source);
} catch (\InvalidArgumentException $e) {
$erreur = $e;
}
if (false === $file || null === $file) {
throw new \InvalidArgumentException(sprintf('The template "%s" does not exist.', $name, 0, null, $erreur));
}
//return new \PHPTAL_FileSource( $file );
return new \PHPTAL_StringSource( file_get_contents($file) );
}
public function exists($name)
{
try {
$this->resolve($name);
} catch (\InvalidArgumentException $e) {
return false;
}
return true;
}
public function supports($name)
{
return false !== strpos($name, '.tal');
}
}