grzegorz-jamroz/sf-api-bundle
Composer 安装命令:
composer require grzegorz-jamroz/sf-api-bundle
包简介
Bundle provides basic features for Symfony Api.
README 文档
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 ------------------- -------- -------- ------ -----------------------------------
统计信息
- 总下载量: 162
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2022-05-18