Moved from phpunit->kahlan + autoloader fix
This commit is contained in:
parent
5368fe4edf
commit
fd1ae3a9c5
|
@ -84,7 +84,7 @@
|
|||
throw new \Exception('Missing classname for autoloader.');
|
||||
|
||||
/* (3) Detect if build class or lib class */
|
||||
$type = $path[0] === 'lib' ? 'lib' : 'build';
|
||||
$type = $path[0] === 'lib' ? 'lib' : 'build';
|
||||
|
||||
|
||||
/* [2] Manage type and check file
|
||||
|
@ -103,7 +103,6 @@
|
|||
}
|
||||
|
||||
// On definit l'autoloader comme autoloader (obvious)
|
||||
require_once __ROOT__.'/lib/vendor/autoload.php';
|
||||
spl_autoload_register('autoloader', false, true);
|
||||
|
||||
|
||||
|
|
|
@ -11,17 +11,10 @@
|
|||
"require-dev": {
|
||||
"phpro/grumphp": "^0.11.5",
|
||||
"jakub-onderka/php-parallel-lint": "^0.9.2",
|
||||
"phpunit/phpunit": "^6.1"
|
||||
"phpunit/phpunit": "^6.1",
|
||||
"crysalead/kahlan": "^2.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"database\\": "build/database",
|
||||
"api\\": "build/api",
|
||||
"error\\": "build/error",
|
||||
"orm\\": "build/orm",
|
||||
"http\\": "build/http",
|
||||
"router\\": "build/router",
|
||||
"viewer\\": "build/viewer"
|
||||
}
|
||||
"files": ["autoloader.php", "lib/vendor/autoload.php"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ parameters:
|
|||
bin_dir: vendor/bin
|
||||
tasks:
|
||||
phplint: ~
|
||||
phpunit:
|
||||
config_file: phpunit/phpunit.xml
|
||||
always_execute: true
|
||||
kahlan: ~
|
||||
jsonlint:
|
||||
detect_key_conflicts: true
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
require_once '../autoloader.php';
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
use \router\core\Router;
|
||||
use \api\core\Request;
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
|
||||
debug();
|
||||
|
||||
|
||||
// DEFAULT SESSION CREDENTIALS
|
||||
echo '{"data1": "'.session_id().'"}';
|
||||
// echo '"data2": "'. ( $_SESSION['session_token']==$_COOKIE['session_token'] ? 'YES' : 'NO' ). '"}';
|
||||
|
||||
|
||||
?>
|
|
@ -1,12 +0,0 @@
|
|||
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
|
||||
use \api\core\Authentification;
|
||||
use \database\core\Repo;
|
||||
|
||||
|
||||
var_dump( Authentification::auth() );
|
||||
|
||||
var_dump( $_SESSION );
|
||||
|
||||
?>
|
|
@ -1,476 +0,0 @@
|
|||
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
|
||||
|
||||
var_dump(__ROOT__);
|
||||
exit();
|
||||
use \api\core\ModuleRequest;
|
||||
use \manager\sessionManager;
|
||||
use \manager\ResourceDispatcher;
|
||||
use \error\core\Error;
|
||||
use \database\core\Repo;
|
||||
use \database\core\DatabaseDriver;
|
||||
|
||||
|
||||
use \orm\core\Table;
|
||||
use \orm\core\Rows;
|
||||
use \orm\core\Row;
|
||||
use \orm\core\SQLBuilder;
|
||||
|
||||
debug();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* INSERTION DES UTILISATEURS DANS LA BDD DEPUIS JSON
|
||||
*
|
||||
*
|
||||
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
||||
*
|
||||
*/
|
||||
function insertUsersFromJSON(){
|
||||
$json = file_get_contents(__ROOT__.'/config/generated_users.json');
|
||||
$json = json_decode( $json, true );
|
||||
|
||||
// Pour chaque entree
|
||||
foreach( $json as $user ){
|
||||
|
||||
// Creation de la requete
|
||||
$request = new ModuleRequest('userDefault/create', [
|
||||
'code' => $user['code'],
|
||||
'username' => $user['username'],
|
||||
'firstname' => $user['firstname'],
|
||||
'lastname' => $user['lastname'],
|
||||
'mail' => $user['email'],
|
||||
'password' => $user['password'],
|
||||
'status' => $user['status']
|
||||
]);
|
||||
$answer = $request->dispatch();
|
||||
|
||||
// Debug error
|
||||
if( $answer->error != Error::Success )
|
||||
var_dump( $answer->error );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//insertUsersFromJSON();
|
||||
|
||||
|
||||
|
||||
|
||||
/* NSERTION DES MACHINES DANS LA BDD DEPUIS JSON
|
||||
*
|
||||
*
|
||||
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
||||
*
|
||||
*/
|
||||
function insertMachinesFromJSON(){
|
||||
$json = file_get_contents(__ROOT__.'/config/generated_machines.json');
|
||||
$json = json_decode( $json, true );
|
||||
|
||||
// Pour chaque entree
|
||||
foreach( $json as $machine ){
|
||||
|
||||
// Creation de la requete
|
||||
$request = new ModuleRequest('machineDefault/create', [
|
||||
'name' => $machine['name']
|
||||
]);
|
||||
$answer = $request->dispatch();
|
||||
|
||||
// Debug error
|
||||
if( $answer->error != Error::Success )
|
||||
var_dump( $answer->error );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//insertMachinesFromJSON();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* AFFICHAGE DES UTILISATEURS DE LA BDD
|
||||
*
|
||||
*
|
||||
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
||||
*
|
||||
*/
|
||||
function selectUsers(){
|
||||
|
||||
// Creation de la requete
|
||||
$requete = new ModuleRequest('userDefault/getAll');
|
||||
$answer = $requete->dispatch();
|
||||
|
||||
var_dump( Error::explicit($answer->error) );
|
||||
var_dump( $answer->get('users') );
|
||||
|
||||
return true;
|
||||
|
||||
}//selectUsers();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* AFFICHAGE DES MACHINES DE LA BDD
|
||||
*
|
||||
*
|
||||
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
||||
*
|
||||
*/
|
||||
function selectMachines(){
|
||||
|
||||
// Creation de la requete
|
||||
$requete = new ModuleRequest('machineDefault/getAll');
|
||||
$answer = $requete->dispatch();
|
||||
|
||||
var_dump( Error::explicit($answer->error) );
|
||||
var_dump( $answer->get('machines') );
|
||||
|
||||
return true;
|
||||
|
||||
}//selectMachines();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* AFFICHAGE DES UTILISATEURS DE LA BDD (MIS EN PAGE)
|
||||
*
|
||||
*
|
||||
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
||||
*
|
||||
*/
|
||||
function displayUsers(){
|
||||
|
||||
// Creation de la requete
|
||||
$request = new ModuleRequest('userDefault/getAll');
|
||||
$answer = $request->dispatch();
|
||||
|
||||
// Debug error
|
||||
if( $answer->error != Error::Success )
|
||||
var_dump( Error::explicit($answer->error) );
|
||||
|
||||
// display result
|
||||
var_dump( $answer->getAll() );
|
||||
|
||||
return true;
|
||||
|
||||
}//displayUsers();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* TEST DU DISPATCHER DES MANAGERS
|
||||
*
|
||||
* @return nomRetour<typeRetour> Description du retour
|
||||
|
||||
*/
|
||||
function testModuleDispatcher(){
|
||||
|
||||
// Creation d'une requete en objet
|
||||
$req1 = new ModuleRequest('firstModule/returnvar', ['id_user' => 10, 'code' => '11-22-33-44'] );
|
||||
// Creation d'une requete a partir d'un json en <String>
|
||||
$req2 = ModuleRequest::fromString('{"path": "firstModule/returnvar", "data": {"id_user":10, "code":"11-22-33-44"}}');
|
||||
|
||||
var_dump( $req1->dispatch() );
|
||||
|
||||
return true;
|
||||
|
||||
}//testModuleDispatcher();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* TEST DU DISPATCHER DES REPO
|
||||
*
|
||||
* @return nomRetour<typeRetour> Description du retour
|
||||
|
||||
*/
|
||||
function testRepoDispatcher(){
|
||||
|
||||
// Creation d'une requete en objet
|
||||
$req1 = new Repo('user/getById', ['19']);
|
||||
// $req1 = new Repo('user/getByCode', array('92-55-B9-B3'));
|
||||
var_dump( $req1->answer() );
|
||||
|
||||
if( $req1->error != Error::Success )
|
||||
var_dump( Error::explicit($req1->error) );
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}//testRepoDispatcher();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* INSERTION (COMPOSITE) DES UTILISATEURS DE LA BDD
|
||||
*
|
||||
*
|
||||
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
||||
*
|
||||
*/
|
||||
function insertUsersComposite(){
|
||||
|
||||
// Creation de la requete
|
||||
$request = new ModuleRequest('userDefault/create', ['92-55-B9-B1', 'b', 'bla', 'bla', 'bla@test.com', 'sadas', '1'] );
|
||||
$answer = $request->dispatch();
|
||||
// Debug error
|
||||
if( $answer->error != Error::Success )
|
||||
var_dump( Error::explicit($answer->error) );
|
||||
|
||||
var_dump( $answer->getAll() );
|
||||
|
||||
return true;
|
||||
|
||||
}//insertUsersComposite();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RETOURNE LES GROUPES D'UN UTILISATEUR
|
||||
*
|
||||
*
|
||||
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
||||
*
|
||||
*/
|
||||
function getUserClusters(){
|
||||
$id_user = 115;
|
||||
|
||||
// Groupes de l'utilisateur 'a'
|
||||
$getUser1Clusters = new Repo('user/getClusters', [$id_user]);
|
||||
$user1Clusters = $getUser1Clusters->answer();
|
||||
var_dump( $user1Clusters );
|
||||
|
||||
// On ajoute un groupe a l'utilisateur 100
|
||||
$linkA = new Repo('cluster/link', array($user1Clusters[0]['id_cluster'], 100) );
|
||||
var_dump( $linkA->answer() );
|
||||
$getUser2Clusters = new Repo('user/getClusters', array(100));
|
||||
var_dump( $getUser2Clusters->answer() );
|
||||
|
||||
// On retire un groupe a l'utilisateur 100
|
||||
$unlinkA = new Repo('cluster/unlink', array($user1Clusters[0]['id_cluster'], 100) );
|
||||
var_dump( $linkA->answer() );
|
||||
$getUser2Clusters = new Repo('user/getClusters', array(100));
|
||||
var_dump( $getUser2Clusters->answer() );
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}//getUserClusters();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* MODIFICATION D'UN UTILISATEUR
|
||||
*
|
||||
*
|
||||
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
||||
*
|
||||
*/
|
||||
function editUser(){
|
||||
$id_user = 48;
|
||||
|
||||
$request = new ModuleRequest('userDefault/edit', array(
|
||||
'B1-87-EA-BF',
|
||||
'Abigail',
|
||||
'Mcmillan',
|
||||
'Savage',
|
||||
'mcmillansavage@corecom.com',
|
||||
'password',
|
||||
0
|
||||
));
|
||||
|
||||
|
||||
// ["B1-87-EA-BF","Abigail01","Mcmillan","Savage","mcmillansavage@corecom.com","password",0]
|
||||
|
||||
var_dump( $request->dispatch() );
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}//editUser();
|
||||
|
||||
|
||||
// new ResourceDispatcher('f/svg/search/st/sub-menu-side/ff0000', true);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function createWarehouse(){
|
||||
|
||||
$insert = new Repo('admin/create', [
|
||||
'FirstAdmin',
|
||||
'adminmail@gmail.com',
|
||||
'AdminPassword'
|
||||
]);
|
||||
var_dump( $insert->answer() );
|
||||
|
||||
|
||||
$getAll = new Repo('admin/getAll');
|
||||
}//createWarehouse();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
debug();
|
||||
|
||||
/* [1] FETCH
|
||||
=========================================================*/
|
||||
// $warehouse =
|
||||
// Table::get('warehouse') // Table : WAREHOUSE
|
||||
// ->whereName(['stef-montauban', Rows::COND_EQUAL]) // condition : name = 'stef-montauban'
|
||||
// ->select('name') // select : warehouse.name
|
||||
// ->unique(); // limit : 1
|
||||
//
|
||||
// $myUser =
|
||||
// Table::get('user') // Table : USER
|
||||
// ->whereId([100, Rows::COND_INF]) // condition : clé primaire(id_user) < 100
|
||||
// ->whereId([[94, 95, 96], Rows::COND_IN]) // condition : clé primaire(id_user) parmi les valeurs [94, 95, 96]
|
||||
// ->whereUsername(['%e%', Rows::COND_LIKE]) // condition : username LIKE '%e%'
|
||||
// ->select('name') // Select : user.id_user
|
||||
// ->select('id_user', Rows::SEL_COUNT)
|
||||
// ->join('id_warehouse', $warehouse) // jointure la table WAREHOUSE (automatique, soit référence, soit primaire soit même référence)
|
||||
//
|
||||
// // SELECT
|
||||
// ->fetch();
|
||||
// var_dump($myUser);
|
||||
|
||||
|
||||
// SELECT user.firstname, user.mail, user.username, user.id_user, warehouse.name
|
||||
// FROM user, (SELECT warehouse.* FROM warehouse WHERE warehouse.name = :warehouse_x_name_0 ) as warehouse
|
||||
// WHERE user.id_user < :user_x_id_user_0
|
||||
// AND user.id_user IN (:user_x_id_user_1_0, :user_x_id_user_1_1)
|
||||
// AND user.username LIKE :user_x_username_2
|
||||
// AND user.id_warehouse = warehouse.id_warehouse
|
||||
//
|
||||
// LIMIT 1;
|
||||
|
||||
/* [2] Modification
|
||||
=========================================================*/
|
||||
// $warehouse =
|
||||
// Table::get('warehouse') // Access to table 'warehouse'
|
||||
// ->whereName(['stef-montauban', Rows::COND_NOTEQ]); // condition : name = 'my-warehouse'
|
||||
//
|
||||
//
|
||||
// $myUser =
|
||||
// Table::get('user') // Access to table 'user'
|
||||
// ->whereId([100, Rows::COND_INF]) // PRIMARY KEY (other condition on same field)
|
||||
// ->whereId([[1,4,6,9], Rows::COND_IN]) // PRIMARY KEY (other condition on same field)
|
||||
// ->whereUsername(['%e%', Rows::COND_LIKE]) // Dynamic getter 'getByMySuperColumn' -> 'my_super_column'
|
||||
// ->select(['mail', 'username', 'firstname']) // Select clause
|
||||
// ->select('id_user') // Select clause (added)
|
||||
// ->join('id_warehouse', $warehouse) // joins warehouse (with name 'my-warehouse') to column 'id_warehouse'
|
||||
// // ->unique() // unique result
|
||||
//
|
||||
// // ->fetch();
|
||||
// ->edit([
|
||||
// 'id_warehouse' => Table::get('warehouse')->whereName(['stef-montauban', Rows::COND_EQUAL])->unique()->select('id_warehouse')->fetch()['id_warehouse']
|
||||
// ]);
|
||||
|
||||
// var_dump($myUser);
|
||||
|
||||
|
||||
/* [3] INSERTION
|
||||
=========================================================*/
|
||||
// $insert = Table::get('user')
|
||||
// ->insert([
|
||||
// [
|
||||
// 'id_user' => Rows::INSERT_DEFAULT,
|
||||
// 'id_warehouse' => 7,
|
||||
// 'code' => 'AA-AA-AA-AA',
|
||||
// 'username' => 'AA',
|
||||
// 'firstname' => 'AA',
|
||||
// 'lastname' => 'AA',
|
||||
// 'mail' => 'AA@AA.AA'
|
||||
// ],
|
||||
// [
|
||||
// 'id_user' => Rows::INSERT_DEFAULT,
|
||||
// 'id_warehouse' => 7,
|
||||
// 'code' => 'BB-BB-BB-BB',
|
||||
// 'username' => 'BB',
|
||||
// 'firstname' => 'BB',
|
||||
// 'lastname' => 'BB',
|
||||
// 'mail' => 'BB@BB.BB'
|
||||
// ]
|
||||
// ]);
|
||||
|
||||
|
||||
/* [4] Suppression
|
||||
=========================================================*/
|
||||
// $warehouse =
|
||||
// Table::get('warehouse') // Access to table 'warehouse'
|
||||
// ->whereName(['%stef%', Rows::COND_LIKE]) // condition : name = 'my-warehouse'
|
||||
// ->select('id_warehouse');
|
||||
//
|
||||
//
|
||||
// $myUser =
|
||||
// Table::get('user') // Access to table 'user'
|
||||
// ->whereId([[7,91], Rows::COND_IN]) // PRIMARY KEY (other condition on same field)
|
||||
// ->whereUsername(['%', Rows::COND_LIKE]) // Dynamic getter 'getByMySuperColumn' -> 'my_super_column'
|
||||
// ->select(['mail', 'username', 'firstname']) // Select clause
|
||||
// ->select('id_user') // Select clause (added)
|
||||
// ->join('id_warehouse', $warehouse) // joins warehouse (with name 'my-warehouse') to column 'id_warehouse'
|
||||
// ->unique() // unique result
|
||||
//
|
||||
// ->delete();
|
||||
|
||||
// var_dump($myUser);
|
||||
|
||||
|
||||
|
||||
// $a = new ModuleRequest('authentificationDefault/warehouse', [
|
||||
// 'name' => 'test',
|
||||
// 'password' => 'slk'
|
||||
// ]);
|
||||
//
|
||||
// $a->dispatch();
|
||||
|
||||
Table::add();
|
||||
|
||||
$state = Table::get('state')
|
||||
->select('state')
|
||||
->select('value', Rows::SEL_CONCAT);
|
||||
// ->orderby('state');
|
||||
|
||||
$pm = Table::get('pin_merge')
|
||||
->whereIdChip(1, Rows::COND_EQUAL)
|
||||
->select('id_chip')
|
||||
->orderby('id_chip')
|
||||
// ->orderby('pin')
|
||||
->join('id_pin_merge', $state);
|
||||
|
||||
$resultA = $pm->fetch();
|
||||
var_dump($resultA);
|
||||
?>
|
|
@ -1,35 +0,0 @@
|
|||
{
|
||||
"name": "xdrm_api",
|
||||
"version": "0.1",
|
||||
"description": "API du serveur de centralisation des accès.",
|
||||
|
||||
"requests": {
|
||||
|
||||
"sync": {
|
||||
"url": "stefproject/api/machineDefault/sync",
|
||||
"method": "POST",
|
||||
"headers": { "Authorization": "Digest @warehouse" },
|
||||
"postdata": {
|
||||
"token": "@token",
|
||||
"data": "@data"
|
||||
},
|
||||
"description": "Synchronisation des données de la machine avec le serveur."
|
||||
},
|
||||
|
||||
"sync-renew": {
|
||||
"url": "stefproject/api/machineDefault/sync",
|
||||
"method": "POST",
|
||||
"headers": { "Authorization": "Digest @warehouse" },
|
||||
"postdata": {
|
||||
"token": "@token",
|
||||
"data": "@data",
|
||||
"renew": "@renew"
|
||||
},
|
||||
"description": "Synchronisation des données de la machine avec le serveur. Remise à 0 du token"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
<?php namespace test\client;
|
||||
|
||||
use \error\core\Error;
|
||||
|
||||
/* CLASSE PERMETANT L'UTILISATION DU manifest.json POUR UTILISER DES APIS DIVERSES
|
||||
*
|
||||
* @return nomRetour<typeRetour> Description du retour
|
||||
*
|
||||
*/
|
||||
class api{
|
||||
|
||||
// Fichier de configuration par defaut
|
||||
private $config_path = 'api.manifest.json';
|
||||
public $error;
|
||||
|
||||
// liste des methodes
|
||||
public static $METHODS = array(
|
||||
'POST' => array( CURLOPT_POST, true ),
|
||||
'GET' => array( CURLOPT_HTTPGET, true ),
|
||||
'PUT' => array( CURLOPT_CUSTOMREQUEST, 'PUT' ),
|
||||
'DELETE' => array( CURLOPT_CUSTOMREQUEST, 'DELETE' )
|
||||
);
|
||||
|
||||
/*************/
|
||||
/* ATTRIBUTS */
|
||||
/*************/
|
||||
private $manifest = null; // Contiendra le tableau correspondant au JSON
|
||||
private $requests = array(); // Contiendra la liste des requetes de l'api et leurs parametres
|
||||
|
||||
private $name;
|
||||
private $description;
|
||||
private $version;
|
||||
|
||||
|
||||
/* CONSTRUCTEUR DU CLIENT DE L'API
|
||||
*
|
||||
* @config<String> Chemin du fichier de configuration de l'api
|
||||
*
|
||||
*/
|
||||
public function __construct($config=null){
|
||||
/* [0] Gestion du fichier de config si donne en param
|
||||
=========================================================*/
|
||||
if( $config !== null ) $this->config_path = $config;
|
||||
|
||||
/* [1] On recupere le contenu du fichier de config
|
||||
=========================================================*/
|
||||
$manifest = json_decode( file_get_contents($this->config_path), true );
|
||||
|
||||
// Si erreur de parsage ou de fichier, on retourne une erreur
|
||||
if( $manifest === null ){
|
||||
$this->error = Error::ParsingFailed;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* [2] On repartie et classe les donnees
|
||||
=========================================================*/
|
||||
/* (1) Informations generales */
|
||||
$name = $manifest['name'];
|
||||
$description = $manifest['description'];
|
||||
$version = $manifest['version'];
|
||||
|
||||
/* (2) Liste des requetes */
|
||||
$this->requests = $manifest['requests'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ENVOI ET CONSTRUCTION D'UNE REQUETE
|
||||
*
|
||||
* @request_name<String> Nom de la requete en question
|
||||
* @parameters<Array> Liste des parametres de la requete
|
||||
*
|
||||
* @return response<Array> Reponse HTTP au format norme ou FAUX si une erreur occure
|
||||
*
|
||||
*/
|
||||
public function send($request_name, $parameters=array()){
|
||||
/* [1] On construit la requete avec les parametres
|
||||
=========================================================*/
|
||||
$build = $this->build($request_name, $parameters);
|
||||
|
||||
// Si la construction a echoue, on retourne une erreur
|
||||
if( $build === false ) return false;
|
||||
|
||||
|
||||
/* [2] Header et pre-data de la requete
|
||||
=========================================================*/
|
||||
/* (1) On definit l'URL */
|
||||
$curl = curl_init($build['url']);
|
||||
|
||||
// permet de recupere le resultat au lieu de l'afficher
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
|
||||
/* (2) On definit la methode */
|
||||
$method_arguments = self::$METHODS[ $build['method'] ];
|
||||
|
||||
curl_setopt($curl, $method_arguments[0], $method_arguments[1]);
|
||||
|
||||
|
||||
/* (3) On definit les headers */
|
||||
$headers = array();
|
||||
|
||||
// On construit le header au bon format : 'name: value'
|
||||
foreach($build['headers'] as $name=>$value)
|
||||
array_push($headers, $name.': '.$value);
|
||||
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
|
||||
/* (4) On definit les donnees POST si on est pas en get */
|
||||
if( $build['method'] != 'GET' ){
|
||||
$postdata = '';
|
||||
|
||||
// On formatte les donnees au format 'key=value&key=value'
|
||||
foreach($build['postdata'] as $key=>$value)
|
||||
$postdata .= $key.'='.$value.'&';
|
||||
rtrim($postdata); // on supprime le '&' a la fin s'il y a
|
||||
|
||||
// On envoie les donnees
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
|
||||
}
|
||||
|
||||
|
||||
/* [4] Execution de la requete et recup de la response
|
||||
=========================================================*/
|
||||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
|
||||
/* [5] On retourne la reponse
|
||||
=========================================================*/
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* CONSTRUCTION D'UNE REQUETE
|
||||
*
|
||||
* @request_name<String> Nom de la requete
|
||||
* @parameters<Array> Liste des parametres de la requete
|
||||
*
|
||||
* @return filledRequest<Array> Renvoie la requete avec les bons parametres
|
||||
*
|
||||
*/
|
||||
private function build($request_name, $parameters=array()){
|
||||
/* [0] Gestion des INPUTS
|
||||
=========================================================*/
|
||||
// On retourne une erreur si la requete n'existe pas
|
||||
if( !isset($this->requests[$request_name]) ) return false;
|
||||
|
||||
// On enregistre une copie de la requete
|
||||
$request = $this->requests[$request_name];
|
||||
|
||||
|
||||
/* [1] Gestion de la methode
|
||||
=========================================================*/
|
||||
// Si la methode n'est pas prise en compte, on retourne une erreur
|
||||
if( !isset( self::$METHODS[$request['method']] ) ) return false;
|
||||
|
||||
|
||||
|
||||
|
||||
/* [2] Remplacement des parametres (valeurs globales)
|
||||
=========================================================*/
|
||||
/* (1) Remplacement dans l'URL */
|
||||
$request['url'] = $this->fillParameters($request['url'], $parameters);
|
||||
|
||||
/* (2) Remplacement dans les headers */
|
||||
foreach($request['headers'] as $name=>$value)
|
||||
$request['headers'][$name] = $this->fillParameters($value, $parameters);
|
||||
|
||||
/* (2) Remplacement dans les postdata */
|
||||
foreach($request['postdata'] as $name=>$value)
|
||||
$request['postdata'][$name] = $this->fillParameters($value, $parameters);
|
||||
|
||||
|
||||
/* [3] Retour de la requete construite
|
||||
=========================================================*/
|
||||
return $request;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* REMPLACE LES PARAMETRES DANS UNE CHAINE
|
||||
*
|
||||
* @before<String> Chaine a etudier et dans laquelle remplacer les parametres
|
||||
* @parameters<Array> Liste des parametres a remplacer (prefixes d'un '@')
|
||||
*
|
||||
* @return after<String> Chaine contenant les parametres de la liste @parameters
|
||||
*
|
||||
*/
|
||||
private function fillParameters($before, $parameters){
|
||||
// On initialise la valeur de retour
|
||||
$after = $before;
|
||||
|
||||
/* [1] On remplace les parametres prefixes par '@'
|
||||
=========================================================*/
|
||||
foreach($parameters as $name=>$value){
|
||||
$position = strpos($after, $name);
|
||||
|
||||
// Si on a trouve, on remplace le nom de variable par la valeur
|
||||
if( $position !== false )
|
||||
$after = substr($after, 0, $position) . $value . substr($after, $position+strlen($name) );
|
||||
|
||||
}
|
||||
|
||||
/* [2] On retourne la nouvelle chaine
|
||||
=========================================================*/
|
||||
return $after;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -1,94 +0,0 @@
|
|||
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
|
||||
use \api\core\ModuleRequest;
|
||||
use \manager\sessionManager;
|
||||
|
||||
use \test\client\api;
|
||||
|
||||
debug();
|
||||
|
||||
|
||||
|
||||
/* [1] Gestion de l'enregistrement
|
||||
=========================================================*/
|
||||
if( isset($_POST['code']) && isset($_POST['action']) ){
|
||||
|
||||
array_push($_SESSION['history'],[
|
||||
'code' => json_decode( $_POST['code'], true ),
|
||||
'action' => json_decode( $_POST['action'], true )
|
||||
]);
|
||||
|
||||
$data = '';
|
||||
|
||||
foreach($_SESSION['history'] as $h=>$entry)
|
||||
$data .= "<span>".$entry['code']." - ".$entry['action']."</span><br>";
|
||||
|
||||
|
||||
echo json_encode( [
|
||||
'ModuleError' => 0,
|
||||
'data' => $data
|
||||
] );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* [2] Gestion de la synchronisation
|
||||
=========================================================*/
|
||||
if( isset($_POST['sync']) ){
|
||||
|
||||
$api = new api();
|
||||
|
||||
/* (1) On effectue la synchro */
|
||||
$token = sessionManager::secure_hash( $_COOKIE['mac_password'], $_COOKIE['mac_count'] );
|
||||
|
||||
|
||||
// Renouvellement du TOKEN
|
||||
if( $_COOKIE['mac_count'] == 1 ){
|
||||
|
||||
|
||||
$response = $api->send('sync-renew', [
|
||||
'@warehouse' => '643405e1004845c2291c244faab192e3ad493b9dec147c8030475794b0f2fa23',
|
||||
'@token' => $token,
|
||||
'@data' => json_encode( $_SESSION['history'] ),
|
||||
'@renew' => sessionManager::secure_hash( $_COOKIE['mac_password'], 10)
|
||||
]);
|
||||
$parsedResponse = json_decode( $response, true );
|
||||
|
||||
|
||||
// On change les données locales uniquement si on a une réponse positive
|
||||
if( $parsedResponse['ModuleError'] == 0 ){
|
||||
$_COOKIE['mac_count'] = 9;
|
||||
setcookie('mac_count', $_COOKIE['mac_count'], time()+3600*24*365, '/');
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
$response = $api->send('sync', [
|
||||
'@warehouse' => '643405e1004845c2291c244faab192e3ad493b9dec147c8030475794b0f2fa23',
|
||||
'@token' => $token,
|
||||
'@data' => json_encode( $_SESSION['history'] )
|
||||
]);
|
||||
$parsedResponse = json_decode( $response, true );
|
||||
|
||||
|
||||
// On change les données locales uniquement si on a une réponse positive
|
||||
if( $parsedResponse['ModuleError'] == 0 ){
|
||||
$_COOKIE['mac_count']--;
|
||||
setcookie('mac_count', $_COOKIE['mac_count'], time()+3600*24*365, '/');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$toReturn = [
|
||||
'response' => $parsedResponse,
|
||||
'count' => $_COOKIE['mac_count'],
|
||||
'token' => $token,
|
||||
'status' => $parsedResponse['ModuleError'],
|
||||
'data' => ($parsedResponse['ModuleError']==0) ? $parsedResponse['data'] : 'void'
|
||||
];
|
||||
|
||||
echo json_encode($toReturn);
|
||||
}
|
||||
?>
|
|
@ -1,434 +0,0 @@
|
|||
<?php define('__ROOT__', dirname(dirname(dirname(__DIR__))) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
|
||||
$_SESSION['history'] = [];
|
||||
|
||||
if( !isset($_COOKIE['mac_password']) || !isset($_COOKIE['mac_count']) || !isset($_COOKIE['token']) ){
|
||||
$_COOKIE['mac_count'] = 10;
|
||||
$_COOKIE['mac_password'] = 'macPassword';
|
||||
|
||||
// hash password
|
||||
$_COOKIE['token'] = $_COOKIE['mac_password'];
|
||||
for( $i = 0 ; $i < $_COOKIE['mac_count'] ; $i++ )
|
||||
$_COOKIE['token'] = hash('512', $_COOKIE['token']);
|
||||
|
||||
setcookie('mac_count', $_COOKIE['mac_count'], time()+3600*24*365, '/');
|
||||
setcookie('mac_password', $_COOKIE['mac_password'], time()+3600*24*365, '/');
|
||||
setcookie('token', $_COOKIE['token'], time()+3600*24*365, '/');
|
||||
|
||||
header('Refresh: 0');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Virtual Client</title>
|
||||
|
||||
|
||||
<script type='text/javascript' src='/js/lib/reset.js' ></script> <!-- Corrections Javascript natif (ajouts) -->
|
||||
<script type='text/javascript' src='/js/lib/api.js' ></script> <!-- Gestion des transactions avec le serveur -->
|
||||
<script type='text/javascript' src='/js/lib/page-manager.js' ></script> <!-- Gestion réseau/chargement/liens/URL -->
|
||||
<script type='text/javascript' src='/js/lib/form-deflater.js' ></script> <!-- Gestion des formulaires (Object) -->
|
||||
<script type='text/javascript' src='/js/lib/local-storage-interface.js' ></script> <!-- Interface pour le 'localStorage' -->
|
||||
<script type='text/javascript' src='/test/client/lib.js' ></script> <!-- Dépendance Directe -->
|
||||
<style type='text/css'>
|
||||
body{
|
||||
background: #1c384b;
|
||||
font-size: 16px;
|
||||
font-family: 'Roboto';
|
||||
}
|
||||
|
||||
#machine-box{
|
||||
position: absolute;
|
||||
top: 40%;
|
||||
left: 60%;
|
||||
width: 20em;
|
||||
height: 35em;
|
||||
|
||||
border-radius: 10px;
|
||||
border: 2px solid #1a1a1a;
|
||||
box-shadow: 0 0 2em #172e3d;
|
||||
|
||||
background: #222;
|
||||
|
||||
transform: translateX(-50%) translateY(-50%);
|
||||
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#machine-box > #led{
|
||||
position: absolute;
|
||||
top: calc( 20% - 1.5em/2 - 2px/2 );
|
||||
left: calc( 75% - 1.5em/2 - 2px/2 );
|
||||
width: 1.5em;
|
||||
height: 1.5em;
|
||||
|
||||
border-radius: 50% / 50%;
|
||||
border: 2px solid #111;
|
||||
|
||||
background: #000;
|
||||
}
|
||||
|
||||
#machine-box > #r1,
|
||||
#machine-box > #r2{
|
||||
position: absolute;
|
||||
top: calc( 25% - 3em/2 );
|
||||
left: 100%;
|
||||
width: 4em;
|
||||
height: 3em;
|
||||
|
||||
background: #000;
|
||||
|
||||
color: #ccc;
|
||||
text-align: center;
|
||||
line-height: 3em;
|
||||
}
|
||||
#machine-box > #r2{
|
||||
top: calc( 50% - 3em/2 );
|
||||
}
|
||||
|
||||
|
||||
#machine-box > #r1.active,
|
||||
#machine-box > #r2.active{
|
||||
font-weight: bold;
|
||||
color: #18eea9;
|
||||
}
|
||||
|
||||
#card-stack{
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 20%;
|
||||
width: 20em;
|
||||
height: 35em;
|
||||
|
||||
transform: translateX(-50%) translateY(-50%);
|
||||
}
|
||||
|
||||
#card-stack > .card{
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 4em;
|
||||
margin-bottom: .2em;
|
||||
|
||||
border-radius: 10px 10px 0 0;
|
||||
box-shadow: 0 2px 10px #111;
|
||||
|
||||
background: #eee;
|
||||
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
line-height: 4em;
|
||||
text-align: center;
|
||||
|
||||
transition: all .2s ease-in-out;
|
||||
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#card-stack > .card:hover{
|
||||
background: #fff;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#card-stack > .card.active{
|
||||
background: #aaa;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#card-stack > input{
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: calc( 100% - 1em*2 );
|
||||
height: calc( 3em - 1em*2 );
|
||||
padding: 1em;
|
||||
margin-bottom: 2em;
|
||||
|
||||
border-radius: 3px;
|
||||
border: 0;
|
||||
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
#sync-button,
|
||||
#card-pass{
|
||||
position: absolute;
|
||||
top: calc( 50% + 29em );
|
||||
left: 60%;
|
||||
padding: 1.5em;
|
||||
|
||||
border-radius: 3px;
|
||||
border: 2px solid #fff;
|
||||
|
||||
background: #1ee18e;
|
||||
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
letter-spacing: .15em;
|
||||
text-transform: uppercase;
|
||||
|
||||
transition: all .2s ease-in-out;
|
||||
|
||||
transform: translateX(-50%) translateY(-50%);
|
||||
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#card-pass{
|
||||
top: calc( 40% + 29em );
|
||||
background: #3595ce;
|
||||
}
|
||||
|
||||
#sync-button:hover{
|
||||
background: #1ac47c;
|
||||
}
|
||||
|
||||
#card-pass:hover{
|
||||
background: #2d7dad;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
<div id='machine-box'>
|
||||
<div id='led'></div>
|
||||
<div id='r1'>r1</div>
|
||||
<div id='r2'>r2</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id='card-stack'>
|
||||
<input id='add-card' placeholder='Code RFID' type='text'>
|
||||
<div class='card'>AB-CD-EF-GH</div>
|
||||
<div class='card'>10-FE-BD-61</div>
|
||||
<div class='card'>92-55-B9-B3</div>
|
||||
</div>
|
||||
|
||||
|
||||
<input type='button' id='card-pass' value='Passer la carte'>
|
||||
<input type='button' id='sync-button' value='Synchronisation'>
|
||||
|
||||
|
||||
|
||||
|
||||
<script type='text/javascript'>
|
||||
/* [0] Initialisation et éléments
|
||||
=========================================================*/
|
||||
/* (1) Etats du système */
|
||||
var STATE = [ 0, 0, 0 ];
|
||||
|
||||
/* (2) Elements du DOM */
|
||||
var mBox = document.getElementById('machine-box');
|
||||
var led = document.getElementById('led');
|
||||
var r1 = document.getElementById('r1');
|
||||
var r2 = document.getElementById('r2');
|
||||
var cBox = document.getElementById('card-stack');
|
||||
var cAdd = document.getElementById('add-card');
|
||||
var sync = document.getElementById('sync-button');
|
||||
var pass = document.getElementById('card-pass');
|
||||
|
||||
/* (3) Variables de suivi */
|
||||
var CARD = null;
|
||||
var lastCard = null;
|
||||
var lsi = new localStorageInterface();
|
||||
lsi.createDataset('STATES.CNF' );
|
||||
lsi.createDataset('ACTIONS.CNF');
|
||||
lsi.createDataset('CHIPS.CNF');
|
||||
lsi.createDataset('PERMISSIONS.CNF');
|
||||
lsi.createDataset('SERVER.CNF' );
|
||||
lsi.createDataset('HISTORY.LOG');
|
||||
lsi.createDataset('STATES.LOG' );
|
||||
|
||||
/* (4) Récupération des données de fonctionnement */
|
||||
var api = new APIClass('/api/');
|
||||
|
||||
var ACTIONS, STATES, CHIPS, PERMISSIONS;
|
||||
|
||||
var request = {
|
||||
path: 'machineDefault/init',
|
||||
id_machine: 126,
|
||||
token:
|
||||
};
|
||||
|
||||
api.send({path: 'machineDefault/init', id_machine: 126}, function(response){
|
||||
lsi.import('ACTIONS.CNF', response.actions);
|
||||
lsi.import('STATES.CNF', response.states);
|
||||
lsi.import('CHIPS.CNF', response.chips);
|
||||
lsi.import('PERMISSIONS.CNF', response.permissions);
|
||||
|
||||
ACTIONS = lsi.export('ACTIONS.CNF');
|
||||
STATES = lsi.export('STATES.CNF');
|
||||
CHIPS = lsi.export('CHIPS.CNF');
|
||||
PERMISSIONS = lsi.export('PERMISSIONS.CNF');
|
||||
}, '643405e1004845c2291c244faab192e3ad493b9dec147c8030475794b0f2fa23');
|
||||
|
||||
/* (5) On initialise la carte + les puces */
|
||||
var board = new Board(50);
|
||||
|
||||
var CHIP = {
|
||||
led: new LedInterface( new Chip('serial', [1, 2, 3]), led ),
|
||||
r1: new RelayInterface( new Chip('serial', [4]), r1 ),
|
||||
r2: new RelayInterface( new Chip('serial', [5]), r2 )
|
||||
};
|
||||
|
||||
var chipList = Object.keys(CHIP);
|
||||
|
||||
// Branchement des puces
|
||||
for( var i = 0 ; i < chipList.length ; i++ )
|
||||
board.plug( CHIP[chipList[i]] );
|
||||
|
||||
|
||||
/* [1] Fonctions
|
||||
=========================================================*/
|
||||
/* (1) Gestion de mise à jour de la led en fonction de l'état
|
||||
---------------------------------------------------------*/
|
||||
function updateChips(){
|
||||
var STATES = lsi.export('STATES.CNF');
|
||||
var CHIPS = lsi.export('CHIPS.CNF');
|
||||
|
||||
/* (1) On vérifie quel état correspond */
|
||||
for( var s in STATES ){
|
||||
|
||||
/* (2) Si l'état correspond */
|
||||
if( previous(STATES[s].global_state, STATE) ){
|
||||
|
||||
console.log('STATE', STATE.join(''), 'matches', STATES[s].global_state);
|
||||
|
||||
/* (3) On applique l'état à chaque CHIP */
|
||||
for( var c in CHIPS ){
|
||||
|
||||
/* (4) Si la puce a bien cet été de défini */
|
||||
if( !CHIPS[c].states.hasOwnProperty(STATES[s].chips[c]) )
|
||||
break;
|
||||
|
||||
/* (5) On récupère les PIN + les VALUES */
|
||||
var pins = CHIPS[c].pins;
|
||||
var values = CHIPS[c].states[STATES[s].chips[c]];
|
||||
|
||||
/* (6) On applique les valeurs */
|
||||
for( var p in pins )
|
||||
board.set( parseInt(pins[p]), parseInt(values[p]) );
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* [2] Gestion de l'ajout de carte
|
||||
=========================================================*/
|
||||
cAdd.addEventListener('keyup', function(e){
|
||||
if( e.keyCode == 13 ) cBox.innerHTML += "<div class='card'>"+e.target.value+"</div>";
|
||||
}, false);
|
||||
|
||||
|
||||
/* [3] Gestion de la sélection de carte
|
||||
=========================================================*/
|
||||
cBox.addEventListener('click', function(e){
|
||||
if( e.target.className == 'card' ){
|
||||
CARD = e.target.innerHTML;
|
||||
|
||||
var allCards = document.querySelectorAll('#card-stack .card');
|
||||
for( var i = 0 ; i < allCards.length ; i++ )
|
||||
allCards[i].remClass('active');
|
||||
|
||||
e.target.addClass('active');
|
||||
}
|
||||
}, false);
|
||||
CARD = document.querySelector('#card-stack .card').innerHTML;
|
||||
document.querySelector('#card-stack .card').addClass('active');
|
||||
|
||||
|
||||
/* [4] Passage de carte
|
||||
=========================================================*/
|
||||
var INTERVAL = null;
|
||||
var COUNT = 0;
|
||||
|
||||
|
||||
/* (0) Routine de comptage de temps
|
||||
---------------------------------------------------------*/
|
||||
function countRoutine(){
|
||||
/* (1) Si le TIMEOUT actuel n'est pas défini, on quitte */
|
||||
var exists = false;
|
||||
for( var t in Object.keys(ACTIONS) )
|
||||
if( t == COUNT ) exists = true;
|
||||
|
||||
// Si aucune action pour ce timeout, on quitte
|
||||
if( !exists ) return;
|
||||
|
||||
/* (2) Pour chaque action de ce timeout */
|
||||
for( var a in Object.keys(ACTIONS[COUNT]) ){
|
||||
|
||||
/* (3) On vérifie que l'utilisateur a la permissions d'effectuer l'action */
|
||||
var hasPermission = PERMISSIONS.hasOwnProperty(CARD) && PERMISSIONS[CARD].actions.indexOf( ACTIONS[COUNT][a].id_action.toString() ) > -1;
|
||||
|
||||
// Si on a pas la permission, on quitte
|
||||
if( !hasPermission ) continue;
|
||||
|
||||
|
||||
|
||||
|
||||
/* (4) Si la condition est correcte, On applique la modification de l'état */
|
||||
if( previous(ACTIONS[COUNT][a].previous, STATE) ){
|
||||
action(ACTIONS[COUNT][a].action, STATE);
|
||||
|
||||
/* (5) On enregistre l'action dans l'historique */
|
||||
var historyKeys = lsi.keys('HISTORY.LOG').length;
|
||||
|
||||
lsi.set('HISTORY.LOG', historyKeys+1, {
|
||||
id_user: parseInt(PERMISSIONS[CARD].id_user),
|
||||
id_machine: 1,
|
||||
id_action: parseInt(ACTIONS[COUNT][a].id_action)
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
updateChips();
|
||||
COUNT++;
|
||||
}
|
||||
|
||||
/* (1) Appui carte
|
||||
---------------------------------------------------------*/
|
||||
pass.addEventListener('mousedown', function(e){
|
||||
COUNT = 0;
|
||||
|
||||
countRoutine();
|
||||
INTERVAL = setInterval( countRoutine, 1000 );
|
||||
|
||||
}, false);
|
||||
|
||||
/* (2) Levé carte
|
||||
---------------------------------------------------------*/
|
||||
window.addEventListener('mouseup', function(e){
|
||||
clearInterval(INTERVAL);
|
||||
}, false);
|
||||
|
||||
|
||||
/* [5] Synchronisation
|
||||
=========================================================*/
|
||||
sync.addEventListener('click', function(e){
|
||||
|
||||
}, false);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,8 +0,0 @@
|
|||
var Pin;(function(){Pin=function(a){parseInt(a)==a&&0<=a&&255>=a?this.value=parseInt(a):this.value=0};Pin.prototype={value:this.value};Pin.prototype.set=function(a){parseInt(a)==a&&0<=a&&255>=a&&(this.value=parseInt(a))};Pin.prototype.get=function(){return this.value}})();var Board;
|
||||
(function(){Board=function(a){if(!(parseInt(a)!=a||1>a)){this.maxPin=a;this.pins=[];this.listener=[];for(a=0;a<this.maxPin;a++)this.pins[a]=!1;this.listener[a]=null}};Board.prototype={maxPin:this.maxPin,pins:this.pins,listener:this.listener};Board.prototype.plug=function(a){if(!(a.chip instanceof Chip))return!1;for(var b=0;b<a.chip.pins.length;b++)if(this.pins[a.chip.pins[b]]instanceof Pin)return!1;for(b=0;b<a.chip.pins.length;b++)this.pins[a.chip.pins[b]]=a.chip.values[b],this.listener[a.chip.pins[b]]=
|
||||
a};Board.prototype.set=function(a,b){if(!(parseInt(a)!=a||a>this.maxPin)&&this.pins[a]instanceof Pin){if("boolean"==typeof b)b=b?255:0;else if(b!=parseInt(b)||0>b||255<b)return;b=parseInt(b);this.pins[a].set(b);"function"===typeof this.listener[a].update&&this.listener[a].update()}}})();var Chip;
|
||||
(function(){Chip=function(a,b){if("string"==typeof a&&(a=a.toLowerCase(),-1!=["spi","i2c","serial"].indexOf(a)&&b instanceof Array)){for(var c=0;c<b.length;c++)if(parseInt(b[c])!=b[c])return;this.type=a;this.pins=b;this.values=[];for(c=0;c<this.pins.length;c++)this.values[c]=new Pin(0)}};Chip.prototype={type:this.type,pins:this.pins,values:this.values};Chip.prototype.setPin=function(a,b){if(!(parseInt(a)!=a||this.pins.length>=a)){if("boolean"==typeof b)b=b?255:0;else if(b!=parseInt(b)||0>b||255<b)return;
|
||||
b=parseInt(b);this.values[a].set(b)}};Chip.prototype.setPins=function(a){for(var b=0;b<this.pins.length;b++)this.setPin(b,a[b])};Chip.prototype.getPin=function(a){return parseInt(a)!=a||this.pins.length<=a?!1:this.values[a].get()};Chip.prototype.getPins=function(){for(var a=[],b=0;b<this.pins.length;b++)a[b]=this.getPin(b);return a}})();var LedInterface;
|
||||
(function(){LedInterface=function(a,b){a instanceof Chip&&b instanceof Element&&(this.chip=a,this.container=b)};LedInterface.prototype={chip:this.chip,container:this.container};LedInterface.prototype.update=function(){this.container.style.backgroundColor="rgb("+this.chip.getPin(0)+","+this.chip.getPin(1)+","+this.chip.getPin(2)+")"}})();var RelayInterface;
|
||||
(function(){RelayInterface=function(a,b){a instanceof Chip&&b instanceof Element&&(this.chip=a,this.container=b)};RelayInterface.prototype={chip:this.chip,container:this.container};RelayInterface.prototype.update=function(){1<this.chip.getPin(0)?this.container.addClass("active"):this.container.remClass("active")}})();var previous,action;
|
||||
(function(){previous=function(a,b){console.warn(a);a=a.toLowerCase();for(var c=0;c<a.length;c++)if("x"!=a[c]&&a[c]!=b[c])return!1;return!0};action=function(a,b){a=a.toLowerCase();for(var c=0;c<a.length;c++)"x"!=a[c]&&(b[c]=parseInt(a[c]))}})();
|
|
@ -1,392 +0,0 @@
|
|||
var Pin;
|
||||
|
||||
(function(){
|
||||
|
||||
// Constructeur de Pin
|
||||
Pin = function(value){
|
||||
if( parseInt(value) == value && value >= 0 && value <= 255 )
|
||||
this.value = parseInt(value);
|
||||
else
|
||||
this.value = 0;
|
||||
};
|
||||
|
||||
Pin.prototype = { value: this.value };
|
||||
|
||||
Pin.prototype.set = function(value){
|
||||
if( parseInt(value) == value && value >= 0 && value <= 255 )
|
||||
this.value = parseInt(value);
|
||||
};
|
||||
|
||||
Pin.prototype.get = function(){
|
||||
return this.value;
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var Board;
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
/* CONSTRUCTEUR DE CARTE
|
||||
*
|
||||
* @maxPin<int> Nombre de pin de la board
|
||||
*
|
||||
*/
|
||||
Board = function(maxPin){
|
||||
if( parseInt(maxPin) != maxPin || maxPin < 1 )
|
||||
return;
|
||||
|
||||
this.maxPin = maxPin;
|
||||
this.pins = [];
|
||||
this.listener = [];
|
||||
|
||||
for( var i = 0 ; i < this.maxPin ; i++ )
|
||||
this.pins[i] = false;
|
||||
this.listener[i] = null;
|
||||
};
|
||||
|
||||
Board.prototype = {
|
||||
maxPin: this.maxPin, // Nombre de Pins de la Board
|
||||
pins: this.pins, // Liste des valeurs des pins (FALSE->libre, Pin()->prise)
|
||||
listener: this.listener // Contient la classe d'amorcage pour chaque pin
|
||||
};
|
||||
|
||||
|
||||
/* BRANCHE UNE PUCE SUR LA Board
|
||||
*
|
||||
* @chipInterface<Object> Interface contenant la carte et la mise à jour
|
||||
*
|
||||
*/
|
||||
Board.prototype.plug = function(chipInterface){
|
||||
/* [0] Vérification des paramètres
|
||||
=========================================================*/
|
||||
if( !(chipInterface.chip instanceof Chip) )
|
||||
return false;
|
||||
|
||||
/* [1] Vérification des Pins
|
||||
=========================================================*/
|
||||
for( var i = 0 ; i < chipInterface.chip.pins.length ; i++ )
|
||||
if( this.pins[chipInterface.chip.pins[i]] instanceof Pin ) // si pin déja prise
|
||||
return false;
|
||||
|
||||
/* [2] Branchement + on lie l'interface
|
||||
=========================================================*/
|
||||
for( i = 0 ; i < chipInterface.chip.pins.length ; i++ ){
|
||||
this.pins[chipInterface.chip.pins[i]] = chipInterface.chip.values[i];
|
||||
this.listener[chipInterface.chip.pins[i]] = chipInterface;
|
||||
}
|
||||
};
|
||||
|
||||
/* MODIFICATION D'UNE VALEUR DE PIN
|
||||
*
|
||||
* @pinOrder<int> Indice de la pin
|
||||
* @value<int> Valeur à attribuer
|
||||
*
|
||||
* @return nomRetour<typeRetour> Description du retour
|
||||
*
|
||||
*/
|
||||
Board.prototype.set = function(pinOrder, value){
|
||||
/* [0] Vérification des paramètres
|
||||
=========================================================*/
|
||||
/* (1) On vérifie que @pinOrder est un entier et qu'il est branché */
|
||||
if( parseInt(pinOrder) != pinOrder || pinOrder > this.maxPin ) return;
|
||||
|
||||
/* (2) On vérifie que la pin de @pinOrder est branchée */
|
||||
if( !(this.pins[pinOrder] instanceof Pin) ) return;
|
||||
|
||||
/* (3) On vérifie que @value est un booléen, si oui : true=>255, false=>0 */
|
||||
if( typeof value == 'boolean' )
|
||||
value = value ? 255 : 0;
|
||||
|
||||
/* (4) On vérifie que @value est dans 0-255 */
|
||||
else if( value != parseInt(value) || value < 0 || value > 255 ) return;
|
||||
|
||||
// On met @value en entier
|
||||
value = parseInt(value);
|
||||
|
||||
|
||||
/* [1] On attribue la valeur
|
||||
=========================================================*/
|
||||
this.pins[pinOrder].set(value);
|
||||
|
||||
/* [2] On lance le listener
|
||||
=========================================================*/
|
||||
if( typeof this.listener[pinOrder].update === 'function' )
|
||||
this.listener[pinOrder].update();
|
||||
};
|
||||
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var Chip;
|
||||
|
||||
(function(){
|
||||
|
||||
/* CLASSE 'Chip' Correspond à un périphérique processeur
|
||||
*
|
||||
* @chip<String> Type de communication
|
||||
* @pins<Array> Numéros des pins de la carte
|
||||
*
|
||||
* @return Chip<Chip> Retourne une instance de 'Chip'
|
||||
*
|
||||
*/
|
||||
Chip = function(type, pins){
|
||||
/* [0] Vérification des paramètres
|
||||
=========================================================*/
|
||||
/* (1) @type de carte */
|
||||
if( typeof type != 'string' ) return;
|
||||
|
||||
type = type.toLowerCase();
|
||||
if( ['spi', 'i2c', 'serial'].indexOf(type) == -1 ) return;
|
||||
|
||||
/* (2) @pins un tableau d'entiers */
|
||||
if( !(pins instanceof Array) ) return;
|
||||
|
||||
for( var i = 0 ; i < pins.length ; i++ )
|
||||
if( parseInt(pins[i]) != pins[i] ) return;
|
||||
|
||||
|
||||
|
||||
/* [1] On récupère les valeurs
|
||||
=========================================================*/
|
||||
/* (1) On enregistre le type */
|
||||
this.type = type;
|
||||
|
||||
/* (2) On enregistre la liste des pins et leurs valeurs */
|
||||
this.pins = pins;
|
||||
this.values = [];
|
||||
|
||||
for( i = 0 ; i < this.pins.length ; i++ )
|
||||
this.values[i] = new Pin(0);
|
||||
};
|
||||
|
||||
Chip.prototype = {
|
||||
type: this.type, // Type de communication ('spi', 'i2c', ou 'serial')
|
||||
pins: this.pins, // Liste des numéros des Pin's (ordonnée)
|
||||
values: this.values // Liste des valeurs des pins (ordonnée) (objets Pin() )
|
||||
};
|
||||
|
||||
/* ATTRIBUE UNE VALEUR A UNE PIN DONNEE
|
||||
*
|
||||
* @pinOrder<int> Indice de la pin (0, 1, 2, ...)
|
||||
* @value<int/Boolean> Valeur dans 0-255 (ou booléen) à attribuer
|
||||
*
|
||||
*/
|
||||
Chip.prototype.setPin = function(pinOrder, value){
|
||||
/* [0] Vérification des paramètres
|
||||
=========================================================*/
|
||||
/* (1) On vérifie que @pinOrder est un entier et qu'il est un indice de @this.pins */
|
||||
if( parseInt(pinOrder) != pinOrder || this.pins.length >= pinOrder ) return;
|
||||
|
||||
/* (2) On vérifie que @value est un booléen, si oui : true=>255, false=>0 */
|
||||
if( typeof value == 'boolean' )
|
||||
value = value ? 255 : 0;
|
||||
|
||||
/* (3) On vérifie que @value est dans 0-255 */
|
||||
else if( value != parseInt(value) || value < 0 || value > 255 ) return;
|
||||
|
||||
// On met @value en entier
|
||||
value = parseInt(value);
|
||||
|
||||
|
||||
/* [1] On attribue la valeur
|
||||
=========================================================*/
|
||||
this.values[pinOrder].set(value);
|
||||
};
|
||||
|
||||
|
||||
/* ATTRIBUE LES VALEUR DES PIN
|
||||
*
|
||||
* @values<Array> Valeurs
|
||||
*
|
||||
*/
|
||||
Chip.prototype.setPins = function(values){
|
||||
for( var i = 0 ; i < this.pins.length ; i++ )
|
||||
this.setPin( i, values[i] );
|
||||
};
|
||||
|
||||
|
||||
/* RECUPERE LA VALEUR D'UNE PIN DONNEE
|
||||
*
|
||||
* @pinOrder<int> Indice de la pin à lire
|
||||
*
|
||||
* @return value<int> Valeur entière dans 0-255
|
||||
*
|
||||
*/
|
||||
Chip.prototype.getPin = function(pinOrder){
|
||||
/* [0] Vérification des paramètres
|
||||
=========================================================*/
|
||||
/* (1) On vérifie que @pin est un entier et qu'elle existe */
|
||||
if( parseInt(pinOrder) != pinOrder || this.pins.length <= pinOrder ) return false;
|
||||
|
||||
|
||||
/* [1] On retourne la valeur
|
||||
=========================================================*/
|
||||
return this.values[pinOrder].get();
|
||||
};
|
||||
|
||||
|
||||
/* RECUPERE LES VALEUR DES PIN
|
||||
*
|
||||
* @return values<Array> Valeurs
|
||||
*
|
||||
*/
|
||||
Chip.prototype.getPins = function(){
|
||||
var values = [];
|
||||
|
||||
for( var i = 0 ; i < this.pins.length ; i++ )
|
||||
values[i] = this.getPin( i );
|
||||
|
||||
return values;
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var LedInterface;
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
/* CONSTRUCTEUR D'INTERFACE DE LED
|
||||
*
|
||||
* @chip<Chip> Puce associée à la LED
|
||||
* @container<Element> Conteneur de couleur
|
||||
*
|
||||
*/
|
||||
LedInterface = function(chip, container){
|
||||
/* [0] Vérification des paramètres
|
||||
=========================================================*/
|
||||
if( !(chip instanceof Chip) || !(container instanceof Element) )
|
||||
return;
|
||||
|
||||
/* [1] On enregistre les valeurs
|
||||
=========================================================*/
|
||||
this.chip = chip;
|
||||
this.container = container;
|
||||
};
|
||||
|
||||
|
||||
LedInterface.prototype = {
|
||||
chip: this.chip, // Puce associée à la LED
|
||||
container: this.container // Conteneur de couleur
|
||||
};
|
||||
|
||||
|
||||
/* APPLIQUE LA COULEUR EN FONCTION DES VALEURS DE LA 'CHIP'
|
||||
*
|
||||
*/
|
||||
LedInterface.prototype.update = function(){
|
||||
this.container.style.backgroundColor = 'rgb('+this.chip.getPin(0)+','+this.chip.getPin(1)+','+this.chip.getPin(2)+')';
|
||||
};
|
||||
|
||||
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var RelayInterface;
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
/* CONSTRUCTEUR D'INTERFACE DU RELAI
|
||||
*
|
||||
* @chip<Chip> Puce associée au relai
|
||||
* @container<Element> Conteneur du relai
|
||||
*
|
||||
*/
|
||||
RelayInterface = function(chip, container){
|
||||
/* [0] Vérification des paramètres
|
||||
=========================================================*/
|
||||
if( !(chip instanceof Chip) || !(container instanceof Element) )
|
||||
return;
|
||||
|
||||
/* [1] On enregistre les valeurs
|
||||
=========================================================*/
|
||||
this.chip = chip;
|
||||
this.container = container;
|
||||
};
|
||||
|
||||
|
||||
RelayInterface.prototype = {
|
||||
chip: this.chip, // Puce associée au relai
|
||||
container: this.container // Conteneur du relai
|
||||
};
|
||||
|
||||
|
||||
/* APPLIQUE L'ACTIVATION EN FONCTION DES VALEURS DE LA 'CHIP'
|
||||
*
|
||||
*/
|
||||
RelayInterface.prototype.update = function(){
|
||||
if( this.chip.getPin(0) > 1) this.container.addClass('active');
|
||||
else this.container.remClass('active');
|
||||
};
|
||||
|
||||
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
||||
var previous;
|
||||
var action;
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
/* RETOURNE SI UN ETAT EST CORRECT
|
||||
*
|
||||
* @previous<String> Condition d'état
|
||||
* @state<Array> Liste des états du système
|
||||
*
|
||||
* @return state<Boolean> Retourne si OUI ou NON l'état répond à la condition
|
||||
*
|
||||
*/
|
||||
previous = function(previous, state){
|
||||
console.warn(previous);
|
||||
previous = previous.toLowerCase();
|
||||
|
||||
for( var i = 0 ; i < previous.length ; i++ )
|
||||
if( previous[i] == 'x' ) continue;
|
||||
else if( previous[i] != state[i] ) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/* MODIFIE LES ETATS EN FONCTION D'UNE ACTION
|
||||
*
|
||||
* @action<String> Action sur les états
|
||||
* @state<Array> Liste des états du système
|
||||
*
|
||||
*/
|
||||
action = function(action, state){
|
||||
action = action.toLowerCase();
|
||||
|
||||
for( var i = 0 ; i < action.length ; i++ )
|
||||
if( action[i] == 'x' ) continue;
|
||||
else state[i] = parseInt(action[i]);
|
||||
};
|
||||
|
||||
|
||||
})();
|
|
@ -1,53 +0,0 @@
|
|||
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
|
||||
debug();
|
||||
|
||||
|
||||
// DEFAULT SESSION CREDENTIALS
|
||||
var_dump( 'SESSID---'.session_id() );
|
||||
// var_dump( 'TOKEN----'.( $_SESSION['session_token']==$_COOKIE['session_token'] ? 'YES' : 'NO' ) );
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<div id=ajax1>NO VALUE</div><br>
|
||||
<!-- <div id=ajax2>NO VALUE</div> -->
|
||||
|
||||
<br><br><br><br>
|
||||
|
||||
<button id=testAjax>LOAD AJAX</button>
|
||||
|
||||
<script type='text/javascript'>
|
||||
|
||||
|
||||
function pHandler(data){
|
||||
var parsedData = JSON.parse(data);
|
||||
|
||||
document.getElementById('ajax1').innerHTML = parsedData.data1;
|
||||
document.getElementById('ajax2').innerHTML = parsedData.data2;
|
||||
}
|
||||
|
||||
function testAjax(){
|
||||
var xhr; // object ajax
|
||||
|
||||
if(window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari
|
||||
xhr = new XMLHttpRequest();
|
||||
else // IE5, IE6
|
||||
xhr = new ActiveXObject('Microsoft.XMLHttpRequest');
|
||||
|
||||
xhr.onreadystatechange = function(){
|
||||
if( xhr.readyState == 4 ) // si la requête est terminée
|
||||
if( [0,200].indexOf(xhr.status) > -1 ) // si fichier existe et reçu
|
||||
pHandler(xhr.responseText);
|
||||
else // si code d'erreur retourne null
|
||||
pHandler();
|
||||
}
|
||||
|
||||
xhr.open( 'POST', '/test/ajaxTest.php', true );
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
document.getElementById('testAjax').onclick = testAjax;
|
||||
|
||||
</script>
|
|
@ -1,24 +0,0 @@
|
|||
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
debug();
|
||||
|
||||
use \manager\sessionManager;
|
||||
|
||||
|
||||
|
||||
$hash = 'password';
|
||||
$times = 1;
|
||||
|
||||
$start = microtime(true);
|
||||
$hashed = sessionManager::secure_hash($hash, $times);
|
||||
$stop = microtime(true);
|
||||
|
||||
var_dump( $hashed );
|
||||
$elapsed = ($stop-$start)/1000;
|
||||
var_dump('time: '. $elapsed . ' ms');
|
||||
var_dump('hash/sec: '. $elapsed/$times . ' ms');
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
|
@ -1,5 +1,5 @@
|
|||
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
require_once __ROOT__.'/vendor/autoload.php';
|
||||
use \api\core\Request;
|
||||
use \orm\core\Table;
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
require_once __ROOT__.'/vendor/autoload.php';
|
||||
use \viewer\core\Viewer;
|
||||
use \api\core\Request;
|
||||
use \database\core\Repo;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
require_once __ROOT__.'/vendor/autoload.php';
|
||||
use \api\core\Request;
|
||||
use \database\core\DatabaseDriver;
|
||||
use \database\core\Repo;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
require_once __ROOT__.'/vendor/autoload.php';
|
||||
use \viewer\core\Viewer;
|
||||
?>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
require_once __ROOT__.'/vendor/autoload.php';
|
||||
use \api\core\Request;
|
||||
?>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
require_once __ROOT__.'/vendor/autoload.php';
|
||||
use \api\core\Request;
|
||||
?>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
require_once '../../autoloader.php';
|
||||
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
||||
require_once __ROOT__.'/vendor/autoload.php';
|
||||
use \api\core\Request;
|
||||
use \viewer\core\Viewer;
|
||||
use \database\core\Repo;
|
||||
|
|
|
@ -0,0 +1,303 @@
|
|||
<?php
|
||||
|
||||
use \api\core\Checker;
|
||||
|
||||
describe('api', function(){
|
||||
|
||||
describe('core', function(){
|
||||
|
||||
describe('Checker', function(){
|
||||
|
||||
/* (1) Unknown type
|
||||
---------------------------------------------------------*/
|
||||
context('* unknown type', function(){
|
||||
|
||||
it('do not pass unknown type with any value', function(){
|
||||
|
||||
expect(Checker::run('unknown_type', 'someString' ))->toBeFalsy();
|
||||
expect(Checker::run('unknown_type', 123 ))->toBeFalsy();
|
||||
expect(Checker::run('unknown_type', [1, 2] ))->toBeFalsy();
|
||||
expect(Checker::run('unknown_type', true ))->toBeFalsy();
|
||||
expect(Checker::run('unknown_type', false ))->toBeFalsy();
|
||||
expect(Checker::run('unknown_type', new StdClass() ))->toBeFalsy();
|
||||
expect(Checker::run('unknown_type', null ))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* (2) Mixed
|
||||
---------------------------------------------------------*/
|
||||
context('* mixed', function(){
|
||||
|
||||
it('pass type="mixed" with any type', function(){
|
||||
|
||||
expect(Checker::run('mixed', 'someString' ))->toBeTruthy();
|
||||
expect(Checker::run('mixed', 123 ))->toBeTruthy();
|
||||
expect(Checker::run('mixed', [1, 2] ))->toBeTruthy();
|
||||
expect(Checker::run('mixed', true ))->toBeTruthy();
|
||||
expect(Checker::run('mixed', false ))->toBeTruthy();
|
||||
expect(Checker::run('mixed', new StdClass() ))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
it('do not pass type="mixed" with null', function(){
|
||||
|
||||
expect(Checker::run('mixed', null))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* (3) id
|
||||
---------------------------------------------------------*/
|
||||
context('* id', function(){
|
||||
|
||||
it('pass type="id" whith any integer number (string or int)', function(){
|
||||
|
||||
expect(Checker::run('id', '123' ))->toBeTruthy();
|
||||
expect(Checker::run('id', 123 ))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
it('do not pass type="id" whith decimal value (string or int)', function(){
|
||||
|
||||
expect(Checker::run('id', '1.23' ))->toBeFalsy();
|
||||
expect(Checker::run('id', 1.23 ))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
it('pass type="id" whith boundaries', function(){
|
||||
|
||||
expect(Checker::run('id', 0 ))->toBeTruthy();
|
||||
expect(Checker::run('id', 2147483647 ))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
it('do not pass type="id" whith not match out-of-boundaries', function(){
|
||||
|
||||
expect(Checker::run('id', 0-1 ))->toBeFalsy();
|
||||
expect(Checker::run('id', 2147483647+1 ))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* (4) text
|
||||
---------------------------------------------------------*/
|
||||
context('* text', function(){
|
||||
|
||||
it('pass type="text" with any string', function(){
|
||||
|
||||
expect(Checker::run('text', '123' ))->toBeTruthy();
|
||||
expect(Checker::run('text', '123'.'123' ))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
it('pass type="text" with empty string', function(){
|
||||
|
||||
$empty_str = '';
|
||||
expect($empty_str)->toHaveLength(0);
|
||||
expect(Checker::run('text', $empty_str))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
it('do not pass type="text" when not string', function(){
|
||||
|
||||
expect(Checker::run('text', [] ))->toBeFalsy();
|
||||
expect(Checker::run('text', 1 ))->toBeFalsy();
|
||||
expect(Checker::run('text', 1.23 ))->toBeFalsy();
|
||||
expect(Checker::run('text', true ))->toBeFalsy();
|
||||
expect(Checker::run('text', false ))->toBeFalsy();
|
||||
expect(Checker::run('text', new StdClass() ))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* (5) Rfid
|
||||
---------------------------------------------------------*/
|
||||
context('* hash', function(){
|
||||
|
||||
given('sizes', function(){ return [
|
||||
40 => 'sha1',
|
||||
64 => 'sha256',
|
||||
128 => 'sha512'
|
||||
];
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('do not pass when -40/64/128 char hash', function(){
|
||||
|
||||
foreach($this->sizes as $size=>$sha){
|
||||
|
||||
$hash = hash($sha, 'someClearText');
|
||||
$hash = substr($hash, 1); // remove 1 char
|
||||
|
||||
expect($hash)->toHaveLength($size-1);
|
||||
expect(Checker::run('hash', $hash))->toBeFalsy();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
it('pass when 40/64/128 char hash', function(){
|
||||
|
||||
foreach($this->sizes as $size=>$sha){
|
||||
|
||||
$hash = hash($sha, 'someClearText');
|
||||
|
||||
expect($hash)->toHaveLength($size);
|
||||
expect(Checker::run('hash', $hash))->toBeTruthy();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
it('do not pass when +40/64/128 char hash', function(){
|
||||
|
||||
foreach($this->sizes as $size=>$sha){
|
||||
|
||||
$hash = hash($sha, 'someClearText');
|
||||
$hash = $hash.'a'; // add character
|
||||
|
||||
expect($hash)->toHaveLength($size+1);
|
||||
expect(Checker::run('hash', $hash))->toBeFalsy();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
it('do not pass when incorrect character', function(){
|
||||
$hash = hash('sha256', 'someClearText');
|
||||
$hash[1] = 'g';
|
||||
|
||||
expect($hash)->not->toMatch('/^[a-f0-9]+$/');
|
||||
expect(Checker::run('hash', $hash))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* (6) mail
|
||||
---------------------------------------------------------*/
|
||||
context('* mail', function(){
|
||||
|
||||
it('do not pass type="mail" with out-of-boundaries elements match', function(){
|
||||
|
||||
expect(Checker::run('mail', '@b.cd'))->toBeFalsy();
|
||||
expect(Checker::run('mail', 'a@.cd'))->toBeFalsy();
|
||||
expect(Checker::run('mail', 'a@b.d'))->toBeFalsy();
|
||||
expect(Checker::run('mail', 'a@b.cdefg'))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
it('pass type="mail" with max length', function(){
|
||||
|
||||
$mail = str_repeat('a', 45).'@b.cd';
|
||||
|
||||
expect($mail)->toHaveLength(50);
|
||||
expect(Checker::run('mail', $mail))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
it('do not pass type="mail" with more than max length', function(){
|
||||
|
||||
$mail = str_repeat('a', 46).'@b.cd';
|
||||
|
||||
expect($mail)->toHaveLength(51);
|
||||
expect(Checker::run('mail', $mail))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
it('pass type="mail" with minimum match', function(){
|
||||
|
||||
expect(Checker::run('mail', 'a@b.cd'))->toBeTruthy();
|
||||
expect(Checker::run('mail', 'a@b.cdef'))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* (7) alphanumeric
|
||||
---------------------------------------------------------*/
|
||||
context('* alphanumeric', function(){
|
||||
|
||||
it('pass when : letters/numbers/./-', function(){
|
||||
|
||||
expect(Checker::run('alphanumeric', 'abcz0129-.'))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
it('pass when unicode', function(){
|
||||
|
||||
expect(Checker::run('alphanumeric', 'çèééàôò'))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
it('do not pass when not alphanumeric (space/,)', function(){
|
||||
|
||||
expect(Checker::run('alphanumeric', 'abcz0129-. '))->toBeFalsy();
|
||||
expect(Checker::run('alphanumeric', 'abcz0129-.,'))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
it('do not pass when empty', function(){
|
||||
|
||||
$str = '';
|
||||
|
||||
expect($str)->toBeEmpty();
|
||||
expect(Checker::run('alphanumeric', $str))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
/* (8) letters
|
||||
---------------------------------------------------------*/
|
||||
context('* letters', function(){
|
||||
|
||||
it('pass when letters (letters/space/-)', function(){
|
||||
|
||||
expect(Checker::run('letters', 'abcz- - -a'))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('do not pass when unicode', function(){
|
||||
|
||||
expect(Checker::run('letters', 'çèééàôò'))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
it('do not pass when not letters (./,/numbers)', function(){
|
||||
|
||||
expect(Checker::run('letters', 'abcz- - -a0'))->toBeFalsy();
|
||||
expect(Checker::run('letters', 'abcz- - -a9'))->toBeFalsy();
|
||||
expect(Checker::run('letters', 'abcz- - -a,'))->toBeFalsy();
|
||||
expect(Checker::run('letters', 'abcz- - -a.'))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
it('do not pass when empty', function(){
|
||||
|
||||
$str = '';
|
||||
|
||||
expect($str)->toBeEmpty();
|
||||
expect(Checker::run('letters', $str))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue