X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ftemplate%2Fclass_BaseTemplateEngine.php;h=1908e3bc9b87eef6372134402779611f29e4177a;hp=a233e776e1e2386812a0efc8bf2d2f30b5e91968;hb=2b4f4b88ec5f9d385110e800494c680e164b5a36;hpb=c043deee4ad5b0f39830948b3ccd27f7fc38c193 diff --git a/framework/main/classes/template/class_BaseTemplateEngine.php b/framework/main/classes/template/class_BaseTemplateEngine.php index a233e776..1908e3bc 100644 --- a/framework/main/classes/template/class_BaseTemplateEngine.php +++ b/framework/main/classes/template/class_BaseTemplateEngine.php @@ -1,16 +1,20 @@ . */ -class BaseTemplateEngine extends BaseFrameworkSystem { +abstract class BaseTemplateEngine extends BaseFrameworkSystem { /** * The local path name where all templates and sub folders for special * templates are stored. We will internally determine the language plus @@ -78,9 +82,9 @@ class BaseTemplateEngine extends BaseFrameworkSystem { private $compiledData = ''; /** - * The last loaded template's FQFN for debugging the engine + * The last loaded template's file instance (SplFileInfo) */ - private $lastTemplate = ''; + private $lastTemplate = NULL; /** * The variable stack for the templates @@ -494,17 +498,17 @@ class BaseTemplateEngine extends BaseFrameworkSystem { } /** - * Setter for the last loaded template's FQFN + * Setter for the last loaded template's file instance * * @param $template The last loaded template * @return void */ - private final function setLastTemplate ($template) { - $this->lastTemplate = (string) $template; + private final function setLastTemplate (SplFileInfo $fileInstance) { + $this->lastTemplate = $fileInstance; } /** - * Getter for the last loaded template's FQFN + * Getter for the last loaded template's file instance * * @return $template The last loaded template */ @@ -692,19 +696,19 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * now entirely done by php_intl. These old thing with language-based * template paths comes from an older time. */ - $fqfn = sprintf('%s%s%s%s%s%s', + $fileInstance = new SplFileInfo(sprintf('%s%s%s%s%s%s', $this->getTemplateBasePath(), $this->getGenericBasePath(), $this->getTemplateType(), DIRECTORY_SEPARATOR, (string) $templateName, $ext - ); + )); // First try this try { // Load the raw template data - $this->loadRawTemplateData($fqfn); + $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))) { @@ -715,7 +719,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $this->loadTemplate($templateName, $ext); } else { // Throw it again - throw new FileNotFoundException($fqfn, self::EXCEPTION_FILE_NOT_FOUND); + throw new FileNotFoundException($fileInstance, self::EXCEPTION_FILE_NOT_FOUND); } } @@ -724,21 +728,21 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * A private loader for raw template names * - * @param $fqfn The full-qualified file name for a template + * @param $fileInstance An instance of a SplFileInfo class * @return void */ - private function loadRawTemplateData ($fqfn) { + private function loadRawTemplateData (SplFileInfo $fileInstance) { // Some debug code to look on the file which is being loaded - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: FQFN=' . $fqfn); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: fileInstance=' . $fileInstance); // Load the raw template - $rawTemplateData = $this->getFileIoInstance()->loadFileContents($fqfn); + $rawTemplateData = $this->getFileIoInstance()->loadFileContents($fileInstance); // Store the template's contents into this class $this->setRawTemplateData($rawTemplateData); - // Remember the template's FQFN - $this->setLastTemplate($fqfn); + // Remember the template's file instance + $this->setLastTemplate($fileInstance); } /** @@ -1109,7 +1113,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $variableName The variable we are looking for * @param $value The value we want to store in the variable * @return void - * @throws EmptyVariableException If the variable name is left empty + * @throws InvalidArgumentException If the variable name is left empty */ public final function assignVariable ($variableName, $value) { // Replace all dashes to underscores to match variables with configuration entries @@ -1118,7 +1122,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Empty variable found? if (empty($variableName)) { // Throw an exception - throw new EmptyVariableException(array($this, 'variableName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new InvalidArgumentException('Parameter "variableName" is empty'); } // END - if // First search for the variable if it was already added @@ -1209,10 +1213,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Assigns all the application data with template variables * - * @param $applicationInstance A manageable application instance * @return void */ - public function assignApplicationData (ManageableApplication $applicationInstance) { + public function assignApplicationData () { + // Get application instance + $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + // Get long name and assign it $this->assignVariable('app_full_name' , $applicationInstance->getAppName());