umpirsky / country-list

:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.
MIT License
5.18k stars 1.55k forks source link

Using this package in PHP/Composer #48

Closed MidnightDesign closed 8 years ago

MidnightDesign commented 8 years ago

I'm not sure how this is supposed to be used with Composer. I don't think there is a reliable way to get the location (directory) of the data.

The simplest way around this is with an auto-loaded class that can return the directory the data is located. Would you accept a PR with this addition?

Edit: See my fork.

umpirsky commented 8 years ago

@MidnightDesign Thanks for the issue.

Actually there is. Similar package umpirsky/currency-list is used in moneyphp/money.

See https://github.com/moneyphp/money/blob/master/src%2FISOCurrencies.php#L31-L46.

MidnightDesign commented 8 years ago

Do you really think this is the way to go? It seems pretty fragile to me.

@Seldaek Can you give us your Composer-opinion on this?

Seldaek commented 8 years ago

This is safe as long as there are no batshit crazy custom installers in the game that relocate packages randomly. It's a similar pattern to what we do for binaries to find the autoloader really https://github.com/Seldaek/jsonlint/blob/master/bin/jsonlint#L20 and has the same constraint (no crazy custom installers).

MidnightDesign commented 8 years ago

Thanks for your opinion!

But isn't that a little different? In the case you mentioned, you're trying to initialize the autoloader itself. When autoloading is already wired up, I don't think that's the way to do it.

Seldaek commented 8 years ago

Well.. yeah you can for sure use a class to do the resolution, I am not saying your method is wrong, but IMO both are valid workable solutions. One uses a class as indirection which adds overhead while the other potentially does useless io/filesystem stats, but it's marginal either way I think.

umpirsky commented 8 years ago

Just wanted to add that it is not a primary use case to use this package with composer. Mainly because it is not limited to PHP at all.

MidnightDesign commented 8 years ago

Yeah, I got that. That's why I chose this title for the issue. :)

umpirsky commented 8 years ago

:)