-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileSystemLoader.php
56 lines (45 loc) · 1.58 KB
/
FileSystemLoader.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
<?php
namespace Matt9mg\Concrete5\Symfony\Form;
use Symfony\Component\Templating\Loader\FilesystemLoader as BaseFilesystemLoader;
use Symfony\Component\Templating\Storage\FileStorage;
use Symfony\Component\Templating\TemplateReferenceInterface;
/**
* Class FilesystemLoader
* @package Matt9mg\Concrete5\Symfony\Form
*/
class FilesystemLoader extends BaseFilesystemLoader
{
/**
* {@inheritdoc}
*/
public function load(TemplateReferenceInterface $template)
{
$file = $template->getPath();
if (self::isAbsolutePath($file) && is_file($file)) {
return new FileStorage($file);
}
$replacements = array();
foreach ($template->all() as $key => $value) {
$replacements['%'.$key.'%'] = $value;
}
$fileFailures = array();
foreach ($this->templatePathPatterns as $templatePathPattern) {
if (is_file($file = strtr($templatePathPattern, $replacements)) && is_readable($file)) {
if (null !== $this->logger) {
$this->logger->debug('Loaded template file.', array('file' => $file));
}
return new FileStorage($file);
}
if (null !== $this->logger) {
$fileFailures[] = $file;
}
}
// only log failures if no template could be loaded at all
foreach ($fileFailures as $file) {
if (null !== $this->logger) {
$this->logger->debug('Failed loading template file.', array('file' => $file));
}
}
return false;
}
}