Guides
Tutorials
// src/App/ApiResource.php
namespace App\ApiResource;
use ApiPlatform\Metadata\ApiResource;
use App\State\BookProcessor;
// src/App/ApiResource.php
namespace App\ApiResource;
use ApiPlatform\Metadata\ApiResource;
use App\State\BookProcessor;
We use a BookProcessor
as the ApiResource::processor option.
#[ApiResource(processor: BookProcessor::class)]
class Book
{
public string $id;
}
// src/App/State.php
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\ApiResource\Book;
#[ApiResource(processor: BookProcessor::class)]
class Book
{
public string $id;
}
// src/App/State.php
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\ApiResource\Book;
final class BookProcessor implements ProcessorInterface
{
/**
* @param Book $data
*/
public function process($data, Operation $operation, array $uriVariables = [], array $context = [])
{
file_put_contents(sprintf('book-%s.json', $uriVariables['id']), json_encode($data));
return $data;
}
}
final class BookProcessor implements ProcessorInterface
{
/**
* @param Book $data
*/
public function process($data, Operation $operation, array $uriVariables = [], array $context = [])
{
file_put_contents(sprintf('book-%s.json', $uriVariables['id']), json_encode($data));
return $data;
}
}