PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.0.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.0.0
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / TemplateEngine / TemplateEngine.php
wp-staging / Framework / TemplateEngine Last commit date
TemplateEngine.php 1 year ago TemplateEngineException.php 5 years ago TemplateEngineInterface.php 2 years ago
TemplateEngine.php
69 lines
1 <?php
2
3 namespace WPStaging\Framework\TemplateEngine;
4
5 use DateTime;
6 use WPStaging\Framework\Adapter\DateTimeAdapter;
7
8 class TemplateEngine implements TemplateEngineInterface
9 {
10 /**
11 * Hook that is used to inject pro templates in UI. So they can be used by our JS
12 * @var string
13 */
14 const HOOK_RENDER_PRO_TEMPLATES = 'wpstg.template.render_pro_templates';
15
16 /** @var string Absolute path to the views directory. */
17 protected $views;
18
19 /**
20 * @param string $path
21 * @param array $params
22 *
23 * @return string
24 */
25 public function render(string $path, array $params = []): string
26 {
27 if (!isset($this->views)) {
28 $this->views = WPSTG_VIEWS_DIR;
29 }
30
31 $fullPath = WPSTG_VIEWS_DIR . $path;
32 if (!file_exists($fullPath)) {
33 throw new TemplateEngineException('Template not found: ' . $fullPath);
34 }
35
36 extract($params, EXTR_SKIP);
37 ob_start();
38
39 /** @noinspection PhpIncludeInspection */
40 require $fullPath;
41 $result = ob_get_clean();
42
43 return (string)$result;
44 }
45
46 /**
47 * @return string
48 * @noinspection PhpUnused
49 */
50 protected function getDateTimeFormat(): string
51 {
52 return (new DateTimeAdapter())->getDateTimeFormat();
53 }
54
55 /**
56 * @param DateTime|null $dateTime
57 *
58 * @return string
59 */
60 protected function transformToWpFormat($dateTime = null): string
61 {
62 if (!$dateTime) {
63 return '';
64 }
65
66 return (new DateTimeAdapter())->transformToWpFormat($dateTime);
67 }
68 }
69