boshurik/api-bundle

Set of useful services for building API

0.3.1 2021-04-16 14:00 UTC

This package is auto-updated.

Last update: 2024-04-16 21:08:26 UTC


README

Build Status

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);
}