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
Requires
- php: ^7.4 || ^8.0
- jalismrs/symfony.common.helpers.request: ^1.0.0
- symfony/framework-bundle: ^5.0
- symfony/http-foundation: ^5.0
Requires (Dev)
- composer/package-versions-deprecated: *
- phpunit/phpunit: 9.4.2
- roave/security-advisories: dev-master
- symfony/mime: ^5.0
Suggests
- symfony/mime: Get a more accurate Content-Type header value when using returnFile()
- symfony/serializer: Adds configurable serialization when using returnJson()
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', ); } }