PrinsFrank / standards

A collection of standards as PHP Enums: ISO3166, ISO4217, ISO639...
MIT License
375 stars 10 forks source link

Add ISO_3166-2 to support country sub-divisions #228

Closed robinc-e closed 3 weeks ago

robinc-e commented 1 month ago

Problem

My org needs more localised areas than countries and would like to use this library.

Solution Add ISO_3166-2 to this project to include country subdivisions.

PrinsFrank commented 1 month ago

Hi @robinc-e, thanks for reaching out! I think this should be possible and quite doable. I am travelling the next few weeks but I might have some time to implement this!

What use case do you have for this? Because the specs are quite large and diverse, I am thinking of splitting it up into multiple classes. I don't know if it would be better to have one enum: src/country/SubDivision.php

One enum per country: src/Country/Subdivsion/Netherlands/Country.php

Or one enum per subdivision type per country: src/Country/Subdivsion/Netherlands/Country.php src/Country/Subdivsion/Netherlands/Provice.php src/Country/Subdivsion/Netherlands/SpecialMunicipality.php

What do you think makes sense? And would you have any use at all in knowing the country a region belongs to?

robinc-e commented 1 month ago

For our use case one enum per country would be the most useful, but I can see use cases other people might have for the distinction.

Can your system handle both?

Also should it be County.php or Country.php?

robinc-e commented 3 weeks ago

thanks a million!

PrinsFrank commented 3 weeks ago

There is more functionality coming to get more information about the subdivisions and to add a relation between countries and subdivisions, so this shouldn't have been closed. I'll keep you updated!

PrinsFrank commented 3 weeks ago

@robinc-e I was looking into creating a seperate enum per country/type etc, but that resulted in a lot of classes, which as a consequence then resulted in issues when determining what enum a string belonged to when converting strings to enum cases, so I decided on file instead. What do you think?

I've added some relationships between the countries, their subdivisions, and also some countries have subcountries which are also available right now. Would this work for your use case? I'm writing some documentation and will then create a release with these changes. Do you see any use for subdivision types? Those are currently not implemented. Let me know if you're missing functionality!

PrinsFrank commented 3 weeks ago

This has just been released in https://github.com/PrinsFrank/standards/releases/tag/v3.9.0!