baldeweg / api-bundle
此包已被弃用且不再维护。未建议替代包。
提供API工具。
v55.0.3
2023-09-19 15:35 UTC
Requires
- php: >=8.2
- symfony/console: ^6.3
- symfony/dependency-injection: ^6.3
- symfony/framework-bundle: ^6.3
- symfony/http-foundation: ^6.3
- symfony/property-access: ^6.3
- symfony/serializer: ^6.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.23
- phpunit/phpunit: ^10.3
- symfony/maker-bundle: ^1.50
- symfony/var-dumper: ^6.3
README
提供API工具。
入门指南
composer req baldeweg/api-bundle
如果未自动完成,请在config/bundles.php
中激活此包。
Baldeweg\Bundle\ApiBundle\BaldewegApiBundle::class => ['all' => true],
用法
use Baldeweg\Bundle\ApiBundle\AbstractApiController; use Baldeweg\Bundle\ApiBundle\Response; $response = new Response(); // Contains the keys of the entity you need $fields = ['id', 'name', 'user' => ['id'], 'createdAtTimestamp', 'commentsCount']; // JSON Response with serialized data $response->single($fields, $genre); // single entity $response->collection($fields, $genres); // array of entities $response->invalid(); // Return message and 400 status code $response->deleted(); // Return message and 200 status code // Parse the data from the request and make them available to the form $this->submitForm($request)
测试特质
为了使XHR请求更容易,提供了一个可用的ApiTestTrait
特质。
use \Baldeweg\Bundle\ApiBundle\ApiTestTrait;
生成器
- make:api:controller - 创建控制器
- make:api:test - 创建测试