2017-11-23 10:23:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace router\controller;
|
|
|
|
|
|
|
|
use \api\core\Request;
|
|
|
|
use \api\core\Response;
|
|
|
|
use \api\core\Loader;
|
|
|
|
|
|
|
|
|
|
|
|
class api{
|
|
|
|
|
|
|
|
private $request;
|
|
|
|
private $response;
|
|
|
|
|
|
|
|
/* PRE-CALL
|
|
|
|
*
|
|
|
|
* @url<String> Calling URI
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __construct($matches){
|
|
|
|
|
|
|
|
/* (1) Rebuild request url */
|
|
|
|
$uri = $matches['module'].'/'.$matches['method'].$matches['uri_args'];
|
|
|
|
|
|
|
|
/* (2) Creates request */
|
|
|
|
$this->request = Loader::remote($uri);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* CALL
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function call(){
|
2017-12-08 01:26:40 +00:00
|
|
|
/* (1) Authentication */
|
|
|
|
\router\controller\loader::start();
|
2017-11-23 10:23:09 +00:00
|
|
|
|
2017-12-08 01:26:40 +00:00
|
|
|
/* (2) Process response */
|
2017-11-23 10:23:09 +00:00
|
|
|
$this->response = $this->request->dispatch();
|
|
|
|
|
2017-12-08 01:26:40 +00:00
|
|
|
/* (3) Manages result */
|
2017-11-23 10:23:09 +00:00
|
|
|
if( $this->response instanceof Response )
|
|
|
|
echo $this->response->serialize();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* POST-CALL
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __destruct(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|