everypolitician-popolo for PHP
![Software License][ico-license]
![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
This is a port of the Python package everypolitician-popolo-python to PHP, which itself is a port of the Ruby gem everypolitician-popolo to Python., (*2)
Install
Via Composer, (*3)
``` bash
$ composer require andylolz/everypolitician-popolo, (*4)
## Usage
You can download a Popolo file manually from [EveryPolitician](http://everypolitician.org/).
The following example uses [Ă
land Lagting](https://github.com/everypolitician/everypolitician-data/raw/master/data/Aland/Lagting/ep-popolo-v1.0.json)
(which is the legislature of the Ă
land islands, available as
JSON data from the [EveryPolitician page for Ă
land](http://everypolitician.org/aland/)).
First you'll need to require the library and read in a file from disk.
``` php
use \EveryPolitician\EveryPoliticianPopolo\Popolo;
$popolo = Popolo::fromFilename('ep-popolo-v1.0.json');
All Popolo classes used by EveryPolitician are implemented:, (*5)
There are methods defined for each property on a class, e.g. for a
Person:, (*6)
``` php
count($popolo->persons); // 60
$person = $popolo->persons->first;
echo $person->id; // e3aab23e-a883-4763-be0d-92e5936024e2
echo $person->name; // Aaltonen Carina
echo $person->image; // http://www.lagtinget.ax/files/aaltonen_carina.jpg
echo $person->wikidata; // Q4934081, (*7)
You can also find individual records or collections based on their
attributes:
``` php
echo $popolo->persons->get(["name" => "Aaltonen Carina"]); // <Person: Aaltonen Carina>
$organizations = $popolo->organizations->filter(["classification" => "party"]);
foreach ($organizations as $organization) {
echo $organization;
}
// <Organization: Liberalerna>
// <Organization: Liberalerna pĂ„ Ă
land r.f.>
// <Organization: Moderat Samling>
// <Organization: Moderat Samling pĂ„ Ă
land r.f.>
// <Organization: Moderat samling>
// <Organization: Moderaterna pĂ„ Ă
land>
// <Organization: Obunden Samling>
// <Organization: Obunden Samling pĂ„ Ă
land>
// <Organization: Ă
lands Framtid>
// <Organization: Ă
lands Socialdemokrater>
// <Organization: Ă
lands framtid>
// <Organization: Ă
lands socialdemokrater>
// <Organization: Ă
lÀndsk Center>
// <Organization: Ă
lÀndsk Center r.f.>
// <Organization: Ă
lÀndsk Demokrati>
// <Organization: Ă
lÀndsk center>
Change log
Please see CHANGELOG for information on what has changed recently., (*8)
Testing
bash
$ composer test
, (*9)
Contributing
Please see CONTRIBUTING and CONDUCT for details., (*10)
Credits
License
The MIT License (MIT). Please see License File for more information., (*11)