PHP code example of tracium / symfony

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

    

tracium / symfony example snippets


// config/bundles.php
return [
    // ...
    Apirelio\Symfony\ApirelioBundle::class => ['all' => true],
];



namespace App\Apirelio;

use Symfony\Component\HttpFoundation\Request;
use Apirelio\Symfony\Contracts\CustomerResolver;
use Apirelio\Symfony\Data\ApirelioCustomer;

final class ApiCustomerResolver implements CustomerResolver
{
    public function resolve(Request $request): ?ApirelioCustomer
    {
        $client = $request->attributes->get('api_client');

        return $client === null
            ? null
            : new ApirelioCustomer(
                id: (string) $client->companyId,
                name: $client->companyName,
                plan: $client->plan,
            );
    }
}



namespace App\Apirelio;

use Symfony\Component\HttpFoundation\Request;
use Apirelio\Symfony\Contracts\ApplicationResolver;
use Apirelio\Symfony\Data\ApirelioApplication;

final class ApiApplicationResolver implements ApplicationResolver
{
    public function resolve(Request $request): ?ApirelioApplication
    {
        $client = $request->attributes->get('api_client');

        return $client === null
            ? null
            : new ApirelioApplication(
                id: (string) $client->id,
                name: $client->name,
            );
    }
}

use Apirelio\Symfony\ApirelioManager;

final class SendInvoiceController
{
    public function __invoke(ApirelioManager $apirelio): Response
    {
        $apirelio
            ->setErrorCode('INVALID_CURRENCY')
            ->addMetadata([
                'integration_type' => 'accounting',
                'region' => 'eu-central',
            ]);

        // ...
    }
}
bash
php bin/console messenger:consume async
bash
php bin/console apirelio:flush