From 2fec89d95ffaf18ad7d804546e2ff90e1c733725 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Fri, 23 Oct 2015 12:24:51 +0000 Subject: [PATCH] route : route allow now to get the information from a return in the function of map and display it with the provided output type (json, html, xml, text). git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2374 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- route.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/route.php b/route.php index b020256..6686518 100644 --- a/route.php +++ b/route.php @@ -32,6 +32,24 @@ class route just display a "Unauthorized" message */ public $authenticationURL = null; + + /// RENDERER PART /// + /** Output type to no previous catched renderer (allow : json, xml, txt html) + */ + public $output = "html"; + /** Title by default : space to be compatible with HTML5 */ + public $title = " "; + /** Filename of class containing the presentation layer */ + public $viewClass = FALSE; + /** Method apply to class object to display the $result */ + public $viewMethod = FALSE; + /** Filename in views containing the HTML layout. Without .html at the end */ + public $layout = FALSE; + /** Array to search/replace */ + public $replacement = array(); + /** Array to variable definition */ + public $variable = array (); + /** Return the baseURL of the site Always finish with a slash @param string|null $module The module name (if thereis one) */ @@ -380,12 +398,28 @@ class route echo "==> FOUND EQUAL !\n"; try { - $function (); + $data = $function (); } catch (Exception $e) { $this->error ($e); } + require ("domframework/renderer.php"); + $renderer = new renderer (); + $renderer->result = $data; + $renderer->output = $this->output; + $renderer->title = $this->title; + $renderer->viewClass = $this->viewClass; + $renderer->viewMethod = $this->viewMethod; + $renderer->layout = $this->layout; + $renderer->replacement = $this->replacement; + $renderer->variable = $this->variable; + $renderer->run (); + exit; + $class = "output".$this->output; + require_once ("$class.php"); + $output = new $class (); + $output->out ($data); exit; } @@ -418,12 +452,28 @@ class route try { - call_user_func_array ($function, $params); + $data = call_user_func_array ($function, $params); } catch (Exception $e) { $this->error ($e); } + require ("domframework/renderer.php"); + $renderer = new renderer (); + $renderer->result = $data; + $renderer->output = $this->output; + $renderer->title = $this->title; + $renderer->viewClass = $this->viewClass; + $renderer->viewMethod = $this->viewMethod; + $renderer->layout = $this->layout; + $renderer->replacement = $this->replacement; + $renderer->variable = $this->variable; + $renderer->run (); + exit; + $class = "output".$this->output; + require_once ("$class.php"); + $output = new $class (); + $output->out ($data); exit; } @@ -470,17 +520,24 @@ class route $http = new http (); @header ($_SERVER["SERVER_PROTOCOL"]." $getCode ". $http->codetext ($getCode)); - echo "\n"; - echo " \n"; - echo " ".$http->codetext ($getCode)."\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo" \n"; - echo "

".$http->codetext ($getCode)."

"; - echo $message; - echo" \n"; - echo "\n"; + // TODO : If the output is HTML, add the header line : + // echo " \n"; + require ("domframework/renderer.php"); + $renderer = new renderer (); + $renderer->result = $message; + $renderer->output = $this->output; + $renderer->title = $http->codetext ($getCode); + $renderer->viewClass = $this->viewClass; + $renderer->viewMethod = $this->viewMethod; + $renderer->layout = $this->layout; + $renderer->replacement = $this->replacement; + $renderer->variable = $this->variable; + $renderer->run (); + exit; + $class = "output".$this->output; + require_once ("$class.php"); + $output = new $class (); + $output->out ($message, $http->codetext ($getCode)); exit; } }