Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: php-actions/composer@v6
- uses: php-actions/phpunit@v4
with:
test_suffix: Test.php
bootstrap: vendor/autoload.php
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
.idea*
.phpunit*
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ A lightweight PHP package that resolves an IANA timezone identifier from address

## Requirements

- PHP 8.4+
- PHP 8.2+
- A free [GeoNames account](https://www.geonames.org/login) with the web services enabled

To update dependencies on a system without PHP 8 use:
```shell
docker run --rm --mount type=bind,source="$(pwd)",target=/app composer:2 composer update
```

## Installation

```bash
Expand All @@ -16,9 +21,9 @@ composer require myparcelcom/timezone-resolver
## Usage

```php
use MyParcelCom\TimezoneResolver\GeoNames;
use MyParcelCom\TimezoneResolver\TimezoneResolver;

$resolver = new GeoNames(username: 'your-geonames-username');
$resolver = new TimezoneResolver(username: 'your-geonames-username');

$timezone = $resolver->getTimezone(
countryCode: 'NL',
Expand Down Expand Up @@ -63,27 +68,18 @@ class MyService
The GeoNames username is passed directly to the constructor. In a Laravel application, bind the interface in a service provider:

```php
use MyParcelCom\TimezoneResolver\GeoNames;
use MyParcelCom\TimezoneResolver\TimezoneResolver;
use MyParcelCom\TimezoneResolver\TimezoneResolverInterface;

$this->app->bind(
$this->app->singleton(
TimezoneResolverInterface::class,
fn () => new GeoNames(config('services.geonames.username')),
fn () => new TimezoneResolver('my-geonames-username'),
);
```

```php
// config/services.php
'geonames' => [
'username' => env('GEONAMES_USERNAME'),
],
```

## Testing

```bash
composer install
vendor/bin/phpunit
docker run -v $(pwd):/app --rm -w /app php:8.4-cli vendor/bin/phpunit
```

## License
Expand Down
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "myparcelcom/timezone-resolver",
"description": "Resolves a local timezone from address data using the GeoNames API.",
"type": "library",
"license": "proprietary",
"require": {
"php": ">=8.2",
"guzzlehttp/guzzle": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^13.0",
"myparcelcom/guzzle-mock": "v1.0.1"
},
"autoload": {
"psr-4": {
"MyParcelCom\\TimezoneResolver\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"MyParcelCom\\TimezoneResolver\\Tests\\": "tests/"
}
},
"config": {
"optimize-autoloader": true,
"sort-packages": true
}
}
Loading