Rinvex Country

repository·master·Indexed 23 days ago

https://github.com/rinvex/countries

A lightweight, framework-agnostic PHP package for retrieving comprehensive country data. It provides access to ISO codes, geographic information, currencies, and metadata via helper functions and the CountryLoader class. Requires PHP ^8.1.

Tokens
968
Snippets
3
Records
7
Agent score
33%

What's inside rinvex/countries

  1. Understand the country data structure

    master

    The country data is stored in resources/data/countries.json and contains a rich set of attributes for each country. Key data groups include:

    • Names: name contains common, official, and native names (where native is keyed by ISO 639-3 language codes).
    • Codes: ISO 3166-1 alpha2, alpha3, and numeric codes.
    • Currency: currency provides ISO 4217 details (code, numeric, name, and minor unit) keyed by the three-letter currency code.
    • Geography (geo): Includes continent (keyed by two-letter code), postal_code usage, coordinates (latitude, longitude), area, region, subregion, landlocked status, and borders.
    • Dialling: dialling includes calling_code, national_prefix, and various length specifications for national and international numbers.
    • Languages: languages is a list of official languages keyed by ISO 639-3 code.
    • Translations: translations provides name translations keyed by ISO 639-3 code.
    • Extra Metadata: The extra object contains various international identifiers such as geonameid, fifa, fips, ioc, eu_member, and emoji (flag emoji).
  2. Upgrade instructions for Rinvex Country

    master

    Depending on your current version, follow these steps to upgrade:

    Upgrading to v3.x from v2.x

    • There are no major breaking changes; the API is 100% backward compatible.
    • Requirement: PHP v7.0 is now the minimum requirement.

    Upgrading to v2.x from v1.x

    • The package was completely rewritten. You should replace your existing implementation with the new API.
  3. Install Rinvex Country via Composer

    master

    Install the package using Composer to retrieve country details like names, ISO codes, currencies, and geo data.

    Requirements:

    • PHP ^8.1
    • Framework-agnostic (works with any PHP framework)
    composer require rinvex/countries
  4. Retrieve a single country by code

    master

    Use the country() helper function to retrieve a country object by its ISO alpha-2 code (e.g., 'eg' for Egypt). The returned object contains full country details.

    // Get single country
    $egypt = country('eg');
    
    // Get country name
    echo $egypt->getName();
    
    // Get country ISO 3166-1 alpha2 code
    echo $egypt->getIsoAlpha2();
  5. Retrieve all countries or filtered lists

    master

    Use the countries() helper to get a list of all countries. For better performance, this returns a short-listed result set with common details.

    To filter countries, use \Rinvex\Country\CountryLoader::where() with a key-value pair representing the attribute and the desired value (e.g., filtering by continent).

    // Get all countries
    $countries = countries();
    
    // Get countries with where condition (continent: Oceania)
    $whereCountries = \Rinvex\Country\CountryLoader::where('geo.continent', ['OC' => 'Oceania']);
  6. Access country attributes and metadata

    master

    The country object provides a wide range of self-descriptive methods to access specific attributes.

    Commonly used methods include:

    • Names: getName(), getNativeName(), getOfficialName(), getDemonym()
    • Codes: getIsoAlpha2(), getIsoAlpha3(), getIsoNumeric(), getTld()
    • Geography: getContinent(), getRegion(), getArea(), getLatitude(), getLongitude(), getBorders()
    • Communication: getCallingCode(), getInternationalPrefix(), getNationalPrefix()
    • Data Formats: getGeoJson(), getFlag() (SVG), getEmoji(), getCurrencies()
    • Identifiers: getGeonameid(), getFifa(), getIoc(), getFips()