ajout d'un routage Symfony sur une classe contenu dans les include avec la création de la classe Conduit permettant de rendre un page conduite par la route Symfony, ajout de la class asynchonous permettant d'injecter du js et du css
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
This commit is contained in:
parent
df2f1e1cf5
commit
afedafc2a2
|
@ -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 '<pre>';
|
||||
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']) {
|
||||
|
|
41
application/class/Asynchonous.php
Normal file
41
application/class/Asynchonous.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace MVC\Classe;
|
||||
|
||||
|
||||
class Asynchonous
|
||||
{
|
||||
|
||||
private $_css;
|
||||
private $_javascript;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->_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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
|
46
application/class/Dispacher.php
Normal file
46
application/class/Dispacher.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
class Dispacher
|
||||
{
|
||||
|
||||
public $route;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
echo $_SERVER['REQUEST_URI'];
|
||||
//Avoid callback from empty homepage
|
||||
if ($_SERVER['REQUEST_URI'] == '/' || $_SERVER['REQUEST_URI'] == '') {
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
application/class/Implement/Conduit.php
Normal file
22
application/class/Implement/Conduit.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace MVC\Classe\Implement;
|
||||
|
||||
|
||||
class Conduit extends Action
|
||||
{
|
||||
public function initialize($var)
|
||||
{
|
||||
//Export variable from conduit
|
||||
foreach ($var as $key => $value) {
|
||||
|
||||
if ($key != "controller") {
|
||||
if ($key != "_route") {
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
define("APPLICATION_PATH", dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "application");
|
||||
define("MODULES_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "modules");
|
||||
define("CONDUIT_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "conduits");
|
||||
define("CONTROLLERS_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs");
|
||||
define("CONFIG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "config");
|
||||
define("LOG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "logs");
|
||||
|
|
|
@ -4,11 +4,11 @@ home_route:
|
|||
|
||||
foo_route:
|
||||
path: /foo
|
||||
defaults: { controller: 'FooController::indexAction' }
|
||||
defaults: { controller: 'FooConduit::index' }
|
||||
|
||||
foo_placeholder_route:
|
||||
path: /foo/{id}
|
||||
defaults: { controller: 'FooController::loadAction' }
|
||||
defaults: { controller: 'FooConduit::load' }
|
||||
requirements:
|
||||
id: '[0-9]+'
|
||||
|
||||
|
|
20
application/include/conduits/FooConduit.php
Normal file
20
application/include/conduits/FooConduit.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
|
||||
use MVC\Classe\Implement\Conduit;
|
||||
|
||||
class FooConduit extends Conduit
|
||||
{
|
||||
// Route('/foo')
|
||||
public function index()
|
||||
{
|
||||
$this->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));
|
||||
|
||||
}
|
||||
}
|
18
application/include/vues/view/foo.blade.php
Normal file
18
application/include/vues/view/foo.blade.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
@extends('body')
|
||||
|
||||
@section('sidebar')
|
||||
@parent
|
||||
|
||||
<p>This is appended to the master sidebar.</p>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<h1>Foo</h1>
|
||||
<br/><br/><br/>
|
||||
<a href="{{ \MVC\Classe\Url::link_rewrite(false, 'authentification', []) }}">S'authentifier ?</a>
|
||||
<hr/>
|
||||
Variable Loader:
|
||||
{{ $id ? $id : 'init' }}
|
||||
|
||||
@endsection
|
||||
|
Loading…
Reference in a new issue