From: Roland Häder Date: Tue, 27 May 2008 19:03:35 +0000 (+0000) Subject: Template engine now checks variables first then code template X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b511cb66771117b1005838310bc84f491ae24f0a;p=shipsimu.git Template engine now checks variables first then code template --- diff --git a/inc/classes/main/controller/form/class_WebDoFormController.php b/inc/classes/main/controller/form/class_WebDoFormController.php index 7e2e086..6c01d87 100644 --- a/inc/classes/main/controller/form/class_WebDoFormController.php +++ b/inc/classes/main/controller/form/class_WebDoFormController.php @@ -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] diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index ee01937..64902cb 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -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; } diff --git a/index.php b/index.php index 1956b02..75926e2 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@