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 +