c6digital/mapit-php

Third-party PHP SDK for MapIt.

Fund package maintenance!
c6digital

v0.1.2 2024-04-30 11:41 UTC

This package is auto-updated.

Last update: 2024-12-08 13:48:06 UTC


README

Latest Version on Packagist Tests Total Downloads

This package provides a lightweight SDK to interact with MapIt APIs. It doesn't have methods for everything, only the things that we as an organisation frequently use.

Installation

You can install the package via Composer:

composer require c6digital/mapit-php

Usage

use C6Digital\MapIt\MapIt;

$mapIt = new MapIt(
    key: 'your-mapit-key-here',          // Your MapIt API key / token.
    url: 'https://mapit.mysociety.org'  // An optional MapIt URL.
);

Laravel

If you're using Laravel, this package provides a service provider that automatically registers the MapIt class and uses .env variables to configure the key and URL.

MAPIT_KEY=...
MAPIT_URL=...

You can then request it from the container when you need to use it.

use C6Digital\MapIt\MapIt;

class MyController
{
    public function __invoke(MapIt $mapIt)
    {
        // ...
    }
}

Retrieving postcodes

$mapIt->postcode('SW1P 3BD');

Throwing when errors occur

$mapIt->throw()->postcode(...);

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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