php-vn-lib/lib/method.php

60 lines
1.1 KiB
PHP

<?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.
*
* @param {Db\Conn} $db The main database connection
* @return mixed The result of the method
*/
abstract function run($db);
/**
* Returns the system database connection.
*
* return {Db\Conn} The database connection
*/
function getSysConn() {
return $this->app->getSysConn();
}
/**
* 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 (!isset($map[$param])) {
return FALSE;
break;
}
return TRUE;
}
}