mdgascar / malagasy-address-symfony
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
Type:symfony-bundle
pkg:composer/mdgascar/malagasy-address-symfony
Requires
- php: >=8.3
- mdgascar/malagasy-address: ^0.1
- symfony/dependency-injection: ^7.4 || ^8.0
- symfony/http-kernel: ^7.4 || ^8.0
Requires (Dev)
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13 || ^3.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpstan/phpstan-strict-rules: ^2.1
- phpunit/phpunit: ^12.5 || ^13.4
- povils/phpmnd: ^3.6
- symfony/config: ^7.4 || ^8.0
- symfony/filesystem: ^7.4 || ^8.0
- symfony/framework-bundle: ^7.4 || ^8.0
- symfony/translation: ^7.4 || ^8.0
- symfony/twig-bundle: ^7.4 || ^8.0
- symfony/validator: ^7.4 || ^8.0
- twig/twig: ^3.15
Suggests
- doctrine/doctrine-bundle: For the mg_place Doctrine type (doctrine/dbal 4)
- symfony/validator: For the MalagasyPlace constraint
- twig/twig: For the mg_place filter
Provides
None
Conflicts
- doctrine/dbal: <4.0
Replaces
None
README
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.
