use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
-use Org\Mxchange\CoreFramework\Handler\Stream\IoHandler;
use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
use Org\Mxchange\CoreFramework\Generic\NullPointerException;
use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
use Org\Mxchange\CoreFramework\Response\Responseable;
-use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
+use Org\Mxchange\CoreFramework\Traits\Handler\Io\IoHandlerTrait;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \InvalidArgumentException;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseTemplateEngine extends BaseFrameworkSystem {
- /**
- * The file I/O instance for the template loader
- */
- private $fileIoInstance = NULL;
+ // Load traits
+ use IoHandlerTrait;
+
+ // Exception codes for the template engine
+ const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0x110;
+ const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0x111;
+ const EXCEPTION_INVALID_VIEW_HELPER = 0x112;
+ const EXCEPTION_VARIABLE_IS_MISSING = 0x113;
/**
* The local path name where all templates and sub folders for special
/**
* The variable stack for the templates
*/
- private $varStack = array();
+ private $varStack = [];
/**
* Loaded templates for recursive protection and detection
*/
- private $loadedTemplates = array();
+ private $loadedTemplates = [];
/**
* Compiled templates for recursive protection and detection
*/
- private $compiledTemplates = array();
+ private $compiledTemplates = [];
/**
* Loaded raw template data
/**
* Loaded helpers
*/
- private $helpers = array();
+ private $helpers = [];
/**
* Current variable group
/**
* All template groups except "general"
*/
- private $variableGroups = array();
+ private $variableGroups = [];
/**
* Code begin
*/
private $languageSupport = true;
- /**
- * XML compacting is disabled by default
- */
- private $xmlCompacting = false;
-
- // Exception codes for the template engine
- const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0x110;
- const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0x111;
- const EXCEPTION_INVALID_VIEW_HELPER = 0x112;
- const EXCEPTION_VARIABLE_IS_MISSING = 0x113;
-
/**
* Protected constructor
*
* @param $className Name of the class
* @return void
*/
- protected function __construct ($className) {
+ protected function __construct (string $className) {
// Call parent constructor
parent::__construct($className);
*/
private function readCurrentGroup () {
// Default is not found
- $result = array();
+ $result = [];
// Is the group there?
if ($this->isVarStackSet($this->currGroup)) {
// Is the stack there?
if (!isset($this->varStack[$variableGroup])) {
// Then initialize it here
- $this->varStack[$variableGroup] = array();
+ $this->varStack[$variableGroup] = [];
}
// Not found, add it
$this->loadRawTemplateData($fileInstance);
} catch (FileNotFoundException $e) {
// If we shall load a code-template we need to switch the file extension
- if (($this->getTemplateType() != $this->getConfigInstance()->getConfigEntry('html_template_type')) && (empty($extOther))) {
+ if (($this->getTemplateType() != FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('html_template_type')) && (empty($extOther))) {
// Switch over to the code-template extension and try it again
$ext = $this->getCodeTemplateExtension();
// Initialize some arrays
if (is_null($this->loadedRawData)) {
// Initialize both
- $this->loadedRawData = array();
- $this->rawTemplates = array();
+ $this->loadedRawData = [];
+ $this->rawTemplates = [];
}
// Load all requested templates
*/
public function loadHtmlTemplate (string $template) {
// Set template type
- $this->setTemplateType($this->getConfigInstance()->getConfigEntry('html_template_type'));
+ $this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('html_template_type'));
// Load the special template
$this->loadTemplate($template);
$variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
// Sweet and simple...
- //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: variableName=' . $variableName . ',getConfigEntry()=' . $this->getConfigInstance()->getConfigEntry($variableName));
- $this->assignVariable($variableName, $this->getConfigInstance()->getConfigEntry($variableName));
+ //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: variableName=' . $variableName . ',getConfigEntry()=' . FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($variableName));
+ $this->assignVariable($variableName, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($variableName));
}
/**
*/
public function loadCodeTemplate (string $template) {
// Set template type
- $this->setTemplateType($this->getConfigInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type'));
+ $this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type'));
// Load the special template
$this->loadTemplate($template);
*/
public function loadEmailTemplate (string $template) {
// Set template type
- $this->setTemplateType($this->getConfigInstance()->getConfigEntry('email_template_type'));
+ $this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('email_template_type'));
// Load the special template
$this->loadTemplate($template);
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: value='. $value . ',name=' . $currVariable['name'] . ',index=' . $index);
// Is it a configuration key?
- if ($this->getConfigInstance()->isConfigurationEntrySet($value)) {
+ if (FrameworkBootstrap::getConfigurationInstance()->isConfigurationEntrySet($value)) {
// The value itself is a configuration entry
$this->assignConfigVariable($value);
} else {
*/
public final function compileVariables () {
// Initialize the $content array
- $validVar = $this->getConfigInstance()->getConfigEntry('tpl_valid_var');
- $dummy = array();
+ $validVar = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('tpl_valid_var');
+ $dummy = [];
// Iterate through all general variables
foreach ($this->getVarStack('general') as $currVariable) {
*/
public function compileTemplate () {
// Get code type to make things shorter
- $codeType = $this->getConfigInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type');
+ $codeType = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type');
// We will only work with template type "code" from configuration
if (substr($this->getTemplateType(), 0, strlen($codeType)) != $codeType) {
// Abort here
- throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED);
+ throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED);
}
// Get the raw data.
// Is this view helper loaded?
if (!isset($this->helpers[$helperName])) {
// Create a class name
- $className = self::convertToClassName($helperName) . 'ViewHelper';
+ $className = StringUtils::convertToClassName($helperName) . 'ViewHelper';
// Generate new instance
$this->helpers[$helperName] = ObjectFactory::createObjectByName($className);
$this->setRawTemplateData($rawData);
}
- /**
- * Renders the given XML content
- *
- * @param $content Valid XML content or if not set the current loaded raw content
- * @return void
- * @throws XmlParserException If an XML error was found
- */
- public function renderXmlContent (string $content = NULL) {
- // Is the content set?
- if (is_null($content)) {
- // Get current content
- $content = $this->getRawTemplateData();
- }
-
- // Get a XmlParser instance
- $parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', array($this));
-
- // Check if XML compacting is enabled
- if ($this->isXmlCompactingEnabled()) {
- // Yes, so get a decorator class for transparent compacting
- $parserInstance = ObjectFactory::createObjectByConfiguredName('deco_compacting_xml_parser_class', array($parserInstance));
- }
-
- // Parse the XML document
- $parserInstance->parseXmlContent($content);
- }
-
/**
* Enables or disables language support
*
return $this->languageSupport;
}
- /**
- * Enables or disables XML compacting
- *
- * @param $xmlCompacting New XML compacting setting
- * @return void
- */
- public final function enableXmlCompacting (bool $xmlCompacting = true) {
- $this->xmlCompacting = $xmlCompacting;
- }
-
- /**
- * Checks whether XML compacting is enabled
- *
- * @return $xmlCompacting Whether XML compacting is enabled or disabled
- */
- public final function isXmlCompactingEnabled () {
- return $this->xmlCompacting;
- }
-
- /**
- * Private getter for file IO instance
- *
- * @return $fileIoInstance An instance to the file I/O sub-system
- */
- protected final function getFileIoInstance () {
- return $this->fileIoInstance;
- }
-
- /**
- * Setter for file I/O instance
- *
- * @param $fileIoInstance An instance to the file I/O sub-system
- * @return void
- */
- public final function setFileIoInstance (IoHandler $fileIoInstance) {
- $this->fileIoInstance = $fileIoInstance;
- }
-
/**
* Removes all commentd, tabs and new-line characters to compact the content
*