PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.1.4
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.1.4
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 1 year ago
TemplateEngine.php
87 lines
1 <?php
2
3 namespace WPStaging\Framework\TemplateEngine;
4
5 use DateTime;
6 use WPStaging\Core\WPStaging;
7 use WPStaging\Framework\Adapter\DateTimeAdapter;
8 use WPStaging\Framework\Assets\Assets;
9
10 class TemplateEngine implements TemplateEngineInterface
11 {
12 /**
13 * Hook that is used to inject pro templates in UI. So they can be used by our JS
14 * @var string
15 */
16 const HOOK_RENDER_PRO_TEMPLATES = 'wpstg.template.render_pro_templates';
17
18 /** @var string Absolute path to the views directory. */
19 protected $views;
20
21 /** @var Assets */
22 private $assets;
23
24 public function __construct()
25 {
26 $this->assets = WPStaging::make(Assets::class);
27 }
28
29 /**
30 * @param string $path
31 * @param array $params
32 *
33 * @return string
34 */
35 public function render(string $path, array $params = []): string
36 {
37 if (!isset($this->views)) {
38 $this->views = WPSTG_VIEWS_DIR;
39 }
40
41 $fullPath = WPSTG_VIEWS_DIR . $path;
42 if (!file_exists($fullPath)) {
43 throw new TemplateEngineException('Template not found: ' . $fullPath);
44 }
45
46 extract($params, EXTR_SKIP);
47 ob_start();
48
49 /** @noinspection PhpIncludeInspection */
50 require $fullPath;
51 $result = ob_get_clean();
52
53 return (string)$result;
54 }
55
56 /**
57 * @return Assets
58 */
59 public function getAssets()
60 {
61 return $this->assets;
62 }
63
64 /**
65 * @return string
66 * @noinspection PhpUnused
67 */
68 protected function getDateTimeFormat(): string
69 {
70 return (new DateTimeAdapter())->getDateTimeFormat();
71 }
72
73 /**
74 * @param DateTime|null $dateTime
75 *
76 * @return string
77 */
78 protected function transformToWpFormat($dateTime = null): string
79 {
80 if (!$dateTime) {
81 return '';
82 }
83
84 return (new DateTimeAdapter())->transformToWpFormat($dateTime);
85 }
86 }
87