parent
0c09742cb9
commit
6fecace1ae
@ -0,0 +1 @@
|
||||
<mxfile host="app.diagrams.net" modified="2022-11-18T08:53:01.103Z" agent="5.0 (X11)" etag="T0h4_q4_bEF78AhTsrVm" version="20.5.3" type="device"><diagram id="YT-LZJT85HNrmgPDGNfd" name="Page-1">7Vpdj5s4FP010T5NhG0+H5NMp6NVV5o2/XxaEfAEq4BZYyZJf/2aYBKw6ZBOSUh3q5Ey+GJsc+65514ME7RItq+Zn0V/0RDHE2iE2wm6nUDoAlP8loZdZYCGCSrLmpGwsjUMS/INS6MhrQUJcd7qyCmNOcnaxoCmKQ54y+YzRjftbo80bs+a+WusGZaBH+vWTyTkkbwv6Bzt95iso3pmYHvVmcSvO8s7ySM/pJuGCb2aoAWjlFdHyXaB4xK8GpfqurvvnD0sjOGUn3KBh2i0zJbv33zdBm9v7nPjLXt/I0d58uNC3rBcLN/VCGwiwvEy84OyvRFenqB5xJNYtIA49POswv2RbLGYaq6vq54EM463DZNc52tME8zZTnSpzzoSM8maG1O2N0cX2HWfqAH/wehLt68PYx+REQcSnB8ACnYAZcdi2nlInsThujz8kGNWm8UsjTMdnWvTiqkW9VLFIYJIWXlYJPEs4JSJPiW0RJD2jb/C8QPNCSc0FV1WlHOaNDrMYrIuT3CquJEWPCYpXhzCyBjGlV7bkxDpnkRdjjyXH5Hmx1mYkPQ/BTLyRgbZ7FcVnIazUp5L/GIafBVACJPUf2BXzTtSzrtHqYEio0UallLzPHw4bCn7d8EzprZtO229sTT8QA0Ww7HPyVM7PXQhKCd8oEQs7ChthtX2las4IacFC7C8qinnfQMBZSDuszXmzwxUd6SPjzlu9dk7/YDUy3lgazxY4mOuLrVSZUUci8QuGvOerDNA0FjIbAEIgB41AHaEjeqxwcLG1eH6g6R5wAjDo0IFvTZU1thIgRPqlobCpDTFL9KQKhj7y4Iq1vojoVeTGohaHYBaw4gQUhKGqZZNp4qQaSoDwdNEaCiBAV1l2Sg8qJ9N+ojg/ibCWYig13ULNlmgyczbl+R+UqpiusrLf0WK964KonFlFaH+4vjCuqpXbh8pYWXOFg/hArM9pFAAl4+LnKtUvOMjZ12JEtWR0KtE8LqUCA2kRCo1Lq5EetE7EhHM30QYlQiORoRlkWWMJGVGMoq0/OEkJrnPcTHus5AKugVH11P9YegsYdQbHbUbryQ8Dl6oWY1+1fDwNAfLUoPTgu+rjfiqag4TtB+CzY5N6cvGSD3Zle+znWMXDbTJC1XynryLpgwE1HA6cxTAro0M7VXBR5KTKkf8ku8WBgg+9TXCyBvcUC/ypHh1aJaRFauYBNf1xHQzeoaHen30MxleQMN2n5uNL2VjatXN223z5O3upwvsk0sIeGW7f0qxh4yBSojDAi8lnldTI3pX5eDBakTLvJiD53fvgsW3L//cf/hEPucPf/8JNu86v06QW3kymTVbJA3iIsQH47rVpTvfNehBM5y2qyNYJlU/j/YMAf3UUdx/5v0b+1m9N6YGVF9webriD1SPIVshivlSxsGegS77VrOTlfpW8/+AladuJvWy0oPtOsQ+GylNz5o6NgCmK5ZqWshrv+SHljN1XQA8w3VNy62TyQ8z1nanyHJM4CKhl+JPiTk4BY4jUq7tuKbhIfuCdBbN4+dlVffjR3ro1b8=</diagram></mxfile>
|
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace controleur;
|
||||
|
||||
class Controleur {
|
||||
|
||||
function __construct() {
|
||||
global $rep,$vues; // nécessaire pour utiliser variables globales
|
||||
// on démarre ou reprend la session
|
||||
session_start();
|
||||
|
||||
|
||||
//debut
|
||||
|
||||
//on initialise un tableau d'erreur
|
||||
$dVueEreur = array ();
|
||||
|
||||
try{
|
||||
$action=$_REQUEST['action'];
|
||||
|
||||
switch($action) {
|
||||
|
||||
//pas d'action, on réinitialise 1er appel
|
||||
case NULL:
|
||||
$this->Reinit();
|
||||
break;
|
||||
|
||||
|
||||
case "validationFormulaire":
|
||||
$this->ValidationFormulaire($dVueEreur);
|
||||
break;
|
||||
|
||||
//mauvaise action
|
||||
default:
|
||||
$dVueEreur[] = "Erreur d'appel php";
|
||||
require ($rep.$vues['vuephp1']);
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (PDOException $e)
|
||||
{
|
||||
//si erreur BD, pas le cas ici
|
||||
$dVueEreur[] = "Erreur inattendue!!! ";
|
||||
require ($rep.$vues['erreur']);
|
||||
|
||||
}
|
||||
catch (Exception $e2)
|
||||
{
|
||||
$dVueEreur[] = "Erreur inattendue!!! ";
|
||||
require ($rep.$vues['erreur']);
|
||||
}
|
||||
|
||||
|
||||
//fin
|
||||
exit(0);
|
||||
}//fin constructeur
|
||||
|
||||
|
||||
function Reinit() {
|
||||
global $rep,$vues;
|
||||
|
||||
$dVue = array (
|
||||
'nom' => "",
|
||||
'age' => 0,
|
||||
);
|
||||
require ($rep.$vues['vuephp1']);
|
||||
}
|
||||
|
||||
function ValidationFormulaire(array $dVueEreur) {
|
||||
global $rep,$vues;
|
||||
|
||||
|
||||
//si exception, ca remonte !!!
|
||||
$nom=$_POST['txtNom']; // txtNom = nom du champ texte dans le formulaire
|
||||
$age=$_POST['txtAge'];
|
||||
\config\Validation::val_form($nom,$age,$dVueEreur);
|
||||
|
||||
$model = new \Modele\Simplemodel();
|
||||
$data=$model->get_data();
|
||||
|
||||
$dVue = array (
|
||||
'nom' => $nom,
|
||||
'age' => $age,
|
||||
'data' => $data,
|
||||
);
|
||||
require ($rep.$vues['vuephp1']);
|
||||
}
|
||||
|
||||
}//fin class
|
||||
|
||||
?>
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace modeles;
|
||||
|
||||
class Simplemodel
|
||||
{
|
||||
|
||||
//constructeur
|
||||
//vide
|
||||
|
||||
|
||||
function get_data() :string
|
||||
{
|
||||
return "Mon modèle ne fait rien";
|
||||
}
|
||||
|
||||
//fin modèles
|
||||
}
|
||||
?>
|
Binary file not shown.
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
//prs0 compliant
|
||||
class Autoload
|
||||
{
|
||||
private static $_instance = null;
|
||||
|
||||
public static function charger()
|
||||
{
|
||||
if(null !== self::$_instance) {
|
||||
throw new RuntimeException(sprintf('%s is already started', __CLASS__));
|
||||
}
|
||||
|
||||
self::$_instance = new self();
|
||||
|
||||
|
||||
if(!spl_autoload_register(array(self::$_instance, '_autoload'), false)) {
|
||||
throw RuntimeException(sprintf('%s : Could not start the autoload', __CLASS__));
|
||||
}
|
||||
}
|
||||
|
||||
public static function shutDown()
|
||||
{
|
||||
if(null !== self::$_instance) {
|
||||
|
||||
if(!spl_autoload_unregister(array(self::$_instance, '_autoload'))) {
|
||||
throw new RuntimeException('Could not stop the autoload');
|
||||
}
|
||||
|
||||
self::$_instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function _autoload($className)
|
||||
{
|
||||
|
||||
echo $className;
|
||||
$folder = "./";
|
||||
$className = ltrim($className, '\\');
|
||||
$fileName = '';
|
||||
$namespace = '';
|
||||
if ($lastNsPos = strripos($className, '\\')) {
|
||||
$namespace = substr($className, 0, $lastNsPos);
|
||||
$className = substr($className, $lastNsPos + 1);
|
||||
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
|
||||
|
||||
include $folder . $fileName;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SplClassLoader implementation that implements the technical interoperability
|
||||
* standards for PHP 5.3 namespaces and class names.
|
||||
*
|
||||
* http://groups.google.com/group/php-standards/web/psr-0-final-proposal?pli=1
|
||||
*
|
||||
* // Example which loads classes for the Doctrine Common package in the
|
||||
* // Doctrine\Common namespace.
|
||||
* $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine');
|
||||
* $classLoader->register();
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
* @author Roman S. Borschel <roman@code-factory.org>
|
||||
* @author Matthew Weier O'Phinney <matthew@zend.com>
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.org>
|
||||
*/
|
||||
class SplClassLoader
|
||||
{
|
||||
private $_fileExtension = '.php';
|
||||
private $_namespace;
|
||||
private $_includePath;
|
||||
private $_namespaceSeparator = '\\';
|
||||
|
||||
/**
|
||||
* Creates a new <tt>SplClassLoader</tt> that loads classes of the
|
||||
* specified namespace.
|
||||
*
|
||||
* @param string $ns The namespace to use.
|
||||
*/
|
||||
public function __construct(string $ns = null, string $includePath = null)
|
||||
{
|
||||
$this->_namespace = $ns;
|
||||
$this->_includePath = $includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the namespace separator used by classes in the namespace of this class loader.
|
||||
*
|
||||
* @param string $sep The separator to use.
|
||||
*/
|
||||
public function setNamespaceSeparator(string $sep)
|
||||
{
|
||||
$this->_namespaceSeparator = $sep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace seperator used by classes in the namespace of this class loader.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getNamespaceSeparator()
|
||||
{
|
||||
return $this->_namespaceSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base include path for all class files in the namespace of this class loader.
|
||||
*
|
||||
* @param string $includePath
|
||||
*/
|
||||
public function setIncludePath(string $includePath)
|
||||
{
|
||||
$this->_includePath = $includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the base include path for all class files in the namespace of this class loader.
|
||||
*
|
||||
* @return string $includePath
|
||||
*/
|
||||
public function getIncludePath()
|
||||
{
|
||||
return $this->_includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file extension of class files in the namespace of this class loader.
|
||||
*
|
||||
* @param string $fileExtension
|
||||
*/
|
||||
public function setFileExtension($fileExtension)
|
||||
{
|
||||
$this->_fileExtension = $fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file extension of class files in the namespace of this class loader.
|
||||
*
|
||||
* @return string $fileExtension
|
||||
*/
|
||||
public function getFileExtension()
|
||||
{
|
||||
return $this->_fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs this class loader on the SPL autoload stack.
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstalls this class loader from the SPL autoloader stack.
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $className The name of the class to load.
|
||||
* @return void
|
||||
*/
|
||||
public function loadClass(string $className)
|
||||
{
|
||||
if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
|
||||
$fileName = '';
|
||||
$namespace = '';
|
||||
if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
|
||||
$namespace = substr($className, 0, $lastNsPos);
|
||||
$className = substr($className, $lastNsPos + 1);
|
||||
$fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
|
||||
|
||||
require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace config;
|
||||
|
||||
class Validation {
|
||||
|
||||
static function val_action($action) {
|
||||
|
||||
if (!isset($action)) {
|
||||
throw new Exception('pas d\'action');
|
||||
//on pourrait aussi utiliser
|
||||
//$action = $_GET['action'] ?? 'no';
|
||||
// This is equivalent to:
|
||||
//$action = if (isset($_GET['action'])) $action=$_GET['action'] else $action='no';
|
||||
}
|
||||
}
|
||||
|
||||
static function val_form(string &$nom, string &$age, &$dVueEreur) {
|
||||
|
||||
if (!isset($nom)||$nom=="") {
|
||||
$dVueEreur[] = "pas de nom";
|
||||
$nom="";
|
||||
}
|
||||
|
||||
if ($nom != filter_var($nom, FILTER_SANITIZE_STRING))
|
||||
{
|
||||
$dVueEreur[] = "testative d'injection de code (attaque sécurité)";
|
||||
$nom="";
|
||||
|
||||
}
|
||||
|
||||
if (!isset($age)||$age==""||!filter_var($age, FILTER_VALIDATE_INT)) {
|
||||
$dVueEreur[] = "pas d'age ";
|
||||
$age=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
//gen
|
||||
$rep=__DIR__.'/../';
|
||||
|
||||
// liste des modules à inclure
|
||||
|
||||
//$dConfig['includes']= array('controleur/Validation.php');
|
||||
|
||||
|
||||
|
||||
//BD
|
||||
|
||||
$base="sasa";
|
||||
$login="";
|
||||
$mdp="";
|
||||
|
||||
//Vues
|
||||
|
||||
$vues['erreur']='vues/erreur.php';
|
||||
$vues['vuephp1']='vues/vuephp1.php';
|
||||
|
||||
|
||||
?>
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
//si controller pas objet
|
||||
// header('Location: controller/controller.php');
|
||||
|
||||
//si controller objet
|
||||
|
||||
//chargement config
|
||||
require_once(__DIR__.'/config/config.php');
|
||||
|
||||
//chargement autoloader pour autochargement des classes
|
||||
require_once(__DIR__.'/config/Autoload.php');
|
||||
Autoload::charger();
|
||||
|
||||
$cont = new Controleur();
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in new issue