hamedhaghi / countries
A PHP client for the RestCountries API
1.0.8
2024-12-21 15:21 UTC
Requires
- php: ^8.3
- guzzlehttp/guzzle: ^7.0
- symfony/cache: ^6.3
- symfony/property-access: ^6.3
- symfony/serializer: ^6.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0
README
A PHP client for the RestCountries API. This package simplifies interacting with the API by providing an object-oriented interface to retrieve country data.
Features
- Fetch detailed information about countries.
- Support for caching to improve performance.
- Compatible with both legacy and modern PHP projects.
Requirements
- PHP 7.0 or higher
Installation
Install the package via Composer:
composer require hamedhaghi/countries
Usage Example
require_once 'vendor/autoload.php'; use Hamed\Countries\Factory\CountryRepositoryFactory; // 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();
Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
License
This project is licensed under the MIT License.