serendipity_hq/component-geo-builder

Parses the exports of countries from Geonames and exports the data in machine readable formats.

0.3.0 2022-01-08 12:06 UTC

This package is auto-updated.

Last update: 2024-04-22 08:50:29 UTC


README

687474703a2f2f7777772e736572656e64697069747968712e636f6d2f6173736574732f6f70656e2d736f757263652d70726f6a656374732f4c6f676f2d536572656e64697069747948512d49636f6e2d546578742d507572706c652e706e67

Serendipity HQ Geo Builder

Parses the exports of countries from Geonames and exports the data in machine readable formats.
It downloads information of countries from [Geonames exports](https://www.geonames.org/export/zip/).
Ready to be integrated in Symfony apps.

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736572656e6469706974795f68712f636f6d706f6e656e742d67656f2d6275696c6465722e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736572656e6469706974795f68712f636f6d706f6e656e742d67656f2d6275696c6465723f636f6c6f723d253233383839324246267374796c653d666c61742d737175617265266c6f676f3d706870

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53756767657374732d73796d666f6e792f666f726d2d2532333838393242463f7374796c653d666c61742d737175617265266c6f676f3d706870

Supports
68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545342e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545352e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545362e302d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79

Tested on
68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545342e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545352e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545362e302d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79

Current Status

Coverage Maintainability Rating Quality Gate Status Reliability Rating Security Rating Technical Debt Vulnerabilities

Phan PHPStan PSalm PHPUnit Composer PHP CS Fixer Rector

Features

  • Download the exports of countries
  • Build you custom lists of countries to use in your app

Do you like this library?
LEAVE A ★

or run
composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!

Installation and Configuration

Install Component GeoBuilder via Composer

composer req serendipity_hq/component-geo-builder

This library follows the http://semver.org/ versioning conventions.

However, until the version 1, the minor release is treated like a major one.

So it is possible a break in the public API between minor versions (0.1 > 0.2 > 0.3).).

The component is anyway stable and can be used in production, also if it is not very flexible.

See the issues to know more about what we have in mind to implement.

Register the command in a Symfony application

Open the file config/services.yaml and add the class of the geobuilder command:

# config/services.yaml

services:
    ...
    SerendipityHQ\Component\GeoBuilder\Command\BuildCommand:
        $dumpDir: '%kernel.cache_dir%/geobuilder'

    # You also need to autowire the Guzzle CLient if you don't already have one
    GuzzleHttp\Client: ~
    ...

Building the list you need

To build the list you need, simply launch the command geobuilder:build appending the countries you want to build lists for:

$ bin/console geobuilder:build it de

By default the command uses the Hierarchy reader and will create a lot of json files in the kernel.cache_dir/geobuilder folder of your Symfony App.

You can read more about readers, saving folders and more reading the full documentation.

For the moment, let's continue putting GeoBuilder at work.

The next step is to create a form with the data we have just built.

Creating the form

To use the form types, you need to register them as services, so they can be properly initialized by Symfony.

To register them, open the file config/services.yaml and add the HierarchyJsonType:

# config/services.yaml

services:
    ...
    SerendipityHQ\Component\GeoBuilder\Reader\HierarchyJsonReader:
        $dataFolderPath: '%kernel.cache_dir%/geobuilder'
    SerendipityHQ\Component\GeoBuilder\Bridge\Symfony\Form\Type\HierarchyJsonType: ~

Then in your form you can add the HierarchyJsonType:

class UserZoneType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array<string,mixed>  $options
     * @suppress PhanUnusedPublicMethodParameter
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('geobuilder', HierarchyJsonType::class, ['country' => 'it']);
    }
}

About the countries.json file

This file will contain only the countries you built with the bin/console geobuilder:build command.

You can get a complete list of localized countries using the Countries::getNames() method of the symfony/intl component.

But the Symfony component will return all countries in the world, also if you didn't built them.

Do you like this library?
LEAVE A ★

or run
composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!