Skip to content

Commit 666efec

Browse files
author
pulkit
committed
added all functionality testing required & updated to driver based
1 parent 17e0624 commit 666efec

File tree

12 files changed

+278
-5
lines changed

12 files changed

+278
-5
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
/bootstrap/compiled.php
2-
.env.*.php
3-
.env.php
1+
/vendor
2+
composer.lock
3+
.DS_Store
4+
/build

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: php
2+
3+
php:
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- hhvm
8+
9+
before_script:
10+
- travis_retry composer self-update
11+
- travis_retry composer install --no-interaction --prefer-source --dev
12+
13+
script:
14+
- phpunit --coverage-text --coverage-clover=coverage.clover
15+
16+
after_script:
17+
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi;'
18+
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi;'

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
laravel-geoip
1+
GeoIP
22
=============
33

4-
(WIP) Geoip for Laravel
4+
> GeoIP Wrapper
5+
6+
[![Build Status](http://img.shields.io/travis/pulkitjalan/geoip.svg?style=flat-square)](https://travis-ci.org/pulkitjalan/geoip)
7+
[![Scrutinizer Code Quality](http://img.shields.io/scrutinizer/g/pulkitjalan/geoip/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/pulkitjalan/geoip/)
8+
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/pulkitjalan/geoip/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/pulkitjalan/geoip/code-structure/master)
9+
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://www.opensource.org/licenses/MIT)
10+
[![Latest Version](http://img.shields.io/packagist/v/pulkitjalan/geoip.svg?style=flat-square)](https://packagist.org/packages/pulkitjalan/geoip)
11+
[![Total Downloads](https://img.shields.io/packagist/dt/pulkitjalan/geoip.svg?style=flat-square)](https://packagist.org/packages/pulkitjalan/geoip)
12+
13+
This package requires PHP >=5.4

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "pulkitjalan/geoip",
3+
"description": "Geoip wrapper",
4+
"homepage": "https://github.com/pulkitjalan/geoip",
5+
"keywords": ["geoip"],
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Pulkit Jalan"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.4.0",
14+
"illuminate/support": "~4|~5",
15+
"geoip2/geoip2": "2.*"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "4.*",
19+
"mockery/mockery": "0.9.*"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"PulkitJalan\\GeoIP\\": "src"
24+
}
25+
},
26+
"minimum-stability": "stable"
27+
}

phpunit.xml.dist

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="GeoIP Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
<exclude>
21+
<file>src/GeoIPServiceProvider.php</file>
22+
<directory suffix=".php">src/config/</directory>
23+
<directory suffix=".php">src/Facades/</directory>
24+
</exclude>
25+
</whitelist>
26+
</filter>
27+
<logging>
28+
<log type="tap" target="build/report.tap"/>
29+
<log type="junit" target="build/report.junit.xml"/>
30+
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
31+
<log type="coverage-text" target="build/coverage.txt"/>
32+
<log type="coverage-clover" target="build/logs/clover.xml"/>
33+
</logging>
34+
</phpunit>

scrutinizer.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
checks:
4+
php:
5+
code_rating: true
6+
remove_extra_empty_lines: true
7+
remove_php_closing_tag: true
8+
remove_trailing_whitespace: true
9+
fix_use_statements:
10+
remove_unused: true
11+
preserve_multiple: false
12+
preserve_blanklines: true
13+
order_alphabetically: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true
19+
tools:
20+
external_code_coverage:
21+
timeout: 1800
22+
runs: 3
23+
php_code_coverage: false
24+
php_code_sniffer:
25+
config:
26+
standard: PSR2
27+
filter:
28+
paths: ['src']
29+
php_loc:
30+
enabled: true
31+
excluded_dirs: [vendor, tests]
32+
php_cpd:
33+
enabled: true
34+
excluded_dirs: [vendor, tests]

src/GeoIP.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace PulkitJalan\GeoIP;
4+
5+
class GeoIP
6+
{
7+
/**
8+
* @var string
9+
*/
10+
protected $ip;
11+
12+
/**
13+
* Set ip
14+
*
15+
* @return PulkitJalan\GeoIP\GeoIP
16+
*/
17+
public function setIP($ip)
18+
{
19+
$this->ip = $ip;
20+
21+
return $this;
22+
}
23+
24+
/**
25+
* Get ip from server info
26+
*
27+
* @return string ipaddress
28+
*/
29+
public function getIP()
30+
{
31+
return ($this->ip) ?: array_get($_SERVER, 'HTTP_CLIENT_IP', array_get($_SERVER, 'HTTP_X_FORWARDED_FOR', array_get($_SERVER, 'HTTP_X_FORWARDED', array_get($_SERVER, 'HTTP_FORWARDED_FOR', array_get($_SERVER, 'HTTP_FORWARDED', array_get($_SERVER, 'REMOTE_ADDR', '127.0.0.1'))))));
32+
}
33+
}

src/Laravel/Facades/GeoIP.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace PulkitJalan\GeoIP\Laravel\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class GeoIP extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor()
15+
{
16+
return 'geoip';
17+
}
18+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace PulkitJalan\GeoIP\Laravel;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class GeoIPServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Indicates if loading of the provider is deferred.
11+
*
12+
* @var bool
13+
*/
14+
protected $defer = false;
15+
16+
/**
17+
* Boot the service provider.
18+
*/
19+
public function boot()
20+
{
21+
$this->app['PulkitJalan\GeoIP\GeoIP'] = function ($app) {
22+
return $app['geoip'];
23+
};
24+
}
25+
26+
/**
27+
* Register the service provider.
28+
*
29+
* @return void
30+
*/
31+
public function register()
32+
{
33+
$this->app->config->package('pulkitjalan/geoip', realpath(__DIR__.'/config'), 'geoip');
34+
35+
$this->app['geoip'] = $this->app->share(function ($app) {
36+
return new GeoIP($app->config->get('geoip::database'));
37+
});
38+
}
39+
40+
/**
41+
* Get the services provided by the provider.
42+
*
43+
* @return string[]
44+
*/
45+
public function provides()
46+
{
47+
return ['geoip', 'PulkitJalan\GeoIP\GeoIP'];
48+
}
49+
}

src/Laravel/config/config.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| GeoIP Driver
8+
|--------------------------------------------------------------------------
9+
|
10+
| Supported: "maxmind", "ip-api"
11+
|
12+
*/
13+
'driver' => 'maxmind',
14+
15+
'maxmind' => [
16+
17+
'type' => 'database'
18+
19+
/*
20+
|--------------------------------------------------------------------------
21+
| Maxmind database
22+
|--------------------------------------------------------------------------
23+
*/
24+
'database' => app_path().'/database/maxmind/GeoLite2-City.mmdb',
25+
26+
'user_id' => '',
27+
'license_key' => ''
28+
],
29+
];

0 commit comments

Comments
 (0)