1 | <?php |
||
13 | trait TemplateEngineDependent |
||
14 | { |
||
15 | protected $importDependencies = []; |
||
16 | |||
17 | protected $dataDependencies = []; |
||
18 | |||
19 | /** @var TemplateBridgeInterface */ |
||
20 | protected $templateEngine; |
||
21 | |||
22 | /** |
||
23 | * Set the template engine used to parse the body of the document. |
||
24 | * |
||
25 | * @param TemplateBridgeInterface $templateEngine |
||
26 | * |
||
27 | * @return $this |
||
28 | */ |
||
29 | public function setTemplateEngine(TemplateBridgeInterface $templateEngine) |
||
35 | |||
36 | /** |
||
37 | * Pass the document's body through the template engine. |
||
38 | * |
||
39 | * @param string $bodyContent |
||
40 | * |
||
41 | * @throws TemplateErrorInterface |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | 7 | protected function parseTemplateLanguage($bodyContent) |
|
46 | { |
||
47 | 7 | if ($this->templateEngine !== null) |
|
48 | { |
||
49 | $this->importDependencies = $this->templateEngine->getTemplateImportDependencies($bodyContent); |
||
50 | $this->dataDependencies = [ |
||
51 | 'collections' => $this->templateEngine->getAssortmentDependencies('collections', $bodyContent), |
||
52 | 'data' => $this->templateEngine->getAssortmentDependencies('data', $bodyContent), |
||
53 | ]; |
||
54 | |||
55 | $template = $this->templateEngine->createTemplate($bodyContent); |
||
56 | |||
57 | return $template->render(); |
||
58 | } |
||
59 | |||
60 | 7 | return $bodyContent; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Check whether this object has a reference to a collection or data item. |
||
65 | * |
||
66 | * @param string $namespace 'collections' or 'data' |
||
67 | * @param string $needle |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function hasDependencyOnCollection($namespace, $needle) |
||
77 | |||
78 | /** |
||
79 | * Check whether this object has an "import" or "from" reference to a given path. |
||
80 | * |
||
81 | * @param string $filePath |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | public function hasDependencyOnTemplateImport($filePath) |
||
89 | |||
90 | /** |
||
91 | * @return string[] |
||
92 | */ |
||
93 | public function getImportDependencies() |
||
97 | |||
98 | /** |
||
99 | * @return string[] |
||
100 | */ |
||
101 | public function getCollectionDependencies() |
||
105 | } |
||
106 |