Create interface for static Module calls

This commit is contained in:
Philipp 2021-11-14 20:28:36 +01:00
parent 96996790f1
commit 018275919c
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
8 changed files with 170 additions and 93 deletions

View file

@ -21,6 +21,7 @@
namespace Friendica;
use Friendica\Capabilities\ICanHandleRequests;
use Friendica\Core\Logger;
use Friendica\Model\User;
@ -33,23 +34,33 @@ use Friendica\Model\User;
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
abstract class BaseModule
abstract class BaseModule implements ICanHandleRequests
{
/** @var array */
protected static $parameters = [];
public function __construct(array $parameters = [])
{
static::$parameters = $parameters;
}
/**
* Initialization method common to both content() and post()
*
* Extend this method if you need to do any shared processing before both
* content() or post()
* @return array
*/
public static function getParameters(): array
{
return self::$parameters;
}
/**
* {@inheritDoc}
*/
public static function init(array $parameters = [])
{
}
/**
* Module GET method to display raw content from technical endpoints
*
* Extend this method if the module is supposed to return communication data,
* e.g. from protocol implementations.
* {@inheritDoc}
*/
public static function rawContent(array $parameters = [])
{
@ -58,46 +69,29 @@ abstract class BaseModule
}
/**
* Module GET method to display any content
*
* Extend this method if the module is supposed to return any display
* through a GET request. It can be an HTML page through templating or a
* XML feed or a JSON output.
*
* @return string
* {@inheritDoc}
*/
public static function content(array $parameters = [])
{
$o = '';
return $o;
return '';
}
/**
* Module DELETE method to process submitted data
*
* Extend this method if the module is supposed to process DELETE requests.
* Doesn't display any content
* {@inheritDoc}
*/
public static function delete(array $parameters = [])
{
}
/**
* Module PATCH method to process submitted data
*
* Extend this method if the module is supposed to process PATCH requests.
* Doesn't display any content
* {@inheritDoc}
*/
public static function patch(array $parameters = [])
{
}
/**
* Module POST method to process submitted data
*
* Extend this method if the module is supposed to process POST requests.
* Doesn't display any content
* {@inheritDoc}
*/
public static function post(array $parameters = [])
{
@ -105,24 +99,25 @@ abstract class BaseModule
}
/**
* Called after post()
*
* Unknown purpose
* {@inheritDoc}
*/
public static function afterpost(array $parameters = [])
{
}
/**
* Module PUT method to process submitted data
*
* Extend this method if the module is supposed to process PUT requests.
* Doesn't display any content
* {@inheritDoc}
*/
public static function put(array $parameters = [])
{
}
/** Gets the name of the current class */
public static function getClassName(): string
{
return static::class;
}
/*
* Functions used to protect against Cross-Site Request Forgery
* The security token has to base on at least one value that an attacker can't know - here it's the session ID and the private key.