The PHPCallback action executes a callback of the app. The callback must be available as a file and as a class in the app folder.
You must derive a callback from the class \edoc\appserver\ScriptAPI\Callback.
Example
PHP
< ?php
use edoc\appserver\ScriptAPI\Callback;
// Simple example for a callback
// The class name must match the file name!
class Example extends Callback
{
public function init()
{
}
public function exec()
{
$name = $this->param('name');
$this->api->returnValue('Hello ' . $name . '!');
}
}
Script API
PHP
class Action {
// Executes an action.
// @param string $actionName Type of action, e.g. default\\Message.
// @param array $params The parameter for the selected action.
public function exec($actionName, $params);
// Get datasource instance (d.3/db/...)
// @param $name
// @return DataSource|null
public function getDatasource($name): ?DataSource;
// Sets return value of the callback. If called several times, the previous value will be overwritten!
// @param string|int|boolean $value The return value.
public function returnValue($value);
// Sets the return dataset of the callback. If called several times, the previous value will be overwritten!
// @param array $value The return dataset.
public function returnDataset($value);
// Returns information about the current app.
// @return array
public function info();
// Returns all app variables.
// @return array
public function getAppVariables();
// Returns the app variable with the name $name.
// @return mixed
public function getAppVariable($name);
}
class Callback {
// Returns all parameter passed.
// @return array
public function params();
// Returns the passed parameter with the specified names.
// @return mixed
public function param($name);
// Checks whether a parameter with the name $name was returned. Returns true or false.
// @return boolean
public function paramExists($name);
abstract public function init();
abstract public function exec();
}
Parameters
|
Type |
Name |
Description |
|---|---|---|
|
TEXT |
file |
Specifies the path and name of the PHP script on the server in the plugins directory of the app. |
|
KEYVALUELIST |
params |
Specifies the list with the names and values of the parameters that are passed to the callback. |
Return
|
Type |
Description |
|---|---|
|
SINGLEVALUE |
Returns the value of the callback. |
|
DATASET |
Returns the record of the callback. |