From afedafc2a2e49c7dd98d466b966deea7c8db0a73 Mon Sep 17 00:00:00 2001 From: Emmanuel ROY Date: Thu, 5 Dec 2019 14:05:38 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20d'un=20routage=20Symfony=20sur=20une=20?= =?UTF-8?q?classe=20contenu=20dans=20les=20include=20avec=20la=20cr=C3=A9a?= =?UTF-8?q?tion=20de=20la=20classe=20Conduit=20permettant=20de=20rendre=20?= =?UTF-8?q?un=20page=20conduite=20par=20la=20route=20Symfony,=20ajout=20de?= =?UTF-8?q?=20la=20class=20asynchonous=20permettant=20d'injecter=20du=20js?= =?UTF-8?q?=20et=20du=20css?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO: finir la class asynchonous et tester cette version de dev sur un vrai serveur appartenant à la TT+ TODO: ajouter les modules gestionMedia gestionMenu gestionPage (gestionBackendCms) FIXME: appel curl ou fopen d'une methode http depuis une action ou un controlleur. TODO: sécuriser les accès HTTP1.1 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/Application.php | 31 +++----------- application/class/Asynchonous.php | 41 ++++++++++++++++++ application/class/Controlleur.php | 13 +++++- application/class/Dispacher.php | 46 +++++++++++++++++++++ application/class/Implement/Conduit.php | 22 ++++++++++ application/config/define-constantes.php | 1 + application/config/files/routing.yml | 4 +- application/include/conduits/FooConduit.php | 20 +++++++++ application/include/vues/view/foo.blade.php | 18 ++++++++ 9 files changed, 167 insertions(+), 29 deletions(-) create mode 100644 application/class/Asynchonous.php create mode 100644 application/class/Dispacher.php create mode 100644 application/class/Implement/Conduit.php create mode 100644 application/include/conduits/FooConduit.php create mode 100644 application/include/vues/view/foo.blade.php diff --git a/application/class/Application.php b/application/class/Application.php index ff01b1b..c65a56c 100644 --- a/application/class/Application.php +++ b/application/class/Application.php @@ -2,12 +2,6 @@ namespace MVC\Classe; -use Symfony\Component\Config\FileLocator as FileLocator; -use Symfony\Component\Routing\Matcher\UrlMatcher as UrlMatcher; -use Symfony\Component\Routing\RequestContext as RequestContext; -use Symfony\Component\Routing\Loader\YamlFileLoader as YamlFileLoader; -use Symfony\Component\Routing\Exception\ResourceNotFoundException; - require APPLICATION_PATH . DIRECTORY_SEPARATOR . "parameters.php"; class Application @@ -15,35 +9,20 @@ class Application public $http; public $url; public $browser; + public $route; public function __construct(){ $this->http = new HttpMethod(); $this->browser = new Browser(); $this->url = new Url($this->http->method, $this->browser->isAppRequest()); + + $dispacher = new Dispacher(); + $this->route = $dispacher->route; } public function launch(){ - try { - //load config file - $fileLocator = new FileLocator(array(CONFIG_PATH . DIRECTORY_SEPARATOR . 'files')); - $loader = new YamlFileLoader($fileLocator); - $routes = $loader->load('routing.yml'); - - //create context - $context = new RequestContext('/'); - $matcher = new UrlMatcher($routes, $context); - - // Find the current route - $parameters = $matcher->match($_SERVER['REQUEST_URI']); - - echo '
';
-            print_r($parameters);
-            die();
-        } catch (ResourceNotFoundException $e) {
-            echo $e->getMessage();
-        }
-
+        //print_r($this->route);
         $controlleur = new Controlleur($this);
         //si la page n'est un controlleur d'action alors on affiche l'écran
         if(!$this->url->page['control']) {
diff --git a/application/class/Asynchonous.php b/application/class/Asynchonous.php
new file mode 100644
index 0000000..f6ff387
--- /dev/null
+++ b/application/class/Asynchonous.php
@@ -0,0 +1,41 @@
+_css = "";
+        $this->_javascript = "";
+    }
+
+    public function addCss($code)
+    {
+        $this->_css .= "\n";
+        $this->_css .= $code;
+    }
+
+    public function addJs($code)
+    {
+        $this->_javascript .= "\n";
+        $this->_javascript .= $code;
+    }
+
+    public function printCss()
+    {
+        echo $this->_css;
+    }
+
+    public function printJs()
+    {
+        echo $this->_javascript;
+    }
+
+}
\ No newline at end of file
diff --git a/application/class/Controlleur.php b/application/class/Controlleur.php
index 27124f3..1ebd43b 100644
--- a/application/class/Controlleur.php
+++ b/application/class/Controlleur.php
@@ -22,7 +22,18 @@ class Controlleur{
                 }
 
             default:
-                if ($application->url->page['control']) {
+                if ($application->route != NULL) {
+                    $conduit = explode('::', $application->route['controller']);
+                    require CONDUIT_PATH . DIRECTORY_SEPARATOR . $conduit[0] . '.php';
+                    $conduitRoute = "\\" . $conduit[0];
+                    $method = strtolower($conduit[1]);
+                    $class = new $conduitRoute();
+                    $class->initialize($application->route);
+                    $this->vue = new VueVide();
+                    ob_start();
+                    $class->$method();
+                    $this->vue->ecran = ob_get_clean();
+                } else if ($application->url->page['control']) {
                     $url_params = $application->url->page['params'];
                     require TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $application->url->page['name'] . '.php';
                 } else {
diff --git a/application/class/Dispacher.php b/application/class/Dispacher.php
new file mode 100644
index 0000000..d7c37dc
--- /dev/null
+++ b/application/class/Dispacher.php
@@ -0,0 +1,46 @@
+route = NULL;
+        } else {
+            //Test the route from config file
+            try {
+                //load config file
+                $fileLocator = new FileLocator(array(CONFIG_PATH . DIRECTORY_SEPARATOR . 'files'));
+                $loader = new YamlFileLoader($fileLocator);
+                $routes = $loader->load('routing.yml');
+
+                //create context
+                $context = new RequestContext('/');
+                $matcher = new UrlMatcher($routes, $context);
+
+                // Find the current route
+                $parameters = $matcher->match($_SERVER['REQUEST_URI']);
+
+                $this->route = $parameters;
+            } catch (ResourceNotFoundException $e) {
+                $this->route = NULL;
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/application/class/Implement/Conduit.php b/application/class/Implement/Conduit.php
new file mode 100644
index 0000000..cc63e1f
--- /dev/null
+++ b/application/class/Implement/Conduit.php
@@ -0,0 +1,22 @@
+ $value) {
+
+            if ($key != "controller") {
+                if ($key != "_route") {
+                    $this->$key = $value;
+                }
+            }
+        }
+        return;
+    }
+}
\ No newline at end of file
diff --git a/application/config/define-constantes.php b/application/config/define-constantes.php
index ae65056..dd3bb8b 100644
--- a/application/config/define-constantes.php
+++ b/application/config/define-constantes.php
@@ -1,6 +1,7 @@
 render('foo', ['page_title' => 'Foo', 'description' => 'FooConduit']);
+    }
+
+    // Route('/foo/{id}')
+    public function load()
+    {
+        $this->render('foo', array('page_title' => 'Foo', 'description' => 'FooConduit', 'id' => $this->id));
+
+    }
+}
\ No newline at end of file
diff --git a/application/include/vues/view/foo.blade.php b/application/include/vues/view/foo.blade.php
new file mode 100644
index 0000000..3c2678d
--- /dev/null
+++ b/application/include/vues/view/foo.blade.php
@@ -0,0 +1,18 @@
+@extends('body')
+
+@section('sidebar')
+    @parent
+
+    

This is appended to the master sidebar.

+@endsection + +@section('content') +

Foo

+


+ S'authentifier ? +
+ Variable Loader: + {{ $id ? $id : 'init' }} + +@endsection +