eseath / sypexgeo
A PHP package for working with the SypexGeo database file.
Installs: 110 859
Dependents: 1
Suggesters: 0
Security: 0
Stars: 14
Watchers: 3
Forks: 6
Open Issues: 1
Requires
- php: ^7.0|^8.0
- ext-curl: *
- ext-zip: *
- guzzlehttp/guzzle: ^6.0|^7.0
Requires (Dev)
- orchestra/testbench: ^3.6
- phpunit/phpunit: ^6.5|^7.5|^8.5|^9.5
README
A PHP package for working with the SypexGeo database file.
The current version supports Laravel 5.1 and later.
Installation
composer require eseath/sypexgeo
For non-Laravel projects, you need to manually download the database file:
The database is updated 2 times a month.
Setup
Laravel
1. If Laravel version <= 5.4, add into config/app.php
:
'providers' => [ \Eseath\SxGeo\SxGeoServiceProvider::class, ]
2. Publish config sxgeo.php
(optionally):
php artisan vendor:publish --provider="Eseath\SxGeo\SxGeoServiceProvider"
By default, in config specified URL to the database of cities. If you want the database of countries, change url:
...
'dbFileURL' => 'https://sypexgeo.net/files/SxGeoCountry.zip',
...
3. Download the database file:
php artisan sxgeo:update
You can use this command to upgrade database to the current version via CRON.
Usage
use Eseath\SxGeo\SxGeo; $sxGeo = new SxGeo('/path/to/database/file.dat'); $fullInfo = $sxGeo->getCityFull($ip); $briefInfo = $sxGeo->get($ip);
With Laravel
use SxGeo; $data = SxGeo::getCityFull($ip);
Example Data
array:3 [▼
"city" => array:5 [▼
"id" => 524901
"lat" => 55.75222
"lon" => 37.61556
"name_ru" => "Москва"
"name_en" => "Moscow"
]
"region" => array:4 [▼
"id" => 524894
"name_ru" => "Москва"
"name_en" => "Moskva"
"iso" => "RU-MOW"
]
"country" => array:6 [▼
"id" => 185
"iso" => "RU"
"lat" => 60
"lon" => 100
"name_ru" => "Россия"
"name_en" => "Russia"
]
]
array:2 [▼
"city" => array:5 [▼
"id" => 524901
"lat" => 55.75222
"lon" => 37.61556
"name_ru" => "Москва"
"name_en" => "Moscow"
]
"country" => array:2 [▼
"id" => 185
"iso" => "RU"
]
]
Running Tests
The tests are run automatically by Travis CI on multiple PHP and Laravel versions.
If you want to run tests locally, use the following command:
python3 ./test.py
Development
docker-compose run php-7.1 composer install