55 lines
850 B
PHP
55 lines
850 B
PHP
<?php
|
|
|
|
namespace Vn\Web;
|
|
|
|
require_once (__DIR__.'/rest-service.php');
|
|
|
|
use Vn\Lib;
|
|
|
|
/**
|
|
* Base class for REST services.
|
|
**/
|
|
abstract class RestRequest extends \Vn\Lib\Method
|
|
{
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* 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 ();
|
|
}
|
|
}
|
|
|
|
?>
|