2016-05-09 07:40:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Vn\Lib;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for rest methods.
|
|
|
|
**/
|
|
|
|
abstract class Method
|
|
|
|
{
|
|
|
|
protected $app;
|
|
|
|
protected $conn = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the method.
|
|
|
|
*
|
|
|
|
* @param app Lib\App The application
|
|
|
|
**/
|
|
|
|
function __construct ($app)
|
|
|
|
{
|
|
|
|
$this->app = $app;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the method. Shoud be defined by child classes.
|
|
|
|
*
|
2016-09-27 06:20:02 +00:00
|
|
|
* @param {Db\Conn} $db The main database connection
|
2016-05-09 07:40:46 +00:00
|
|
|
* @return mixed The result of the method
|
|
|
|
**/
|
2016-09-27 06:20:02 +00:00
|
|
|
abstract function run ($db);
|
2016-05-09 07:40:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the system database connection.
|
|
|
|
*
|
2016-09-27 06:20:02 +00:00
|
|
|
* return {Db\Conn} The database connection
|
2016-05-09 07:40:46 +00:00
|
|
|
**/
|
|
|
|
function getSysConn ()
|
|
|
|
{
|
|
|
|
return $this->app->getSysConn ();
|
|
|
|
}
|
2016-08-22 10:42:31 +00:00
|
|
|
|
2016-05-09 07:40:46 +00:00
|
|
|
/**
|
|
|
|
* Check if a set of keys are defined and not empty inside the passed
|
|
|
|
* associative array.
|
|
|
|
*
|
|
|
|
* @param {string} $map The map to check
|
|
|
|
* @param {array} $params The list of keys to check
|
|
|
|
* @return {boolean} %TRUE if all key are defined, %FALSE otherwise
|
|
|
|
**/
|
|
|
|
function checkParams ($map, $params)
|
|
|
|
{
|
|
|
|
if (!isset ($map))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
foreach ($params as $param)
|
|
|
|
if (empty ($map[$param]))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|