2018-02-17 17:18:58 +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['uri'];
|
|
|
|
|
|
|
|
/* (2) Creates request */
|
|
|
|
$this->request = Loader::remote($uri);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* CALL
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function call(){
|
|
|
|
|
|
|
|
/* (1) Process response */
|
|
|
|
$this->response = $this->request->dispatch();
|
|
|
|
|
|
|
|
/* (2) Manages result */
|
2018-03-01 16:43:03 +00:00
|
|
|
if( $this->response instanceof Response ){
|
|
|
|
header('Content-Type: application/json');
|
2018-02-17 17:18:58 +00:00
|
|
|
echo $this->response->serialize();
|
2018-03-01 16:43:03 +00:00
|
|
|
}
|
2018-02-17 17:18:58 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* POST-CALL
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __destruct(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|