PHP code example of green-elephpant / carbon-aware
1. Go to this page and download the library: Download green-elephpant/carbon-aware 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/ */
use Buzz\Client\Curl;
use GreenElephpant\CarbonAware\DataProvider\EnergyCharts\Connector\EnergyChartsConnector;
use GreenElephpant\CarbonAware\DataProvider\EnergyCharts\EnergyCharts;
use GreenElephpant\CarbonAware\Service\CarbonAwareService;
use Nyholm\Psr7\Factory\Psr17Factory;
// Create HTTP client with HTTP message factory
// E.g. nyholm/psr7 and kriswallsmith/buzz
$psr17Factory = new Psr17Factory();
$psr18Client = new Curl($psr17Factory);
// Create Connector (here: for energy-charts.info)
$energyChartsConnector = new EnergyChartsConnector(
$psr18Client,
$psr17Factory,
);
// Setup location (the region of the world you want to get the information for)
$location = new GreenElephpant\CarbonAware\Location\Location('DE');
// Finally create the DataProvider instance, using the connector and the location
$dataProvider = new EnergyCharts(
$co2SignalConnector,
$location
);
$carbonAwareService = new CarbonAwareService($connector
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.