-
Notifications
You must be signed in to change notification settings - Fork 0
/
Liquid.php
52 lines (46 loc) · 1.19 KB
/
Liquid.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
<?php
declare(strict_types=1);
namespace Shippinno\Template;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Liquid\Exception\ParseException;
use Liquid\Exception\RenderException;
use Liquid\Template as LiquidTemplate;
class Liquid extends Template
{
/**
* @var LiquidTemplate
*/
private $liquid;
/**
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $filesystem)
{
parent::__construct($filesystem);
if ($filesystem->getAdapter() instanceof Local) {
$path = $filesystem->getAdapter()->getPathPrefix();
} else {
$path = null;
}
$this->liquid = new LiquidTemplate($path);
}
/**
* {@inheritdoc}
*/
public function renderSource(string $source, array $variables): string
{
try {
return $this->liquid->parse($source)->render($variables);
} catch (ParseException|RenderException $e) {
throw new RenderFailedException($source, $e);
}
}
/**
* {@inheritdoc}
*/
protected function fileName(string $templateName): string
{
return $templateName . '.liquid';
}
}