PHP code example of open-solid / open-api-bundle

1. Go to this page and download the library: Download open-solid/open-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/ */

    

open-solid / open-api-bundle example snippets




namespace Api\Catalog\Controller\Post;

use Api\Catalog\Model\Product;
use OpenSolid\OpenApiBundle\Attribute\Payload;
use OpenSolid\OpenApiBundle\Routing\Attribute\Post;

class PostProductAction
{
    #[Post('/products')]
    public function __invoke(#[Payload] PostProductPayload $payload): Product
    {
        return new Product($payload->name, $payload->price);
    }
}
yaml
openapi:
    resource: '@OpenApiBundle/config/routes.php'