1. Go to this page and download the library: Download beziworld/laravel-gus-bdl 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/ */
beziworld / laravel-gus-bdl example snippets
use Beziworld\GusBdl\Facades\GusBdl;
GusBdl::subjects()->all(); // top level: K3 "LUDNOŚĆ", ...
GusBdl::subjects('K3')->pluck('name'); // children of a subject
GusBdl::subject('K3')->children; // ["G7", "G8", ...] with years and availability
GusBdl::searchSubjects('samochody')->first(); // Subject "Ciągniki, samochody i maszyny rolnicze"
$variable = GusBdl::variable(60559);
$variable->name(); // "ludność na 1 km2" (dimensions n1-n5 joined with " / ")
$variable->subjectId; // "P2425"
$variable->level(); // Level::Commune
$variable->measureUnitName; // "osoba"
$variable->years; // [2002, ..., 2025]
GusBdl::variables('P2425')->all();
GusBdl::searchVariables('gęstość zaludnienia', level: Level::Commune, years: [2023])->take(20)->all();
use Beziworld\GusBdl\Enums\Level;
GusBdl::units(levels: [Level::Voivodeship])->all(); // 16 voivodeships
GusBdl::units('011200000000', [Level::County])->all(); // counties of Małopolskie
GusBdl::searchUnits('Kraków', [Level::Commune])->first();
GusBdl::unit('011212161011'); // details with years
$krakow = GusBdl::unitByTeryt('1261011'); // also "12" (voivodeship) and "1261" (county)
$krakow->id; // "011212161011"
$krakow->terytCode(); // "1261011"
$krakow->kind; // "1" (urban commune)
GusBdl::localities('011212001011')->all(); // statistical localities of a commune
GusBdl::unit('011212001011-0981682')->simc(); // "0981682"
// One variable for many units: one DataSeries per unit
foreach (GusBdl::dataByVariable(60559, years: [2022, 2023], level: Level::Voivodeship) as $series) {
$series->unitName; // "MAŁOPOLSKIE"
$series->value(2023); // 225.9
}
// One unit, several variables: one DataSeries per variable
$series = GusBdl::dataByUnit('011212000000', [60559, 72305], [2022, 2023])->keyBy('variableId');
$series[72305]->toArray(); // [2022 => 768015.0, 2023 => 771436.0]
// Shortcut accepting a BDL id, a locality id or a TERYT code
$density = GusBdl::series(60559, '1261011', [2023]);
$density->latest()->value; // 2466.6
$density->latest()->attributeId; // 1 = regular value
$density->lastUpdate; // CarbonImmutable, Europe/Warsaw
// Statistical localities
GusBdl::localityDataByVariable(420, '011200000000')->take(10)->all();
GusBdl::dataByUnit('011212001011-0981682', 148190); // routed to data/localities/by-unit
GusBdl::attributes(); GusBdl::attribute(4); // symbol "x": confidential or not applicable
GusBdl::measures(); GusBdl::aggregates(); GusBdl::years(); GusBdl::levels();
GusBdl::metadata('variables'); // resource metadata
GusBdl::version(); // ["id" => "1.0", ...]
GusBdl::inLanguage('en')->subject('K3')->name; // name in English
GusBdl::withClientId($tenantKey)->variable(60559); // another key at runtime
use Beziworld\GusBdl\Enums\Format;
$xml = GusBdl::raw('data/by-variable/60559', ['unit-level' => 0, 'year' => [2023]], Format::Xml);