Closed denjaland closed 6 years ago
@denjaland Hi. It's actually up to you. This is a general purpose data, you can choose your preferred format and use if the way you wish. From plain text and importing CSV into google docs to importing it in MySQL database and using with any web language/framework to wrapping XML or YAML and using with Java or PHP. This is just the data source.
Okay, but I copy those files then? It's just a respository of data you mean?
I was looking at how one can actually consume this using composer and import the data into my project without the requirement of having to copy the files... - hence my question ;-)
@denjaland If you want to use it with composer just run composer require umpirsky/country-list
, you can also install it with npm.
I think he was asking if you have to copy the files in country-list/data/ manually or are there functions you can call. I am trying to figuring this out to. The readme doesn't say anything about that. Please consider adding it to the readme on how to load/use.
+1 needs usage documentation; how do you include the PHP version into a PHP script in the proper way?
Same as any other script:
$countries = require `data/en/country.php`;
It would be better to encapsulate PHP data in classes somehow to use composer autoloader. Now you have to know exact path from your current script to vendor/umprisky/country-list/data...
With autoload you need to know exact path to vendor/autoload.php
too.
Yes, but only in single file that is run at the begining of every request in your project. With current setup, you can't have a package-submodule required to your main project through composer that uses your data, because you will have to hardcode vendor
path in that submodule.
How about creating classes like \Umpirsky\CountryList\en
that will have array with data as constant?
I will take a look at https://github.com/umpirsky/list-generator/blob/master/src/Umpirsky/ListGenerator/Exporter/Format/Php.php and try to modify it to make classes.
I am not sure if it will not be better to have all classes in single directory to have much simpler autoloader in composer.json
I'd rather add utility class that is capable of locating the resource with some trick like https://github.com/composer/composer/issues/2904#issuecomment-40298252.
Utility class gave me an idea. Wait a second.
Hi,
Thanks for this. What's the proper way to use these in any project? As it's just lists and no actual classes, I'm not entirely sure how to use them? Or am I missing something?
David.