PHP code example of jokod / impactco2-php

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

    

jokod / impactco2-php example snippets




okod\Impactco2Php\Client;
use Jokod\Impactco2Php\Endpoints\HeaterEnpoint;
use Jokod\Impactco2Php\Enums\LanguagesEnum;
use Jokod\Impactco2Php\Endpoints\ThematicsEcvEndpoint;
use Jokod\Impactco2Php\Enums\ThematicEnum;
use Jokod\Impactco2Php\Endpoints\TransportEndpoint;
use Jokod\Impactco2Php\Enums\TransportsEnum;

// Créer une instance du client
$client = new Client([
    'api_key' => 'votre_cle_api', // Optionnel
    'language' => LanguagesEnum::ES // Langue par défaut: FR
]);

// Utiliser l'endpoint ThematicsEcvEndpoint (/thematiques/ecv/{id})
try {
    $thematicsEcvEndpoint = new ThematicsEcvEndpoint(ThematicEnum::FURNITURE, 0); // id et détail
    $response = $client->execute($thematicsEcvEndpoint);
    echo $response;
} catch (\Exception $e) {
    echo 'Erreur : ' . $e->getMessage();
}

// Utiliser l'endpoint TransportEndpoint (/transport)
try {
    $transportEndpoint = new TransportEndpoint(
        10, // distance
        [ // Liste des transports
            TransportsEnum::CAR,
            TransportsEnum::ELECTRIC_CAR
        ], 
        false, // Tous les transports
        0, // Taux de remplissage moyen
        3 // Inclure la construction
    );
    $response = $client->execute($transportEndpoint);
    echo $response;
} catch (\Exception $e) {
    echo 'Erreur : ' . $e->getMessage();
}
bash
composer