boshurik / api-bundle
Set of useful services for building API
Installs: 1 368
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8.0
- symfony/framework-bundle: ^5.0
- symfony/serializer: ^5.0
- symfony/validator: ^5.0
Requires (Dev)
- doctrine/persistence: ^2.0
- friendsofphp/php-cs-fixer: ^2.16
- psalm/plugin-symfony: ^2.0
- symfony/phpunit-bridge: ^5.0
- vimeo/psalm: ^4.0
Suggests
- doctrine/mongodb-odm: To use abstract object normalizer with documents
- doctrine/orm: To use abstract object normalizer with entities
README
Set of useful services for building API
Installation
Composer
$ composer require boshurik/api-bundle
If you are using symfony/flex it is all you need to do
Register the bundle
<?php // config/bundles.php return [ //... \BoShurik\ApiBundle\BoShurikApiBundle => ['all' => true], ];
Usage
ArgumentResolver
class SomeController { public function someAction(SomeModel $model) { // $model - validated object } }
Serializer
/** * @var SomeEntity $entity */ $data = $this->serializer->normalize($entity); // $entity->getId() value $entity = $this->serializer->denormalize('some-id', SomeEntity::class); // SomeEntity instant
ValidationException
$violations = $this->validator->validate($model); if ($violations->count() > 0) { throw new ValidationException($violations); }