A super easy PHP Framework for web development! https://github.com/exacti/phacil-framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.6 KiB

6 years ago
<?php
/**
* Copyright © 2024 ExacTI Technology Solutions. All rights reserved.
* GPLv3 General License.
* https://exacti.com.br
* Phacil PHP Framework - https://github.com/exacti/phacil-framework
*/
namespace Phacil\Framework\templateEngines;
/**
* @since 2.0.0
* @package Phacil\Framework\templateEngines
*/
class Twig {
static private $TwigFolderLoad;
static private $TwigLoaderFilesystem;
static private $TwigEnvironment;
static private $TwigSimpleFilter;
static private $TwigExtensionDebug;
static private $registered;
/** @return void */
public static function registryTwigVersion() {
if(self::$registered)
return;
$preferenceDIObj = \Phacil\Framework\templateEngines\Twig\Api\Extension\TranslateInterface::class;
if (version_compare(phpversion(), '7.2.5', '>') == false) {
self::define('TwigFolderLoad', 'Twig1x');
self::define('TwigLoaderFilesystem', 'Twig_Loader_Filesystem');
self::define('TwigEnvironment', 'Twig_Environment');
self::define('TwigSimpleFilter', 'Twig_SimpleFilter');
self::define('TwigExtensionDebug', 'Twig_Extension_Debug');
if (!\Phacil\Framework\Registry::checkPreferenceExist($preferenceDIObj)) {
\Phacil\Framework\Registry::addDIPreference($preferenceDIObj, \Phacil\Framework\templateEngines\Twig\Extension\Legacy\Translate::class);
}
} else {
self::define('TwigLoaderFilesystem', '\Twig\Loader\FilesystemLoader');
self::define('TwigEnvironment', '\Twig\Environment');
self::define('TwigSimpleFilter', '\Twig\TwigFilter');
self::define('TwigExtensionDebug', '\Twig\Extension\DebugExtension');
if (!\Phacil\Framework\Registry::checkPreferenceExist($preferenceDIObj)) {
\Phacil\Framework\Registry::addDIPreference($preferenceDIObj, 'Phacil\Framework\templateEngines\Twig\Extension\Translate');
}
}
if (self::getVar('TwigFolderLoad')) {
include_once self::getVar('TwigFolderLoad') . "/vendor/autoload.php";
}
self::$registered = true;
}
/**
* @param string $var
* @param string $value
* @return void
*/
protected static function define($var, $value) {
if(property_exists(__CLASS__, $var))
self::$$var = $value;
6 years ago
}
/**
* @param string $var
* @return mixed
*/
public static function getVar($var) {
return property_exists(__CLASS__, $var) ? self::$$var : null;
}
}