PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.22.0
Independent Analytics – WordPress Analytics Plugin v1.22.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / league / plates / src / Engine.php
independent-analytics / vendor / league / plates / src Last commit date
Exception 3 years ago Extension 3 years ago Template 3 years ago Engine.php 3 years ago
Engine.php
267 lines
1 <?php
2
3 namespace IAWP_SCOPED\League\Plates;
4
5 use IAWP_SCOPED\League\Plates\Extension\ExtensionInterface;
6 use IAWP_SCOPED\League\Plates\Template\Data;
7 use IAWP_SCOPED\League\Plates\Template\Directory;
8 use IAWP_SCOPED\League\Plates\Template\FileExtension;
9 use IAWP_SCOPED\League\Plates\Template\Folders;
10 use IAWP_SCOPED\League\Plates\Template\Func;
11 use IAWP_SCOPED\League\Plates\Template\Functions;
12 use IAWP_SCOPED\League\Plates\Template\Name;
13 use IAWP_SCOPED\League\Plates\Template\ResolveTemplatePath;
14 use IAWP_SCOPED\League\Plates\Template\Template;
15 use IAWP_SCOPED\League\Plates\Template\Theme;
16 /**
17 * Template API and environment settings storage.
18 */
19 class Engine
20 {
21 /**
22 * Default template directory.
23 * @var Directory
24 */
25 protected $directory;
26 /**
27 * Template file extension.
28 * @var FileExtension
29 */
30 protected $fileExtension;
31 /**
32 * Collection of template folders.
33 * @var Folders
34 */
35 protected $folders;
36 /**
37 * Collection of template functions.
38 * @var Functions
39 */
40 protected $functions;
41 /**
42 * Collection of preassigned template data.
43 * @var Data
44 */
45 protected $data;
46 /** @var ResolveTemplatePath */
47 private $resolveTemplatePath;
48 /**
49 * Create new Engine instance.
50 * @param string $directory
51 * @param string $fileExtension
52 */
53 public function __construct($directory = null, $fileExtension = 'php')
54 {
55 $this->directory = new Directory($directory);
56 $this->fileExtension = new FileExtension($fileExtension);
57 $this->folders = new Folders();
58 $this->functions = new Functions();
59 $this->data = new Data();
60 $this->resolveTemplatePath = new ResolveTemplatePath\NameAndFolderResolveTemplatePath();
61 }
62 public static function fromTheme(Theme $theme, string $fileExtension = 'php') : self
63 {
64 $engine = new self(null, $fileExtension);
65 $engine->setResolveTemplatePath(new ResolveTemplatePath\ThemeResolveTemplatePath($theme));
66 return $engine;
67 }
68 public function setResolveTemplatePath(ResolveTemplatePath $resolveTemplatePath)
69 {
70 $this->resolveTemplatePath = $resolveTemplatePath;
71 return $this;
72 }
73 public function getResolveTemplatePath() : ResolveTemplatePath
74 {
75 return $this->resolveTemplatePath;
76 }
77 /**
78 * Set path to templates directory.
79 * @param string|null $directory Pass null to disable the default directory.
80 * @return Engine
81 */
82 public function setDirectory($directory)
83 {
84 $this->directory->set($directory);
85 return $this;
86 }
87 /**
88 * Get path to templates directory.
89 * @return string
90 */
91 public function getDirectory()
92 {
93 return $this->directory->get();
94 }
95 /**
96 * Set the template file extension.
97 * @param string|null $fileExtension Pass null to manually set it.
98 * @return Engine
99 */
100 public function setFileExtension($fileExtension)
101 {
102 $this->fileExtension->set($fileExtension);
103 return $this;
104 }
105 /**
106 * Get the template file extension.
107 * @return string
108 */
109 public function getFileExtension()
110 {
111 return $this->fileExtension->get();
112 }
113 /**
114 * Add a new template folder for grouping templates under different namespaces.
115 * @param string $name
116 * @param string $directory
117 * @param boolean $fallback
118 * @return Engine
119 */
120 public function addFolder($name, $directory, $fallback = \false)
121 {
122 $this->folders->add($name, $directory, $fallback);
123 return $this;
124 }
125 /**
126 * Remove a template folder.
127 * @param string $name
128 * @return Engine
129 */
130 public function removeFolder($name)
131 {
132 $this->folders->remove($name);
133 return $this;
134 }
135 /**
136 * Get collection of all template folders.
137 * @return Folders
138 */
139 public function getFolders()
140 {
141 return $this->folders;
142 }
143 /**
144 * Add preassigned template data.
145 * @param array $data;
146 * @param null|string|array $templates;
147 * @return Engine
148 */
149 public function addData(array $data, $templates = null)
150 {
151 $this->data->add($data, $templates);
152 return $this;
153 }
154 /**
155 * Get all preassigned template data.
156 * @param null|string $template;
157 * @return array
158 */
159 public function getData($template = null)
160 {
161 return $this->data->get($template);
162 }
163 /**
164 * Register a new template function.
165 * @param string $name;
166 * @param callable $callback;
167 * @return Engine
168 */
169 public function registerFunction($name, $callback)
170 {
171 $this->functions->add($name, $callback);
172 return $this;
173 }
174 /**
175 * Remove a template function.
176 * @param string $name;
177 * @return Engine
178 */
179 public function dropFunction($name)
180 {
181 $this->functions->remove($name);
182 return $this;
183 }
184 /**
185 * Get a template function.
186 * @param string $name
187 * @return Func
188 */
189 public function getFunction($name)
190 {
191 return $this->functions->get($name);
192 }
193 /**
194 * Check if a template function exists.
195 * @param string $name
196 * @return boolean
197 */
198 public function doesFunctionExist($name)
199 {
200 return $this->functions->exists($name);
201 }
202 /**
203 * Load an extension.
204 * @param ExtensionInterface $extension
205 * @return Engine
206 */
207 public function loadExtension(ExtensionInterface $extension)
208 {
209 $extension->register($this);
210 return $this;
211 }
212 /**
213 * Load multiple extensions.
214 * @param array $extensions
215 * @return Engine
216 */
217 public function loadExtensions(array $extensions = array())
218 {
219 foreach ($extensions as $extension) {
220 $this->loadExtension($extension);
221 }
222 return $this;
223 }
224 /**
225 * Get a template path.
226 * @param string $name
227 * @return string
228 */
229 public function path($name)
230 {
231 $name = new Name($this, $name);
232 return $name->getPath();
233 }
234 /**
235 * Check if a template exists.
236 * @param string $name
237 * @return boolean
238 */
239 public function exists($name)
240 {
241 $name = new Name($this, $name);
242 return $name->doesPathExist();
243 }
244 /**
245 * Create a new template.
246 * @param string $name
247 * @param array $data
248 * @return Template
249 */
250 public function make($name, array $data = array())
251 {
252 $template = new Template($this, $name);
253 $template->data($data);
254 return $template;
255 }
256 /**
257 * Create a new template and render it.
258 * @param string $name
259 * @param array $data
260 * @return string
261 */
262 public function render($name, array $data = array())
263 {
264 return $this->make($name)->render($data);
265 }
266 }
267