From 9bfc904555be1c74fb1d875658611616ad77ce4e Mon Sep 17 00:00:00 2001 From: Emmanuel ROY Date: Mon, 2 Dec 2019 19:01:38 +0100 Subject: [PATCH] =?UTF-8?q?mise=20en=20place=20des=20requ=C3=A8tes=20HTTP1?= =?UTF-8?q?.1=20dans=20le=20core=20du=20MVC=20afin=20qu'elles=20soient=20u?= =?UTF-8?q?tilisable=20simplement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO: tester les requètes HTTP1.1 , sécuriser les accès par un fichier config similaire a l'applet Discourse faite pour Tinternet TODO: ajouter un plug-in symfony permettant de charger un utilisateur dans les apps a partir de l'authentification multiple TODO: lire les documentation officielles provenant des 4 plate-formes tranquillement afin de comprendre commet doit on tester ces type d'auth quitte a créé un sous domaine particulier directement hebergé sur gittea -->Sécuriser le serveur de dev --- application/class/Controlleur.php | 49 ++++++++++++++++--- .../Contrat/HttpReponseInterface.php | 10 ++++ .../Contrat/RestReponseInterface.php | 14 ++++++ application/class/Implement/HttpReponse.php | 32 ++++++++++++ application/class/Implement/RestReponse.php | 41 ++++++++++++++++ application/class/Request.php | 12 ++++- application/class/Response.php | 2 +- .../controlleurs/AcceuilHttpReponse.php | 16 ++++++ 8 files changed, 168 insertions(+), 8 deletions(-) create mode 100644 application/class/Implement/Contrat/HttpReponseInterface.php create mode 100644 application/class/Implement/Contrat/RestReponseInterface.php create mode 100644 application/class/Implement/HttpReponse.php create mode 100644 application/class/Implement/RestReponse.php create mode 100644 application/include/controlleurs/AcceuilHttpReponse.php diff --git a/application/class/Controlleur.php b/application/class/Controlleur.php index 9f0ba66..884736f 100644 --- a/application/class/Controlleur.php +++ b/application/class/Controlleur.php @@ -9,13 +9,50 @@ class Controlleur{ public function __construct($application){ - if($application->url->page['control']){ - $url_params = $application->url->page['params']; - require TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $application->url->page['name'] . '.php'; - } else { - $this->modele = new Modele($application->url->page); - $this->vue = new Vue($this); + + $requete = new MVC\Classe\Request(); + + switch ($requete->method) { + //cas des requètes PUT et DELETE + case 'PUT': + case 'DELETE': + require CONTROLLER_PATH . DIRECTORY_SEPARATOR . $application->url->page['name'] . 'HttpReponse.php'; + $reponseHttp = lcfirst($application->url->page['name']) . 'HttpReponse'; + $response = new $reponseHttp($application->url, $requete->getData()); + if ($requete->method == 'DELETE') { + $reponseHttp->delete(); + } else { + $reponseHttp->put(); + } + break; + //cas des requètes POST et GET + case 'POST': + case 'GET': + if (!file_exists(CONTROLLER_PATH . DIRECTORY_SEPARATOR . $application->url->page['name'] . '')) { + require CONTROLLER_PATH . DIRECTORY_SEPARATOR . $application->url->page['name'] . 'HttpReponse.php'; + $reponseHttp = lcfirst($application->url->page['name']) . 'HttpReponse'; + $response = new $reponseHttp($application->url, $requete->getData()); + if ($requete->method == 'POST') { + $reponseHttp->post(); + } else { + $reponseHttp->get(); + } + break; + } + + + default: + + if ($application->url->page['control']) { + $url_params = $application->url->page['params']; + require TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $application->url->page['name'] . '.php'; + } else { + $this->modele = new Modele($application->url->page); + $this->vue = new Vue($this); + } } + + } } diff --git a/application/class/Implement/Contrat/HttpReponseInterface.php b/application/class/Implement/Contrat/HttpReponseInterface.php new file mode 100644 index 0000000..edd3daa --- /dev/null +++ b/application/class/Implement/Contrat/HttpReponseInterface.php @@ -0,0 +1,10 @@ +url = $url; + $this->params = $url['params']; + $this->data = $requestData; + } + + public function put() + { + + } + + public function delete() + { + + } + +} \ No newline at end of file diff --git a/application/class/Implement/RestReponse.php b/application/class/Implement/RestReponse.php new file mode 100644 index 0000000..e333def --- /dev/null +++ b/application/class/Implement/RestReponse.php @@ -0,0 +1,41 @@ +url = $url; + $this->params = $url['params']; + $this->data = $requestData; + } + + public function get() + { + + } + + public function post() + { + + } + + public function put() + { + + } + + public function delete() + { + + } +} \ No newline at end of file diff --git a/application/class/Request.php b/application/class/Request.php index f8980c9..125f56e 100644 --- a/application/class/Request.php +++ b/application/class/Request.php @@ -24,8 +24,13 @@ class Request case 'POST': break; case 'PUT': - $this->data = json_decode(file_get_contents("php://input"), true); + //$this->data['GET'] = ... + //POST DATA except enctype="multipart/form-data" + $this->data['POST'] = json_decode(file_get_contents("php://input"), true); case 'DELETE': + //$this->data['GET'] = ... + //POST DATA except enctype="multipart/form-data" + $this->data['POST'] = json_decode(file_get_contents("php://input"), true); break; default: // Requête invalide @@ -34,4 +39,9 @@ class Request } } + public function getData() + { + return $this->data; + } + } \ No newline at end of file diff --git a/application/class/Response.php b/application/class/Response.php index 7091613..8eda6e4 100644 --- a/application/class/Response.php +++ b/application/class/Response.php @@ -104,7 +104,7 @@ class Response public function setGetParamsUrl($url, $params = array()) { - $this->url = $url . (strpos($this->url, '?') ? '' : '?') . http_build_query($params); + $this->url = $url . (strpos($url, '?') ? '&' : '?') . http_build_query($params); return $this; } diff --git a/application/include/controlleurs/AcceuilHttpReponse.php b/application/include/controlleurs/AcceuilHttpReponse.php new file mode 100644 index 0000000..4f4ac54 --- /dev/null +++ b/application/include/controlleurs/AcceuilHttpReponse.php @@ -0,0 +1,16 @@ +params . "
" . $this->data; + } + + public function delete() + { + + } +} \ No newline at end of file