jalismrs/symfony.common.controller

Adds Symfony controller abstract class

This package's canonical repository appears to be gone and the package has been frozen as a result.

1.0.2 2021-03-04 10:49 UTC

This package is auto-updated.

Last update: 2024-05-04 18:08:51 UTC


README

Adds Symfony controller abstract class

Test

phpunit or vendor/bin/phpunit

coverage reports will be available in var/coverage

Use

returnFile

use Jalismrs\Symfony\Common\ControllerAbstract;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\BinaryFileResponse;

class SomeController extends ControllerAbstract
{
    public function someActionReturningFile(
        Request $request
    ): BinaryFileResponse
    {
        $file = 'some-file.ext';
    
       return $this->returnFile(
           $file,
       );
    }
}

returnJson

use Jalismrs\Symfony\Common\ControllerAbstract;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;

class SomeController extends ControllerAbstract
{
    public function someActionReturningObject(
        Request $request
    ): JsonResponse
    {
        return $this->returnJson(
            $request,
            new ArrayObject(
                [
                    'property' => 'value',
                ]
            ),
        );
    }
    
    public function someActionReturningList(
        Request $request
    ): JsonResponse
    {
       return $this->returnJson(
           $request,
           [
               [
                   'property' => 'value',
               ]
           ],
           'listing',
       );
    }
}