| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hyperpay\Gateways\Helpers; |
| 4 |
|
| 5 |
if (! defined('ABSPATH')) exit; |
| 6 |
|
| 7 |
use Hyperpay\Gateways\Main; |
| 8 |
|
| 9 |
final class View |
| 10 |
{ |
| 11 |
public static function render($name, $params = []) |
| 12 |
{ |
| 13 |
$loader = new \Twig\Loader\FilesystemLoader(Main::ROOT_PATH . "/assets/templates"); |
| 14 |
$twig = new \Twig\Environment($loader); |
| 15 |
|
| 16 |
$params = static::esc($params); |
| 17 |
|
| 18 |
// rendering the template HTML, JS and CSS |
| 19 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 20 |
echo ($twig->render($name, $params)); |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
public static function esc($value) |
| 25 |
{ |
| 26 |
if (is_array($value)) { |
| 27 |
$esc_values = []; |
| 28 |
foreach ($value as $key => $nested_value) { |
| 29 |
$esc_values[$key] = static::esc($nested_value); |
| 30 |
} |
| 31 |
return $esc_values; |
| 32 |
} |
| 33 |
|
| 34 |
return esc_html($value); |
| 35 |
} |
| 36 |
} |
| 37 |
|