fusio/adapter-symfony

Integrates features of the symfony framework

v5.0.0 2022-01-07 20:52 UTC

This package is auto-updated.

Last update: 2024-03-03 17:51:42 UTC


README

Fusio adapter which helps to integrate features of Symfony. You can install the adapter with the following steps inside your Fusio project:

composer require fusio/adapter-symfony
php bin/fusio system:register "Fusio\Adapter\Symfony\Adapter"

Configuration

All your entities needs to be placed inside the folder src/Entity since the Doctrine connection checks only this folder.

Example

Through the Doctrine connection you can build API endpoints using the Doctrine ORM i.e.:

<?php

namespace App\Action;

use Fusio\Engine\ActionAbstract;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;
use JMS\Serializer\SerializerBuilder;

class Messages extends ActionAbstract
{
    public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
    {
        /** @var \Doctrine\ORM\EntityManager $entityManager */
        $entityManager = $this->connector->getConnection('doctrine');

        /** @var \JMS\Serializer\ArrayTransformerInterface $serializer */
        $serializer = SerializerBuilder::create()->build();

        $dql = "SELECT m FROM App\Entity\Message m ORDER BY m.id DESC";

        $query = $entityManager->createQuery($dql);
        $messages = $query->getResult();

        $result = [];
        foreach ($messages as $message) {
            $result[] = $serializer->toArray($message);
        }

        return $this->response->build(200, [], [
            'messages' => $result,
        ]);
    }
}