2016-08-25 10:47:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Vn\Web;
|
|
|
|
|
2016-08-30 07:43:47 +00:00
|
|
|
require_once (__DIR__.'/rest-service.php');
|
2016-08-25 10:47:09 +00:00
|
|
|
|
2016-09-06 14:25:02 +00:00
|
|
|
use Vn\Lib;
|
|
|
|
|
2016-08-25 10:47:09 +00:00
|
|
|
/**
|
|
|
|
* Base class for REST services.
|
|
|
|
**/
|
|
|
|
abstract class RestRequest extends \Vn\Lib\Method
|
|
|
|
{
|
2016-09-06 14:25:02 +00:00
|
|
|
const PARAMS = NULL;
|
|
|
|
const LOGIN_REQUIRED = TRUE;
|
|
|
|
|
|
|
|
function runRest ()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$db = $this->login ();
|
|
|
|
}
|
|
|
|
catch (Exception $e)
|
|
|
|
{
|
|
|
|
if (self::LOGIN_REQUIRED)
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self::PARAMS !== NULL && !$this->checkParams ($_REQUEST, self::PARAMS))
|
|
|
|
throw new Lib\UserException (s('Missing parameters'));
|
|
|
|
|
|
|
|
return $this->run ($db);
|
|
|
|
}
|
|
|
|
|
2016-08-25 10:47:09 +00:00
|
|
|
/**
|
|
|
|
* Authenticates the user agaisnt database and returns its associated
|
|
|
|
* database connection.
|
|
|
|
*
|
|
|
|
* return Db\Conn The database connection
|
|
|
|
**/
|
|
|
|
function login ()
|
|
|
|
{
|
|
|
|
return $this->app->login ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logouts the current user.
|
|
|
|
**/
|
|
|
|
function logout ()
|
|
|
|
{
|
|
|
|
$this->app->logout ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|