Search by

mdgascar / malagasy-address-symfony

johan-mickael

Symfony bundle: a validation constraint, a Twig filter and a Doctrine type for the codes of the regions, districts, communes and fokontany of Madagascar.

Package info

github.com/mdgascar/malagasy-address-symfony

Documentation

Type:symfony-bundle

pkg:composer/mdgascar/malagasy-address-symfony

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v0.1.0 2026-12-04 00:52 UTC

This package is auto-updated.

Last update: 2026-12-04 00:55:36 UTC


README

md.gascar

malagasy-address-symfony

A Symfony validation constraint, Twig filter and Doctrine type for the codes of the regions, districts, communes and fokontany of Madagascar, on top of mdgascar/malagasy-address. Symfony 7.4 and 8, PHP 8.3+.

Docs: mdgascar.github.io/malagasy-docs/docs/places.

composer require mdgascar/malagasy-address-symfony

Symfony Flex enables the bundle. Without Flex, add Mdgascar\MalagasyAddressBundle\MalagasyAddressBundle::class => ['all' => true] to config/bundles.php.

use Mdgascar\MalagasyAddress\Places\PlaceLevel;
use Mdgascar\MalagasyAddressBundle\Validator\MalagasyPlace;

final class Delivery
{
    #[MalagasyPlace(level: PlaceLevel::Commune)]
    public ?string $commune = null;

    #[MalagasyPlace]
    public ?string $place = null;
}

MalagasyPlace accepts the code of any level; give level to accept one, and within to accept only the places below a code (#[MalagasyPlace(level: PlaceLevel::Commune, within: 'MG11102')]). null and '' pass: add NotBlank to require a value. Messages come in English and French.

With twig/twig, the mg_place filter prints a place with its parents:

{{ user.commune|mg_place }} {# Ankadinandriana, Antananarivo Avaradrano, Analamanga #}

It takes a code or a Place, prints nothing for null, and throws for a code that is not a place.

With Doctrine, the mg_place column type stores a place as its code and reads it back as a Place with its parents:

#[ORM\Column(type: 'mg_place')]
private ?Place $commune = null;

Data and licence

The code is MIT. The place data comes from the OCHA COD-AB for Madagascar (CC BY-IGO): see the NOTICE of malagasy-address-php.

Contributing

See CONTRIBUTING.md.

License

MIT