forked from verdnatura/hedera-web
77 lines
1.5 KiB
PHP
77 lines
1.5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Vn\Web;
|
||
|
|
||
|
require_once (__DIR__.'/app.php');
|
||
|
|
||
|
/**
|
||
|
* Base class for rest services.
|
||
|
**/
|
||
|
class RestApp extends App
|
||
|
{
|
||
|
private $error = NULL;
|
||
|
private $warnings = NULL;
|
||
|
|
||
|
function run ()
|
||
|
{
|
||
|
$this->reply = new JsonReply ();
|
||
|
|
||
|
$this->init ();
|
||
|
$this->startSession ();
|
||
|
|
||
|
try {
|
||
|
// Checks the client version
|
||
|
|
||
|
if (!empty ($_COOKIE['vn_version']))
|
||
|
$clientVersion = (int) $_COOKIE['vn_version'];
|
||
|
|
||
|
if (isset ($clientVersion)
|
||
|
&& $clientVersion < $this->getVersion ())
|
||
|
throw new Lib\UserException (s('Critical version available'), 'newVersion');
|
||
|
|
||
|
// Fetchs the result
|
||
|
|
||
|
$method = $this->loadMethod ($_REQUEST['method']);
|
||
|
$method->run ();
|
||
|
}
|
||
|
catch (SessionExpiredException $e)
|
||
|
{
|
||
|
$this->setError (s('The session has expired'), 'sessionExpired');
|
||
|
}
|
||
|
catch (BadLoginException $e)
|
||
|
{
|
||
|
$this->setError (s('Invalid login'), 'badLogin');
|
||
|
}
|
||
|
catch (Lib\UserException $e)
|
||
|
{
|
||
|
$this->setError ($e->getMessage (), $e->getCode ());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function errorHandler ($errno, $message, $file, $line, $context)
|
||
|
{
|
||
|
switch ($errno)
|
||
|
{
|
||
|
case E_USER_WARNING:
|
||
|
$this->addWarning ($message, $errno);
|
||
|
break;
|
||
|
case E_WARNING:
|
||
|
case E_CORE_WARNING:
|
||
|
case E_COMPILE_WARNING:
|
||
|
$this->addWarning ('Something has gone wrong', 'internalWarning');
|
||
|
default:
|
||
|
return parent::errorHandler ($errno, $message, $file, $line, $context);
|
||
|
}
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
function globalErrorHandler ()
|
||
|
{
|
||
|
$this->setError ('An internal error has occurred', 'internalError');
|
||
|
exit (0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
?>
|