grzegorz-jamroz / sf-api-bundle
Bundle provides basic features for Symfony Api.
Installs: 116
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/grzegorz-jamroz/sf-api-bundle
Requires
- grzegorz-jamroz/plain-data-transformer: ^1.0
- symfony/framework-bundle: ^6.0|^7.0
- symfony/http-foundation: ^6.0|^7.0
- symfony/http-kernel: ^6.0|^7.0
- symfony/messenger: ^6.0|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.89
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.4
- symfony/yaml: ^6.0|^7.0
README
Bundle provides basic features for Symfony Api
Installation
composer require grzegorz-jamroz/sf-api-bundle
Development with Docker
Build and run the containers:
docker compose up -d
Copy vendor folder from container to host
docker compose cp app:/app/vendor ./vendor
Run static analysis
docker compose exec app bin/fix
Run tests
docker compose exec app bin/test
Run single test file:
docker compose exec app vendor/bin/phpunit --filter <testMethodName> <path/to/TestFile.php> docker compose exec app vendor/bin/phpunit --filter testShouldReturnExpectedFloat tests/Unit/TransformNumeric/ToFloatTest.php
Enable xdebug
docker compose exec app xdebug on
Disable xdebug
docker compose exec app xdebug off
Run coverage report
- Enable xdebug
- Run:
docker compose exec app bin/coverage
Usage
Add to your config/routes.yaml file
# config/routes.yaml ifrost_api: resource: ../src/Action/ type: ifrost_api
Default config
You can add config/packages/ifrost_api.yaml in your project to enable/disable some features if not necessary
# config/packages/ifrost_api.yaml # You can enable/disable some features if not necessary ifrost_api: api_request: true exception_listener: false
and from now you can add attribute Symfony\Component\Routing\Annotation\Route to your Action class for example:
<?php declare(strict_types=1); namespace App\Action\Product; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; #[Route('/product/promotion', name: 'product_promotion', methods: ['POST'])] class PromoteAction { public function __invoke(): Response { return new JsonResponse(['message' => 'product promotion']); } }
and when you run bin/console debug:router you will see:
------------------- -------- -------- ------ ----------------------------------- Name Method Scheme Host Path ------------------- -------- -------- ------ ----------------------------------- product_promotion POST ANY ANY /product/promotion ------------------- -------- -------- ------ -----------------------------------