PHP code example of boshurik / api-bundle

1. Go to this page and download the library: Download boshurik/api-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

boshurik / api-bundle example snippets


class SomeController
{
    public function someAction(SomeModel $model)
    {
        // $model - validated object   
    }
}

/**
 * @var SomeEntity $entity
 */
$data = $this->serializer->normalize($entity); // $entity->getId() value
$entity = $this->serializer->denormalize('some-id', SomeEntity::class); // SomeEntity instant  

$violations = $this->validator->validate($model);
if ($violations->count() > 0) {
    throw new ValidationException($violations);
}
 php

// config/bundles.php

return [
    //...
    \BoShurik\ApiBundle\BoShurikApiBundle => ['all' => true],
];