Deployment system
Fusio has a deployment system which allows you to store your complete Fusio configuration into .yaml
config files.
This allows you to store all config in a VCS so that you can easily reproduce a Fusio installation without sharing a
database. The deploy system internally also only talks to the REST API which is used by the backend app. If you want to
see a complex example you can take a look at our headless CMS repository
which uses the deploy system to build a headless CMS.
Operations
All operations are stored in dedicated routes file which includes for each operation a detail yaml file.
"page.getAll": !include resources/operations/page/collection.yaml
"page.get": !include resources/operations/page/entity.yaml
"post.getAll": !include resources/operations/post/collection.yaml
"post.get": !include resources/operations/post/entity.yaml
"comment.getAll": !include resources/operations/comment/collection.yaml
"comment.get": !include resources/operations/comment/entity.yaml
The operations detail yaml file contains all information about an operation which you can also provide at the backend. In this example we use as schema model classes which we have generated. Your action then also automatically receives those generated model classes.
scopes: ["comment"]
public: true
description: "Returns all available comments"
httpMethod: GET
httpPath: "/page"
httpCode: 200
outgoing: "App\\Model\\Comment_Collection"
throws:
500: "App\\Model\\Message"
action: "App\\Action\\Comment\\GetAll"
Models
All models are generated through a TypeSchema definition. Please take a look at the gen/ folder which contains the script to generate the models based on a TypeSchema definition.
Action
Each action uses a service to handle a specific resource. I.e. the comment create action only invokes the create method of the comment service so that the action does not contain any complex logic.
class Create extends ActionAbstract
{
private Comment $commentService;
public function __construct(Comment $commentService)
{
$this->commentService = $commentService;
}
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
{
try {
$id = $this->commentService->create(
$request->getPayload(),
$context
);
$message = new Message();
$message->setSuccess(true);
$message->setMessage('Comment successful created');
$message->setId($id);
} catch (StatusCodeException $e) {
throw $e;
} catch (\Throwable $e) {
throw new InternalServerErrorException($e->getMessage());
}
return $this->response->build(201, [], $message);
}
}
Deployment
Through the command php bin/fusio deploy
you can deploy the API. This command reads all .yaml
files and
creates/updates all resources through the API.