X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ftemplate%2Fclass_BaseTemplateEngine.php;h=8c09dfbf91a01dfa65b5c601a73932a3500a3181;hb=035b3221bff7b542e264a9d0a4a6d086833487ef;hp=87642847795d5479e65638ec5df1f8df94d95cd9;hpb=c1aadb61b45c15273c07c366887c8f58c53155e3;p=core.git diff --git a/framework/main/classes/template/class_BaseTemplateEngine.php b/framework/main/classes/template/class_BaseTemplateEngine.php index 87642847..8c09dfbf 100644 --- a/framework/main/classes/template/class_BaseTemplateEngine.php +++ b/framework/main/classes/template/class_BaseTemplateEngine.php @@ -6,14 +6,14 @@ namespace Org\Mxchange\CoreFramework\Template\Engine; 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; @@ -42,10 +42,14 @@ use \SplFileInfo; * along with this program. If not, see . */ 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 @@ -97,17 +101,17 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { /** * 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 @@ -139,7 +143,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { /** * Loaded helpers */ - private $helpers = array(); + private $helpers = []; /** * Current variable group @@ -149,7 +153,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { /** * All template groups except "general" */ - private $variableGroups = array(); + private $variableGroups = []; /** * Code begin @@ -166,17 +170,6 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { */ 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 * @@ -326,7 +319,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { */ private function readCurrentGroup () { // Default is not found - $result = array(); + $result = []; // Is the group there? if ($this->isVarStackSet($this->currGroup)) { @@ -452,7 +445,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { // Is the stack there? if (!isset($this->varStack[$variableGroup])) { // Then initialize it here - $this->varStack[$variableGroup] = array(); + $this->varStack[$variableGroup] = []; } // Not found, add it @@ -824,8 +817,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { // Initialize some arrays if (is_null($this->loadedRawData)) { // Initialize both - $this->loadedRawData = array(); - $this->rawTemplates = array(); + $this->loadedRawData = []; + $this->rawTemplates = []; } // Load all requested templates @@ -1308,7 +1301,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { public final function compileVariables () { // Initialize the $content array $validVar = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('tpl_valid_var'); - $dummy = array(); + $dummy = []; // Iterate through all general variables foreach ($this->getVarStack('general') as $currVariable) { @@ -1456,7 +1449,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { // 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); @@ -1550,33 +1543,6 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { $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 * @@ -1596,44 +1562,6 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { 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 *