From 71975da3cb786fe81703ace702fbea2c6a82ff08 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 21 Jul 2016 11:56:25 +0000 Subject: [PATCH] Add : outputrest to support the routing to REST $route->output = "rest"; git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2943 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- outputrest.php | 37 +++++++++++++++++++++++++++++++++++++ route.php | 6 +++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 outputrest.php diff --git a/outputrest.php b/outputrest.php new file mode 100644 index 0000000..dc2cc42 --- /dev/null +++ b/outputrest.php @@ -0,0 +1,37 @@ + */ + +require_once ("output.php"); +require_once ("rest.php"); +/** Display in REST the data provided. + * Allow all the output types : JSON, XML, TXT... + */ +class outputrest extends output +{ + /** Data is printed by viewClass->viewmethod, in the middle of $layout + * title is put in the title of the HTML page + * $replacement modify the result (it can do title too : + * array ("{title}"=>"title to display") + * @param mixed $data Data to display on the page + * @param string|null $title Title to put on head of page + * @param string|null $viewClass Class in views to use to display + * @param string|null $viewMethod Method in the class in views + * @param string|null $layout Layout file in views + * @param array|null $replacement Replace the {key}=>value + * @param array|null $variable PHP variables send to the view and to layout + * (can be processed by foreach, if...) + * @return Exit from PHP at the end of HTML display + */ + public function out ($data, $title = FALSE, + $viewClass = FALSE, $viewMethod = FALSE, + $layout = FALSE, $replacement = array(), + $variable = array (), $module = "") + { + if (! isset ($variable["exceptionCode"])) + $variable["exceptionCode"] = 200; + $rest = new \rest (); + $rest->display ($data, $variable["exceptionCode"]); + } +} diff --git a/route.php b/route.php index f220e18..af7e9ae 100644 --- a/route.php +++ b/route.php @@ -614,7 +614,11 @@ class route "{exceptionText}"=>$http->codetext($getCode), "{baseurl}"=>$this->baseURL(), "{baseurlmodule}"=>$this->baseURLmodule())); - $renderer->variable = $this->variable; + $renderer->variable = array_merge ($this->variable, + array ("exceptionCode"=>$getCode, + "exceptionText"=>$http->codetext($getCode), + "baseurl"=>$this->baseURL(), + "baseurlmodule"=>$this->baseURLmodule())); $renderer->run (); return true; }