PHP code example of reynevan / imgw-php

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

    

reynevan / imgw-php example snippets


use Reynevan\Imgw\ImgwClient;

$client = new ImgwClient();

foreach ($client->synop()->getWeatherStations() as $station) {
    printf(
        "%s: %.1f°C\n",
        $station->getName(),
        $station->getTemperature()
    );
}

$synop = $client->synop();

$stations = $synop->getWeatherStations();          // WeatherStation[]
$station  = $synop->getWeatherStationById(12500);   // WeatherStation
$station  = $synop->getWeatherStationByName('Warszawa'); // WeatherStation

foreach ($client->hydro()->getHydroStations() as $station) {
    printf(
        "%s (%s): water level %s cm\n",
        $station->getName(),
        $station->getRiver(),
        $station->getWaterLevel()
    );
}

foreach ($client->meteo()->getMeteoStations() as $station) {
    printf(
        "%s: %.1f°C\n",
        $station->getName(),
        $station->getAirTemperature()
    );
}

foreach ($client->warningshydro()->getWarnings() as $warning) {
    printf(
        "[%s] %s (level %d), valid from %s to %s\n",
        $warning->getOffice(),
        $warning->getEvent(),
        $warning->getLevel(),
        $warning->getValidFrom()?->format('Y-m-d H:i'),
        $warning->getValidTo()?->format('Y-m-d H:i')
    );
}

foreach ($client->warningsmeteo()->getWarnings() as $warning) {
    printf(
        "[%s] %s (level %d)\n",
        $warning->getOffice(),
        $warning->getEvent(),
        $warning->getLevel()
    );
}

use Reynevan\Imgw\Http\HttpClientInterface;
use Reynevan\Imgw\Http\PsrHttpClientAdapter;
use Reynevan\Imgw\ImgwClient;

$httpClient = new PsrHttpClientAdapter($myPsr18Client, $myPsr17RequestFactory);
$client = new ImgwClient($httpClient);

use Reynevan\Imgw\Exceptions\ImgwApiException;

try {
    $station = $client->synop()->getWeatherStationById(999999);
} catch (ImgwApiException $e) {
    // e.g. the station doesn't exist or the API is unavailable
}
bash
composer