Renamed Registry -> GenericRegistry to make it clear that this registry does
[core.git] / framework / main / classes / template / class_BaseTemplateEngine.php
index fd116e5cf166fa48a410e50b79ef68b541b09d78..01ff9a92ede901e7b3925676badebae3a48def26 100644 (file)
@@ -1,15 +1,19 @@
 <?php
 // Own namespace
-namespace CoreFramework\Template\Engine;
+namespace Org\Mxchange\CoreFramework\Template\Engine;
 
 // Import framework stuff
-use CoreFramework\Bootstrap\FrameworkBootstrap;
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Filesystem\FileNotFoundException;
-use CoreFramework\Generic\EmptyVariableException;
-use CoreFramework\Manager\ManageableApplication;
-use CoreFramework\Object\BaseFrameworkSystem;
-use CoreFramework\Response\Responseable;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
+use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Response\Responseable;
+
+// Import SPL stuff
+use \InvalidArgumentException;
+use \SplFileInfo;
 
 /**
  * A generic template engine
@@ -33,7 +37,7 @@ use CoreFramework\Response\Responseable;
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-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
@@ -77,9 +81,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
@@ -493,17 +497,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
         */
@@ -671,12 +675,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
        /**
         * Private loader for all template types
         *
-        * @param       $template       The template we shall load
+        * @param       $templateName   The template we shall load
         * @param       $extOther       An other extension to use
         * @return      void
         * @throws      FileNotFoundException   If the template was not found
         */
-       protected function loadTemplate ($template, $extOther = '') {
+       protected function loadTemplate ($templateName, $extOther = '') {
                // Get extension for the template if empty
                if (empty($extOther)) {
                        // None provided, so get the raw one
@@ -691,19 +695,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',
-                       $this->getConfigInstance()->getConfigEntry('application_base_path'),
+               $fileInstance = new SplFileInfo(sprintf('%s%s%s%s%s%s',
                        $this->getTemplateBasePath(),
                        $this->getGenericBasePath(),
                        $this->getTemplateType(),
-                       (string) $template,
+                       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))) {
@@ -711,10 +715,10 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                $ext = $this->getCodeTemplateExtension();
 
                                // Try it again...
-                               $this->loadTemplate($template, $ext);
+                               $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);
                        }
                }
 
@@ -723,21 +727,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);
        }
 
        /**
@@ -986,7 +990,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                $this->assignVariable($var, $varMatches[3][$key]);
                        } elseif (!empty($varMatches[2][$key])) {
                                // @TODO Non-string found so we need some deeper analysis...
-                               ApplicationEntryPoint::app_exit('Deeper analysis not yet implemented!');
+                               ApplicationEntryPoint::exitApplication('Deeper analysis not yet implemented!');
                        }
                } // END - foreach
        }
@@ -1108,7 +1112,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
@@ -1117,7 +1121,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