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
This commit is contained in:
2015-10-23 12:24:51 +00:00
parent 1726abd0a5
commit 2fec89d95f

View File

@@ -32,6 +32,24 @@ class route
just display a "Unauthorized" message */ just display a "Unauthorized" message */
public $authenticationURL = null; 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 /** Return the baseURL of the site
Always finish with a slash Always finish with a slash
@param string|null $module The module name (if thereis one) */ @param string|null $module The module name (if thereis one) */
@@ -380,12 +398,28 @@ class route
echo "==> FOUND EQUAL !\n"; echo "==> FOUND EQUAL !\n";
try try
{ {
$function (); $data = $function ();
} }
catch (Exception $e) catch (Exception $e)
{ {
$this->error ($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; exit;
} }
@@ -418,12 +452,28 @@ class route
try try
{ {
call_user_func_array ($function, $params); $data = call_user_func_array ($function, $params);
} }
catch (Exception $e) catch (Exception $e)
{ {
$this->error ($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; exit;
} }
@@ -470,17 +520,24 @@ class route
$http = new http (); $http = new http ();
@header ($_SERVER["SERVER_PROTOCOL"]." $getCode ". @header ($_SERVER["SERVER_PROTOCOL"]." $getCode ".
$http->codetext ($getCode)); $http->codetext ($getCode));
echo "<html>\n"; // TODO : If the output is HTML, add the header line :
echo " <head>\n"; // echo " <meta name='ROBOTS' content='NOINDEX, NOFOLLOW'>\n";
echo " <title>".$http->codetext ($getCode)."</title>\n"; require ("domframework/renderer.php");
echo " <meta charset='utf-8'>\n"; $renderer = new renderer ();
echo " <meta name='ROBOTS' content='NOINDEX, NOFOLLOW'>\n"; $renderer->result = $message;
echo " </head>\n"; $renderer->output = $this->output;
echo" <body>\n"; $renderer->title = $http->codetext ($getCode);
echo "<h1>".$http->codetext ($getCode)."</h1>"; $renderer->viewClass = $this->viewClass;
echo $message; $renderer->viewMethod = $this->viewMethod;
echo" </body>\n"; $renderer->layout = $this->layout;
echo "</html>\n"; $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; exit;
} }
} }