digitalcz/register-adries

Provides communication with https://data.gov.sk/dataset/register-adries in PHP OOP via PSR-18 HTTP client


README

Latest Version on Packagist Software License CI codecov Total Downloads

Provides communication with https://data.gov.sk/dataset/register-adries in PHP OOP via PSR-18 HTTP client

Install

Via Composer

$ composer require digitalcz/register-adries

Usage

$register = new DigitalCz\RegisterAdries\RegisterAdries();
$response = $register
    ->request()             // create RequestBuilder
    ->regions()             // set resource to fetch
    ->limit(5)              // limit number of results
    ->offset(10)            // offset first result
    ->execute();            // execute the request and return response 

$response->getRecords();    // DigitalCz\RegisterAdries\Response\Region[]
$response->getTotal();      // total number of results

With conditions

$register = new DigitalCz\RegisterAdries\RegisterAdries();
$register
    ->request()                         // create RequestBuilder
    // comparison
    ->whereEq('foo', 'bar')             // `foo = bar`
    ->whereNeq('foo', 'bar')             // `foo != bar`
    ->whereGt('foo', 40)                // `foo > 40` 
    ->whereGte('foo', 40)               // `foo >= 40` 
    ->whereLt('foo', 40)                // `foo < 40` 
    ->whereLte('foo', 40)               // `foo <= 40` 
    // like
    ->whereLike('foo', 'bar')           // `foo LIKE bar`
    ->whereStartsWith('foo', 'bar')     // `foo LIKE bar%`
    ->whereEndsWith('foo', 'bar')       // `foo LIKE %bar`
    ->whereContains('foo', 'bar')        // `foo LIKE %bar%`
    // helpers
    ->whereObjectId(12)                 // `objectId = 12`
    ->onlyValid();                      // `WHERE {now} > validFrom AND {now} < validTo`

Requesting by objectId

$register = new DigitalCz\RegisterAdries\RegisterAdries();
$register->findRegion(9);           // returns DigitalCz\RegisterAdries\Response\Region or null
$register->findCounty(9);           // returns DigitalCz\RegisterAdries\Response\County or null
$register->findMunicipality(9);     // returns DigitalCz\RegisterAdries\Response\Municipality or null
$register->findDistrict(9);         // returns DigitalCz\RegisterAdries\Response\District or null
$register->findStreet(9);           // returns DigitalCz\RegisterAdries\Response\Street or null
$register->findUnit(9);             // returns DigitalCz\RegisterAdries\Response\Unit or null
$register->findBuilding(9);         // returns DigitalCz\RegisterAdries\Response\Building or null
$register->findEntrance(9);         // returns DigitalCz\RegisterAdries\Response\Entrance or null

Available resources

Available on builder as

$register = new DigitalCz\RegisterAdries\RegisterAdries();
$register 
    ->request()
    // ...
    ->resource('region')
    ->resource(DigitalCz\RegisterAdries\RegisterResource::REGION)
    ->regions()
    // ...
    ->counties()
    ->municipalities()
    ->districts()
    ->streets()
    ->units()
    ->buildings()
    ->entrances();
// It isn't possible to request more resources, this is just example

Using your own http client

You can provide PSR18 http client (and PSR17 factories) when creating instance of RegisterAdries, if no arguments are provided Psr18ClientDiscovery and Psr17FactoryDiscovery will be used (see https://php-http.readthedocs.io/en/latest/discovery.html).

// example
$symfonyHttpClient = Symfony\Component\HttpClient\Psr18Client();

$register = new DigitalCz\RegisterAdries\RegisterAdries(
    $symfonyHttpClient, 
    $symfonyHttpClient   // symfony PSR18 client is also PSR17 factory
);

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer checks   # codesniffer + phpstan + phpunit
$ composer csfix    # code beautifier

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email devs@digital.cz instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.