parent
7fa20c9b4e
commit
5612ea4325
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
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($class)
|
||||
{
|
||||
global $rep;
|
||||
$filename = $class.'.php';
|
||||
$dir =array('modeles/','./','config/','controllers/', 'vues/', 'gateway/');
|
||||
foreach ($dir as $d){
|
||||
$file=$rep.$d.$filename;
|
||||
//echo $file;
|
||||
if (file_exists($file))
|
||||
{
|
||||
include $file;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -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,18 @@
|
||||
<?php
|
||||
|
||||
//gen
|
||||
$rep=__DIR__.'/../';
|
||||
|
||||
|
||||
//Vues
|
||||
|
||||
$vues['erreur']='vues/erreur.php';
|
||||
$vues['tache']='vues/tacheView.php';
|
||||
$vues['inscriptionConfirmee']='vues/validationRegister.php';
|
||||
$vues['login']='vues/login.php';
|
||||
$vues['register']='vues/register.php';
|
||||
$vues['liste']='vues/listeView.php';
|
||||
$vues['connexionConfirmee']='vues/connexionConfirmee.php';
|
||||
$vues['deconnexionConfirmee']='vues/deconnexionConfirmee.php';
|
||||
|
||||
?>
|
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
class FrontControleur
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
global $rep,$vues;
|
||||
session_start();
|
||||
$dVueErreur = array();
|
||||
try
|
||||
{
|
||||
$action = $_REQUEST['action'];
|
||||
|
||||
$acteur = $this->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);
|
||||
}*/
|
||||
}
|
||||
?>
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
class PlayerControleur{
|
||||
|
||||
function __construct() {
|
||||
global $rep,$vues, $previousPage;
|
||||
$dVueEreur = array ();
|
||||
$action=$_REQUEST['action'];
|
||||
try{
|
||||
switch($action) {
|
||||
case "Play" :
|
||||
$this->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();
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
require_once(__DIR__.'/config/config.php');
|
||||
require_once(__DIR__.'/config/Autoload.php');
|
||||
Autoload::charger();
|
||||
$con = new Connection('mysql:host=localhost;dbname=php','root','');
|
||||
$cont = new FrontControleur();
|
||||
?>
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
class Connection extends PDO {
|
||||
|
||||
private $stmt;
|
||||
|
||||
public function __construct(string $dsn, string $username, string $password) {
|
||||
|
||||
parent::__construct($dsn,$username,$password);
|
||||
$this->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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in new issue