A PHP client for the RestCountries API. This package simplifies interacting with the API by providing an object-oriented interface to retrieve country data.
- Fetch detailed information about countries.
- Support for caching to improve performance.
- Compatible with both legacy and modern PHP projects.
- PHP 7.0 or higher
Install the package via Composer:
composer require hamedhaghi/countries
require 'vendor/autoload.php';
use Hamed\Countries\Factory;
// Initialize the client
$factory = new CountryRepositoryFactory();
// Enable caching for faster responses (optional)
$factory = $factory->isCachable()
->setCacheTTL(3600); // Cache expiration time in seconds
// Initialize the repository
$repository = $factory->init();
// Query country data
$countries = $repository->getAll();
$countries = $repository->getByCapital('Berlin');
$countries = $repository->getByCode('DE');
$countries = $repository->getByCurrency('Euro');
$countries = $repository->getByDemonym('German');
$countries = $repository->getByFullName('Germany');
$countries = $repository->getByLanguage('German');
$countries = $repository->getByName('Germany');
$countries = $repository->getByRegion('Europe');
$countries = $repository->getBySubregion('Western Europe');
$countries = $repository->getByTranslation('Germany');
// Clear the cache
$factory->clearCache();
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License.