add: build.router.controller.loader

upd: build.router.controller.api
upd: build.router.controller.page
This commit is contained in:
Guillaume FAUVET 2017-12-08 02:26:40 +01:00 committed by xdrm-brackets
parent aa5b97dcc8
commit d2b54f431b
3 changed files with 62 additions and 41 deletions

View File

@ -32,11 +32,13 @@
*
*/
public function call(){
/* (1) Authentication */
\router\controller\loader::start();
/* (1) Process response */
/* (2) Process response */
$this->response = $this->request->dispatch();
/* (2) Manages result */
/* (3) Manages result */
if( $this->response instanceof Response )
echo $this->response->serialize();

View File

@ -0,0 +1,57 @@
<?php
/**
* Created by PhpStorm.
* User: jean-kevin
* Date: 08/12/17
* Time: 02:07
*/
namespace router\controller;
use kwebsocket\core\wsinterop;
abstract class loader {
public static function start() {
if( $_SESSION['WS'] || strlen($_SESSION['NAME']) == 0 ){
// ask with websocketInterop
$wsi = new wsinterop('localhost', 9998);
if( count($_SESSION['USER']) > 0 ){
// get/send name to web socket
$wsi->send(['operation' => "Connect",'type' => 'user', 'name' => $_SESSION['USER']['username']]);
$check = $wsi->receive();
if( $check['error'] == false )
$_SESSION['NAME'] = $check['name'];
}elseif( count($_SESSION['ADMIN']) > 0 ){
// get/send name to web socket
$wsi->send(['operation' => "Connect",'type' => 'admin', 'name' => $_SESSION['ADMIN']['username']]);
$check = $wsi->receive();
if( $check['error'] == false )
$_SESSION['NAME'] = $check['name'];
}else{
// get/send name to web socket
$wsi->send(['operation' => "Connect",'type' => 'guest', 'name' => null]);
$check = $wsi->receive();
if( $check['error'] == false )
$_SESSION['NAME'] = $check['name'];
}
$wsi->close();
$wsi = null;
$_SESSION['WS'] = false;
}
}
}

View File

@ -26,46 +26,8 @@
*
*/
public function load(){
loader::start();
if( $_SESSION['WS'] || strlen($_SESSION['NAME']) == 0 ){
// ask with websocketInterop
$wsi = new wsinterop('localhost', 9998);
if( count($_SESSION['USER']) > 0 ){
// get/send name to web socket
$wsi->send(['operation' => "Connect",'type' => 'user', 'name' => $_SESSION['USER']['username']]);
$check = $wsi->receive();
if( $check['error'] == false )
$_SESSION['NAME'] = $check['name'];
}elseif( count($_SESSION['ADMIN']) > 0 ){
// get/send name to web socket
$wsi->send(['operation' => "Connect",'type' => 'admin', 'name' => $_SESSION['ADMIN']['username']]);
$check = $wsi->receive();
if( $check['error'] == false )
$_SESSION['NAME'] = $check['name'];
}else{
// get/send name to web socket
$wsi->send(['operation' => "Connect",'type' => 'guest', 'name' => null]);
$check = $wsi->receive();
if( $check['error'] == false )
$_SESSION['NAME'] = $check['name'];
}
$wsi->close();
$wsi = null;
$_SESSION['WS'] = false;
}
if( file_exists(__ROOT__."/view/home.php") )
include __ROOT__."/view/home.php";
else