PHP code example of rugaard / pollen

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

    

rugaard / pollen example snippets


use Rugaard\Pollen\Pollen;

$pollen = new Pollen;

new Pollen(?GuzzleClientInterface $client = null);

get(?Station $station = null, bool $onlyInSeason = false): Collection

use Rugaard\Pollen\Enums\Station;
use Rugaard\Pollen\Pollen;

$pollen = new Pollen;

# All stations.
$measurements = $pollen->get();

# A specific station.
$measurements = $pollen->get(station: Station::East);

# A specific station, in-season allergens only.
$measurements = $pollen->get(station: Station::East, onlyInSeason: true);

$measurements = $pollen->get(station: Station::East);

// Access a specific allergen.
$birch = $measurements->get('birch');

// $birch is a Collection:
// [
//     'date'        => '2024-04-01',        // measurement date
//     'value'       => 200,                 // raw grain count
//     'level'       => Level::High,         // classified level enum
//     'predictions' => Collection [         // null for spore allergens
//         ['date' => '2024-04-02', 'level' => Level::Moderate],
//         ['date' => '2024-04-03', 'level' => Level::Low],
//     ],
// ]

// Out-of-season allergens are null.
$mugwort = $measurements->get('mugwort'); // null

$measurements = $pollen->get();

$east = $measurements->get('east'); // Collection of allergens for Station::East
$west = $measurements->get('west'); // Collection of allergens for Station::West

use Rugaard\Pollen\Enums\Level;

$birch = $measurements->get('birch');

// Compare against a level.
if ($birch->get('level') === Level::VeryHigh) {
    // 🤧
}

// Get a machine-readable code.
$birch->get('level')->code(); // e.g. 'very-high'

// Get the Danish name.
$birch->get('level')->danishName(); // e.g. 'meget højt'