Template engine now checks variables first then code template
authorRoland Häder <roland@mxchange.org>
Tue, 27 May 2008 19:03:35 +0000 (19:03 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 27 May 2008 19:03:35 +0000 (19:03 +0000)
inc/classes/main/controller/form/class_WebDoFormController.php
inc/classes/main/template/class_TemplateEngine.php
index.php

index 7e2e086..6c01d87 100644 (file)
@@ -51,6 +51,9 @@ class WebDoFormController extends BaseController implements Controller {
                // Set resolver instance
                $controllerInstance->setResolverInstance($resolverInstance);
 
+               // Generate some pre/post filters
+               $controllerInstance->addDoFormPrePostFilters();
+
                // Return the prepared instance
                return $controllerInstance;
        }
@@ -65,6 +68,7 @@ class WebDoFormController extends BaseController implements Controller {
        public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
                // Run all pre filters
                $this->executePreFilters($requestInstance, $responseInstance);
+               $requestInstance->debugInstance();
 
                // Get command instance from resolver
                $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance);
@@ -78,6 +82,17 @@ class WebDoFormController extends BaseController implements Controller {
                // Do something more here
                die("OK");
        }
+
+       /**
+        * Add some default pre/post filters for this controller to the matching
+        * filter chains
+        *
+        * @return      void
+        */
+       protected function addDoFormPrePostFilters () {
+               // Add a filter to check for missing user name
+               $this->addPreFilter(UserNameValidatorFilter::createUserNameValidatorFilter());
+       }
 }
 
 // [EOF]
index ee01937..64902cb 100644 (file)
@@ -642,24 +642,24 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
                        // RECURSIVE PROTECTION! BE CAREFUL HERE!
                        if ((!isset($this->loadedRawData[$template])) && (!in_array($template, $this->loadedTemplates))) {
 
-                               // Then try to search for code-templates first
-                               try {
-                                       // Load the code template and remember it's contents
-                                       $this->loadCodeTemplate($template);
-                                       $this->loadedRawData[$template] = $this->getRawTemplateData();
+                               // Template not found, but maybe variable assigned?
+                               if ($this->isVariableAlreadySet($template) !== false) {
+                                       // Use that content here
+                                       $this->loadedRawData[$template] = $this->readVariable($template);
 
-                                       // Remember this template for recursion detection
-                                       // RECURSIVE PROTECTION!
+                                       // Recursive protection:
                                        $this->loadedTemplates[] = $template;
-                               } catch (FilePointerNotOpenedException $e) {
-                                       // Template not found, but maybe variable assigned?
-                                       if ($this->isVariableAlreadySet($template) !== false) {
-                                               // Use that content here
-                                               $this->loadedRawData[$template] = $this->readVariable($template);
-
-                                               // Recursive protection:
+                               } else {
+                                       // Then try to search for code-templates
+                                       try {
+                                               // Load the code template and remember it's contents
+                                               $this->loadCodeTemplate($template);
+                                               $this->loadedRawData[$template] = $this->getRawTemplateData();
+
+                                               // Remember this template for recursion detection
+                                               // RECURSIVE PROTECTION!
                                                $this->loadedTemplates[] = $template;
-                                       } else {
+                                       } catch (FilePointerNotOpenedException $e) {
                                                // Even this is not done... :/
                                                $this->rawTemplates[] = $template;
                                        }
index 1956b02..75926e2 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,4 +1,5 @@
 <?php
+//xdebug_start_trace();
 /**
  * The main class with the entry point to the whole application. This class
  * "emulates" Java(tm)'s entry point call. Additionally it covers local