@@ 46-61 (lines=16) @@ | ||
43 | * |
|
44 | * @throws Twig_Error_Loader When $path is not found |
|
45 | */ |
|
46 | public function getSource($path) |
|
47 | { |
|
48 | try { |
|
49 | // The "loaded_by_puli" tag makes it possible to recognize node |
|
50 | // trees of templates loaded through this loader. In this way, we |
|
51 | // can turn relative Puli paths into absolute ones in those |
|
52 | // templates. The "loaded_by_puli" tag is removed early on by the |
|
53 | // PuliDirTagger visitor and does not appear in the final |
|
54 | // output. |
|
55 | return '{% loaded_by_puli %}'.$this->getResource($path)->getBody(); |
|
56 | } catch (ResourceNotFoundException $e) { |
|
57 | throw new Twig_Error_Loader($e->getMessage(), -1, null, $e); |
|
58 | } catch (InvalidArgumentException $e) { |
|
59 | throw new Twig_Error_Loader($e->getMessage(), -1, null, $e); |
|
60 | } |
|
61 | } |
|
62 | ||
63 | /** |
|
64 | * Gets the cache key to use for the cache for a given template name. |
|
@@ 72-89 (lines=18) @@ | ||
69 | * |
|
70 | * @throws Twig_Error_Loader When $path is not found |
|
71 | */ |
|
72 | public function getCacheKey($path) |
|
73 | { |
|
74 | try { |
|
75 | // Even though the path and $path are the same, call the locator to |
|
76 | // make sure that the path actually exists |
|
77 | // The result of this method MUST NOT be the real path (without |
|
78 | // prefix), because then the generated file has the same cache |
|
79 | // key as the same template loaded through a different loader. |
|
80 | // If loaded through a different loader, relative paths won't be |
|
81 | // resolved, so we'll have the wrong version of the template in |
|
82 | // he cache. |
|
83 | return '__puli__'.$this->getResource($path)->getPath(); |
|
84 | } catch (ResourceNotFoundException $e) { |
|
85 | throw new Twig_Error_Loader($e->getMessage(), -1, null, $e); |
|
86 | } catch (InvalidArgumentException $e) { |
|
87 | throw new Twig_Error_Loader($e->getMessage(), -1, null, $e); |
|
88 | } |
|
89 | } |
|
90 | ||
91 | /** |
|
92 | * Returns true if the template is still fresh. |
|
@@ 101-110 (lines=10) @@ | ||
98 | * |
|
99 | * @throws Twig_Error_Loader When $path is not found |
|
100 | */ |
|
101 | public function isFresh($path, $time) |
|
102 | { |
|
103 | try { |
|
104 | return $this->getResource($path)->getMetadata()->getModificationTime() <= $time; |
|
105 | } catch (ResourceNotFoundException $e) { |
|
106 | throw new Twig_Error_Loader($e->getMessage(), -1, null, $e); |
|
107 | } catch (InvalidArgumentException $e) { |
|
108 | throw new Twig_Error_Loader($e->getMessage(), -1, null, $e); |
|
109 | } |
|
110 | } |
|
111 | ||
112 | /** |
|
113 | * Check if we have the source code of a template, given its name. |