Download the PHP package hsalem7/countries without Composer
On this page you can find all versions of the php package hsalem7/countries. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package countries
Countries. This is a fork of the original package by pragmarx. But this is fixed to work with Laravel 10 until the owner of the original package fixes it.
What does it gives you?
This package has all sorts of information about countries:
info | items |
---|---|
taxes | 32 |
geometry maps | 248 |
topology maps | 248 |
currencies | 256 |
countries | 266 |
timezones | 423 |
borders | 649 |
flags | 1,570 |
states | 4,526 |
cities | 7,376 |
timezones times | 81,153 |
Geology and topology maps
Amongst many other information you'll be able to plot country maps:
Requirements
- PHP 7.0+
Installing
Use Composer to install it:
Instantiating
Should both return
Overloading the default configuration:
#
Usage
This package is not tied to Laravel and doesn't require it to be installed (we have a bridge for this purpose), but it has Laravel Collections in its core, all methods in Collections are available, this way you can do things like filter, map, reduce, search, sort, reject, and a lot more. It, actually, uses Coollection, which is Laravel Collections with a fluent syntax, allowing us to have access to array keys (and values) as object properties.
To get all countries in the data base you just have to:
To get a json you:
Filter by keys and values:
Will find Brazil by its common name, which is a
Or alternatively you can filter like this
And, you can go deepeer
Or search by the country top level domain
To get
And use things like pluck
To get
The package uses a modified Collection which allows you to access properties and methods as objects:
Should give
Borders hydration is disabled by default, but you can have your borders hydrated easily by calling the hydrate method:
Should return
`
Hydration
To improve performance, hydration, which is enabled by default, can be disable on most country properties, and this is how you manually hydrate properties:
Those are some of the hydratable properties:
- Borders
- Cities
- Currencies
- Flag
- Geometry
- Languages
- States
- Taxes
- Timezone
- Topology
Extra where rules
Some properties are stored differently and we therefore need special rules for accessing them, these properties are
ISO639_3
=> The 3 letter language code.ISO4217
=> The 3 letter currency code.
You can of course access them like other properties
Mapping
Sometimes you would like to access a property by a different name, this can be done in settings, this way
Here we bind the language 3 letter short code ISO format to lca3
, which is short for language code alpha 3-letter
.
So now we can access the property by
Or
Some other examples from Laravel News and some other contributors
Generate a list of all countries with code, using native name and common
Should give you 267 (or so) countries like:
Generate a list of countries
returns
Generate a list of currencies
returns
Get the currency symbol
Generate a list of States
returns
Hydrate and get a cities
Should return
Get a countries currencies
returns
Get all currencies
returns
Get the timezone for a State
returns
Get all timezones for a country
Get all times for a timezone
returns
Flags
Countries provides many different flag sources, including SVG flags. This is how you use one of the available sources:
Install flag-icon
Import it to your project
Use Countries to get the flag span
Render it in your blade template
Publishing assets
You can publish configuration by doing:
Data
Sources
This package uses some other open source packages and, until we don't build a better documentation, you can find some more info about data on mledoze/countries and how to use it on this fantastic Laravel News article.
Please check the copyright section for a complete list of packages used by this one.
Updating
WARNING
No data files (JSON, images, icons...) on this project can be updated manually. We will close all pull requests requiring manual updates to those files will be closed, because the update script will delete them anyway.
If you find something wrong with data, you, please, have to ask the package managers (listed data sources and on the copyright section) to fix them, and then you can yourself run the update script to properly update them on this repository.
update.php
This package comes with the update.php
script, which you MUST use to update the data files. It will download all info from all packages and automatically build the .json
(and some others like .svg
too). This is how you do it:
And wait for a *very long time** (sometimes it looks like stuck but it's not) until it finishes rebuilding everything, then it's just a matter of staging, commit, push all regenerated files, and draft a new PR.
Cache
Since this data is not supposed to change, calls are automatically cached.
If you want to change this behaviour, you can edit config/countries.php
file once it's published.
Framework bridges
Sample files
- sample-partial.json: example of a country with no borders hydrated.
- sample-full.json: example of a fully hydrated country.
Author
Antonio Carlos Ribeiro All contributors
Copyright
To build the countries database and relations, this package make use of those sources and packages:
- mledoze/countries
- Natural Earth Vector
- rinvex/country
- commerceguys/tax
- timezonedb
- wiredmax/world-currencies
License
Countries is licensed under the BSD 3-Clause License - see the LICENSE
file for details
Contributing
Pull requests and issues are more than welcome.
All versions of countries with dependencies
pragmarx/coollection Version >=0.8
psr/simple-cache Version ^3.0
nette/caching Version ^2.5|^3.0
colinodell/json5 Version ^1.0|^2.0
nette/utils Version ^4.0
nette/robot-loader Version ^4.0