fusio/sdk-laravel

SDK to integrate Fusio into your Laravel application

v0.2.3 2022-08-06 21:06 UTC

This package is auto-updated.

Last update: 2024-10-16 16:45:41 UTC


README

This library integrates the Fusio SDK into Laravel. That means you can control the complete Fusio backend API through your laravel application. There is also a Laravel sample application which shows how to use this SDK.

Configuration

In order to access the API you need to provide a base_uri, app_key and app_secret at the config. By default, we load this data from the config.

Usage

Backend

Create an action:

$config = new \Fusio\Sdk\Backend\Action_Config();
$config['response'] = \json_encode(['hello' => 'world']);

$action = new \Fusio\Sdk\Backend\Action_Create();
$action->setName('my-new-action');
$action->setClass('Fusio\Adapter\Util\Action\UtilStaticResponse');
$action->setConfig($config);

$response = FusioClient::backend()->getBackendAction()->backendActionActionCreate($action);

echo $response->getMessage() . "\n";

Create an app:

$app = new \Fusio\Sdk\Backend\App_Create();
$app->setStatus(1);
$app->setUserId(1);
$app->setName('my-new-action');
$app->setUrl('https://myapp.com');
$app->setScopes(['foo', 'bar']);

$response = FusioClient::backend()->getBackendApp()->backendActionAppCreate($app);

echo $response->getMessage() . "\n";

Create a route:

$get = new \Fusio\Sdk\Backend\Route_Method();
$get->setActive(true);
$get->setPublic(true);
$get->setDescription('My GET description');
$get->setOperationId('my_get_operation_id');
$get->setResponse('My_Response_Schema');
$get->setAction('My_Action');

$methods = new \Fusio\Sdk\Backend\Route_Methods();
$methods['GET'] = $get;

$version = new \Fusio\Sdk\Backend\Route_Version();
$version->setVersion(1);
$version->setStatus(1);
$version->setMethods($methods);

$route = new \Fusio\Sdk\Backend\Route_Create();
$route->setPath('/new/path');
$route->setController('Fusio\Impl\Controller\SchemaApiController');
$route->setConfig([$version]);

$response = FusioClient::backend()->getBackendRoutes()->backendActionRouteCreate($route);

echo $response->getMessage() . "\n";

Get routes:

$entries = FusioClient::backend()->getBackendRoutes()->backendActionRouteGetAll(null)->getEntry();

foreach ($entries as $entry) {
    echo $entry->getPath() . "\n";
}

Consumer

Change password:

$changePassword = new \Fusio\Sdk\Consumer\Account_ChangePassword();
$changePassword->setOldPassword('test1234');
$changePassword->setNewPassword('test1234!');
$changePassword->setVerifyPassword('test1234!');

$response = FusioClient::consumer()->getConsumerAccountChangePassword()->consumerActionUserChangePassword($changePassword);

echo $response->getMessage() . "\n";