Commit c2f31add authored by thibaut-felten's avatar thibaut-felten

Endpoint users

parent b8edf1f7
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
// of the directory that contains this file (index.php) // of the directory that contains this file (index.php)
// e.g. http://eden.imt-lille-douai.fr/~luc.fabresse/index.php => __ROOT_DIR = /home/luc.fabresse/public_html // e.g. http://eden.imt-lille-douai.fr/~luc.fabresse/index.php => __ROOT_DIR = /home/luc.fabresse/public_html
$rootDirectoryPath = realpath(dirname(__FILE__)); $rootDirectoryPath = realpath(dirname(__FILE__));
define ('__ROOT_DIR', $rootDirectoryPath ); define ('ROOT_DIR', $rootDirectoryPath );
// Load all application config // Load all application config
require_once(__ROOT_DIR . "/config/config.php"); require_once(ROOT_DIR . "/config/config.php");
// Load the Loader class to automatically load classes when needed // Load the Loader class to automatically load classes when needed
require_once(__ROOT_DIR . '/classes/AutoLoader.class.php'); require_once(ROOT_DIR . '/classes/AutoLoader.class.php');
// Reify the current request // Reify the current request
$request = Request::getCurrentRequest(); $request = Request::getCurrentRequest();
......
...@@ -9,37 +9,29 @@ public function __construct() { ...@@ -9,37 +9,29 @@ public function __construct() {
// This method will be automatically executed by PHP whenever it encounters an unknown class name in the source code // This method will be automatically executed by PHP whenever it encounters an unknown class name in the source code
private function load($className) { private function load($className) {
$classFile = ""; $paths = array('/classes/','/model/','/controller/');
// TODO : compute path of the file to load (cf. PHP function is_readable) $fileToLoad = null;
// it is in one of these subdirectory '/classes/', '/model/', '/controller/' $i = 0;
// if it is a model, load its sql queries file too in sql/ directory
if(strpos($className, "Controller") !==FALSE){ do{
$classFile .= __ROOT_DIR . "/controller/"; $fileToLoad = ROOT_DIR . $paths[$i] . ucfirst($className
) . '.class.php';
}else if(strpos($className, "Model") !==FALSE){ $i++;
$classFile .= __ROOT_DIR . "/model/"; } while(!is_readable($fileToLoad) && $i<count($paths));
}else if(strpos($className, "Role") !==FALSE){ if(! is_readable($fileToLoad)){
$classFile .= __ROOT_DIR . "../model/"; throw new Exception('Unknown class '.$className);
}
}else if(strpos($className, "User") !==FALSE){
$classFile .= __ROOT_DIR . "/model/"; require_once($fileToLoad);
}else if(strpos($className, "Response") !==FALSE){ if(strlen(strstr($fileToLoad,'/model/'))>0){
$classFile .= __ROOT_DIR . "/classes/"; $sqlFileToLoad = ROOT_DIR . '/sql/' . ucfirst($className) . '.sql.php';
if(is_readable($sqlFileToLoad)){
}else if(strpos($className, "Request") !==FALSE){ require_once($sqlFileToLoad);
$classFile .= __ROOT_DIR . "/classes/"; }
}else if(strpos($className, "Dispatcher") !==FALSE){
$classFile .= __ROOT_DIR . "/classes/";
}else if(strpos($className, "DatabasePDO") !==FALSE){
$classFile .= __ROOT_DIR . "/classes/";
} }
$classFile.=$className.".class.php";
include $classFile;
} }
} }
$__LOADER = new AutoLoader(); $__LOADER = new AutoLoader();
\ No newline at end of file
...@@ -19,10 +19,10 @@ class DatabasePDO extends PDO { ...@@ -19,10 +19,10 @@ class DatabasePDO extends PDO {
if(defined('DB_PORT')) if(defined('DB_PORT'))
$connectionString .= ";port=". DB_PORT; $connectionString .= ";port=". DB_PORT;
$connectionString .= ";dbname=" . DB_DATABASE; $connectionString .= ";dbname=" . DB_DBNAME;
$connectionString .= ";charset=utf8"; $connectionString .= ";charset=utf8";
parent::__construct($connectionString,DB_USERNAME,DB_PASSWORD); parent::__construct($connectionString,DB_USER,DB_PASSWORD);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} }
} }
\ No newline at end of file
...@@ -11,6 +11,8 @@ class Dispatcher { ...@@ -11,6 +11,8 @@ class Dispatcher {
} }
public static function dispatchToController($controllerName, $request) { public static function dispatchToController($controllerName, $request) {
// TODO $controllerClass = ucfirst($controllerName)."Controller";
$controller = new $controllerClass($controllerName,$request);
return $controller;
} }
} }
\ No newline at end of file
...@@ -23,7 +23,7 @@ class UsersController extends Controller { ...@@ -23,7 +23,7 @@ class UsersController extends Controller {
protected function getAllUsers() protected function getAllUsers()
{ {
$users = User::getList(); $users = User::getList();
// TODO $response = new Response(200,json_encode($users));
return $response; return $response;
} }
} }
\ No newline at end of file
<?php <?php
User::addSqlQuery('USER_LIST', User::addSqlQuery('USER_LIST',
'SELECT * FROM USER ORDER BY USER_LOGIN'); 'SELECT * FROM USERS ORDER BY ID');
User::addSqlQuery('USER_GET_WITH_LOGIN', User::addSqlQuery('USER_GET_WITH_LOGIN',
'SELECT * FROM USER WHERE USER_LOGIN=:login'); 'SELECT * FROM USERS WHERE USER_LOGIN=:login');
User::addSqlQuery('USER_CREATE', User::addSqlQuery('USER_CREATE',
'INSERT INTO USER (USER_ID, USER_LOGIN, USER_EMAIL, USER_ROLE, USER_PWD, USER_NAME, USER_SURNAME) VALUES (NULL, :login, :email, :role, :pwd, :name, :surname)'); 'INSERT INTO USERS (USER_ID, USER_LOGIN, USER_EMAIL, USER_ROLE, USER_PWD, USER_NAME, USER_SURNAME) VALUES (NULL, :login, :email, :role, :pwd, :name, :surname)');
User::addSqlQuery('USER_CONNECT', User::addSqlQuery('USER_CONNECT',
'SELECT * FROM USER WHERE USER_LOGIN=:login and USER_PWD=:password'); 'SELECT * FROM USERS WHERE USER_LOGIN=:login and USER_PWD=:password');
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment