From 5612ea43259d9f50740b187079193a9e0cd170d4 Mon Sep 17 00:00:00 2001 From: pisouvigne Date: Wed, 3 Jun 2020 13:42:39 +0200 Subject: [PATCH] mvc debut --- site/config/Autoload.php | 51 +++++++++ site/config/SplClassLoader.php | 155 ++++++++++++++++++++++++++ site/config/config.php | 18 +++ site/controllers/FrontControleur.php | 85 ++++++++++++++ site/controllers/PlayerControleur.php | 65 +++++++++++ site/index.php | 7 ++ site/modeles/Connection.php | 33 ++++++ site/vues/jeu.html | 5 +- 8 files changed, 418 insertions(+), 1 deletion(-) create mode 100644 site/config/Autoload.php create mode 100644 site/config/SplClassLoader.php create mode 100644 site/config/config.php create mode 100644 site/controllers/FrontControleur.php create mode 100644 site/controllers/PlayerControleur.php create mode 100644 site/index.php create mode 100644 site/modeles/Connection.php diff --git a/site/config/Autoload.php b/site/config/Autoload.php new file mode 100644 index 0000000..965d5d5 --- /dev/null +++ b/site/config/Autoload.php @@ -0,0 +1,51 @@ + \ No newline at end of file diff --git a/site/config/SplClassLoader.php b/site/config/SplClassLoader.php new file mode 100644 index 0000000..98565bf --- /dev/null +++ b/site/config/SplClassLoader.php @@ -0,0 +1,155 @@ +. + */ + +/** + * 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 + * @author Roman S. Borschel + * @author Matthew Weier O'Phinney + * @author Kris Wallsmith + * @author Fabien Potencier + */ +class SplClassLoader +{ + private $_fileExtension = '.php'; + private $_namespace; + private $_includePath; + private $_namespaceSeparator = '\\'; + + /** + * Creates a new SplClassLoader 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; + } + } +} \ No newline at end of file diff --git a/site/config/config.php b/site/config/config.php new file mode 100644 index 0000000..c97efe6 --- /dev/null +++ b/site/config/config.php @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/site/controllers/FrontControleur.php b/site/controllers/FrontControleur.php new file mode 100644 index 0000000..d08bf70 --- /dev/null +++ b/site/controllers/FrontControleur.php @@ -0,0 +1,85 @@ +isGoodAction($action); + + if(empty($acteur)) + { + $dVueErreur[] = 'Action invalide'; + require('pageErreur'); + } + elseif($acteur == 'FrontControleur') + { + switch ($action) { + case 'Play' : + $this->Play($dVueErreur); + break; + } + } + else + { + $controleur = new $acteur(); + } + } + catch(Exception $ex) + { + switch($action) + { + case 'Play' : + require ($rep.$vues['register']); + break; + } + } + } + + function isGoodAction($action) + { + $listeActions=array( + 'Player' => array('Play', NULL), + ); + + if(in_array($action, $listeActions['Player'])) + { + return 'PlayerControleur'; + } + else + return; + } + + + + /*function Login(array &$dVueErreur) + { + global $rep,$vues; + $email = htmlspecialchars($_POST['email']); + $password = htmlspecialchars($_POST['password']); + Validation::isEmailException($email,$dVueErreur); + Validation::isPasswordMatchException($password, $dVueErreur); + $model = new UserManager(); + $retour = $model->connect($email, $password, $dVueErreur); + $controleur = new VisiteurControleur(); + $controleur->GoToListe($dVueErreur); + + } + + + function LogOut(array &$dVueErreur) + { + global $rep,$vues; + $model = new UserManager(); + $model->disconnect(); + $controleur = new VisiteurControleur(); + $controleur->GoToListe($dVueErreur); + }*/ + } +?> \ No newline at end of file diff --git a/site/controllers/PlayerControleur.php b/site/controllers/PlayerControleur.php new file mode 100644 index 0000000..9eb6abb --- /dev/null +++ b/site/controllers/PlayerControleur.php @@ -0,0 +1,65 @@ +Play($dVueEreur); + break; + } + + } catch (PDOException $e) + { + + $dVueErreur[] = "Erreur inattendue!!! "; + require ($rep.$vues['liste']); + + } + catch (Exception $e2) + { + switch ($action) { + case 'CreerToDoListU': + $controleur= new VisiteurControleur(); + $controleur->GoToListe($dVueEreur); + break; + + case 'PasserToDoListPublique' : + $controleur= new VisiteurControleur(); + $controleur->GoToListe($dVueEreur); + break; + + case 'PasserToDoListPrive' : + $controleur= new VisiteurControleur(); + $controleur->GoToListe($dVueEreur); + break; + + default: + $controleur= new VisiteurControleur(); + $controleur->GoToListe($dVueEreur); + break; + } + } + + } + + function Play(array &$dVueErreur) + { + global $rep,$vues; + $email = htmlspecialchars($_POST['email']); + $password1 = htmlspecialchars($_POST['password1']); + $password2 = htmlspecialchars($_POST['password2']); + $pseudo = htmlspecialchars($_POST['pseudo']); + Validation::isVideException($pseudo,$dVueErreur); + Validation::isEmailException($email,$dVueErreur); + Validation::isPasswordValidException($password1, $password2,$dVueErreur); + $model = new UserManager(); + $model->createUser($email, $password1, $pseudo, $dVueErreur); + $controleur = new VisiteurControleur(); + $controleur->GoToLogin(); + } +} \ No newline at end of file diff --git a/site/index.php b/site/index.php new file mode 100644 index 0000000..e63197e --- /dev/null +++ b/site/index.php @@ -0,0 +1,7 @@ + diff --git a/site/modeles/Connection.php b/site/modeles/Connection.php new file mode 100644 index 0000000..b4ce991 --- /dev/null +++ b/site/modeles/Connection.php @@ -0,0 +1,33 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} + + +/** * @param string $query + * @param array $parameters * + * @return bool Returns `true` on success, `false` otherwise +*/ + +public function executeQuery(string $query, array $parameters = []) : bool{ + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } + + return $this->stmt->execute(); +} + +public function getResults() : array { + return $this->stmt->fetchall(); + +} +} + +?> diff --git a/site/vues/jeu.html b/site/vues/jeu.html index f9cb76d..728eb51 100644 --- a/site/vues/jeu.html +++ b/site/vues/jeu.html @@ -26,7 +26,7 @@ -
+