PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.3.1
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.3.1
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 5 years ago TemplateEngineException.php 5 years ago TemplateEngineInterface.php 5 years ago
TemplateEngine.php
66 lines
1 <?php
2
3 // TODO PHP7.x; declare(strict_types=1);
4 // TODO PHP7.x; type-hints & return types;
5
6 namespace WPStaging\Framework\TemplateEngine;
7
8 use DateTime;
9 use WPStaging\Framework\Adapter\DateTimeAdapter;
10
11 class TemplateEngine implements TemplateEngineInterface
12 {
13 /** @var string Absolute path to the views directory. */
14 protected $views;
15
16 /**
17 * @param string $path
18 * @param array $params
19 *
20 * @return string
21 */
22 public function render($path, array $params = [])
23 {
24 if (!isset($this->views)) {
25 $this->views = WPSTG_PLUGIN_DIR . 'Backend/views/';
26 }
27
28 $fullPath = WPSTG_PLUGIN_DIR . $path;
29 if (!file_exists($fullPath)) {
30 throw new TemplateEngineException('Template not found: ' . $fullPath);
31 }
32
33 extract($params, EXTR_SKIP);
34 ob_start();
35
36 /** @noinspection PhpIncludeInspection */
37 require $fullPath;
38 $result = ob_get_clean();
39
40 return (string)$result;
41 }
42
43 /**
44 * @return string
45 * @noinspection PhpUnused
46 */
47 protected function getDateTimeFormat()
48 {
49 return (new DateTimeAdapter())->getDateTimeFormat();
50 }
51
52 /**
53 * @param DateTime|null $dateTime
54 *
55 * @return string
56 */
57 protected function transformToWpFormat(DateTime $dateTime = null)
58 {
59 if (!$dateTime) {
60 return '';
61 }
62
63 return (new DateTimeAdapter())->transformToWpFormat($dateTime);
64 }
65 }
66