PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.18
Independent Analytics – WordPress Analytics Plugin v1.18
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
Extension 3 years ago Template 3 years ago Engine.php 3 years ago
Engine.php
244 lines
1 <?php
2
3 namespace IAWP\League\Plates;
4
5 use IAWP\League\Plates\Extension\ExtensionInterface;
6 use IAWP\League\Plates\Template\Data;
7 use IAWP\League\Plates\Template\Directory;
8 use IAWP\League\Plates\Template\FileExtension;
9 use IAWP\League\Plates\Template\Folders;
10 use IAWP\League\Plates\Template\Func;
11 use IAWP\League\Plates\Template\Functions;
12 use IAWP\League\Plates\Template\Name;
13 use IAWP\League\Plates\Template\Template;
14 /**
15 * Template API and environment settings storage.
16 */
17 class Engine
18 {
19 /**
20 * Default template directory.
21 * @var Directory
22 */
23 protected $directory;
24 /**
25 * Template file extension.
26 * @var FileExtension
27 */
28 protected $fileExtension;
29 /**
30 * Collection of template folders.
31 * @var Folders
32 */
33 protected $folders;
34 /**
35 * Collection of template functions.
36 * @var Functions
37 */
38 protected $functions;
39 /**
40 * Collection of preassigned template data.
41 * @var Data
42 */
43 protected $data;
44 /**
45 * Create new Engine instance.
46 * @param string $directory
47 * @param string $fileExtension
48 */
49 public function __construct($directory = null, $fileExtension = 'php')
50 {
51 $this->directory = new Directory($directory);
52 $this->fileExtension = new FileExtension($fileExtension);
53 $this->folders = new Folders();
54 $this->functions = new Functions();
55 $this->data = new Data();
56 }
57 /**
58 * Set path to templates directory.
59 * @param string|null $directory Pass null to disable the default directory.
60 * @return Engine
61 */
62 public function setDirectory($directory)
63 {
64 $this->directory->set($directory);
65 return $this;
66 }
67 /**
68 * Get path to templates directory.
69 * @return string
70 */
71 public function getDirectory()
72 {
73 return $this->directory->get();
74 }
75 /**
76 * Set the template file extension.
77 * @param string|null $fileExtension Pass null to manually set it.
78 * @return Engine
79 */
80 public function setFileExtension($fileExtension)
81 {
82 $this->fileExtension->set($fileExtension);
83 return $this;
84 }
85 /**
86 * Get the template file extension.
87 * @return string
88 */
89 public function getFileExtension()
90 {
91 return $this->fileExtension->get();
92 }
93 /**
94 * Add a new template folder for grouping templates under different namespaces.
95 * @param string $name
96 * @param string $directory
97 * @param boolean $fallback
98 * @return Engine
99 */
100 public function addFolder($name, $directory, $fallback = \false)
101 {
102 $this->folders->add($name, $directory, $fallback);
103 return $this;
104 }
105 /**
106 * Remove a template folder.
107 * @param string $name
108 * @return Engine
109 */
110 public function removeFolder($name)
111 {
112 $this->folders->remove($name);
113 return $this;
114 }
115 /**
116 * Get collection of all template folders.
117 * @return Folders
118 */
119 public function getFolders()
120 {
121 return $this->folders;
122 }
123 /**
124 * Add preassigned template data.
125 * @param array $data;
126 * @param null|string|array $templates;
127 * @return Engine
128 */
129 public function addData(array $data, $templates = null)
130 {
131 $this->data->add($data, $templates);
132 return $this;
133 }
134 /**
135 * Get all preassigned template data.
136 * @param null|string $template;
137 * @return array
138 */
139 public function getData($template = null)
140 {
141 return $this->data->get($template);
142 }
143 /**
144 * Register a new template function.
145 * @param string $name;
146 * @param callback $callback;
147 * @return Engine
148 */
149 public function registerFunction($name, $callback)
150 {
151 $this->functions->add($name, $callback);
152 return $this;
153 }
154 /**
155 * Remove a template function.
156 * @param string $name;
157 * @return Engine
158 */
159 public function dropFunction($name)
160 {
161 $this->functions->remove($name);
162 return $this;
163 }
164 /**
165 * Get a template function.
166 * @param string $name
167 * @return Func
168 */
169 public function getFunction($name)
170 {
171 return $this->functions->get($name);
172 }
173 /**
174 * Check if a template function exists.
175 * @param string $name
176 * @return boolean
177 */
178 public function doesFunctionExist($name)
179 {
180 return $this->functions->exists($name);
181 }
182 /**
183 * Load an extension.
184 * @param ExtensionInterface $extension
185 * @return Engine
186 */
187 public function loadExtension(ExtensionInterface $extension)
188 {
189 $extension->register($this);
190 return $this;
191 }
192 /**
193 * Load multiple extensions.
194 * @param array $extensions
195 * @return Engine
196 */
197 public function loadExtensions(array $extensions = array())
198 {
199 foreach ($extensions as $extension) {
200 $this->loadExtension($extension);
201 }
202 return $this;
203 }
204 /**
205 * Get a template path.
206 * @param string $name
207 * @return string
208 */
209 public function path($name)
210 {
211 $name = new Name($this, $name);
212 return $name->getPath();
213 }
214 /**
215 * Check if a template exists.
216 * @param string $name
217 * @return boolean
218 */
219 public function exists($name)
220 {
221 $name = new Name($this, $name);
222 return $name->doesPathExist();
223 }
224 /**
225 * Create a new template.
226 * @param string $name
227 * @return Template
228 */
229 public function make($name)
230 {
231 return new Template($this, $name);
232 }
233 /**
234 * Create a new template and render it.
235 * @param string $name
236 * @param array $data
237 * @return string
238 */
239 public function render($name, array $data = array())
240 {
241 return $this->make($name)->render($data);
242 }
243 }
244