Skip to content

Commit cd30931

Browse files
committed
formating and updated service provider to match laravel documentation
1 parent ea8b9de commit cd30931

File tree

11 files changed

+45
-46
lines changed

11 files changed

+45
-46
lines changed

src/Console/UpdateCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ public function __construct(array $config)
4040

4141
/**
4242
* Execute the console command.
43-
*
44-
* @return void
4543
*/
4644
public function fire()
4745
{
4846
$result = $this->geoIPUpdater->update();
4947

50-
if (! $result) {
48+
if (!$result) {
5149
$this->error('Update failed!');
5250

5351
return;

src/Drivers/AbstractGeoIPDriver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ abstract public function get($ip);
3737

3838
/**
3939
* Get the raw GeoIP info from the driver.
40-
*
41-
* @param string $ip
42-
*
40+
*
41+
* @param string $ip
42+
*
4343
* @return mixed
4444
*/
4545
abstract public function getRaw($ip);
4646

4747
/**
48-
* Get the default values (all null)
49-
*
48+
* Get the default values (all null).
49+
*
5050
* @return array
5151
*/
5252
protected function getDefault()

src/Drivers/FreeGeoIPDriver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public function get($ip)
3434

3535
/**
3636
* Get the raw GeoIP info using freegeoip.
37-
*
38-
* @param string $ip
39-
*
37+
*
38+
* @param string $ip
39+
*
4040
* @return array
4141
*/
4242
public function getRaw($ip)
@@ -45,7 +45,7 @@ public function getRaw($ip)
4545
}
4646

4747
/**
48-
* Get the freegeoip url
48+
* Get the freegeoip url.
4949
*
5050
* @param string $ip
5151
*

src/Drivers/IPApiDriver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public function get($ip)
3434

3535
/**
3636
* Get the raw GeoIP info using ip-api.
37-
*
38-
* @param string $ip
39-
*
37+
*
38+
* @param string $ip
39+
*
4040
* @return array
4141
*/
4242
public function getRaw($ip)

src/Drivers/MaxmindDriver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public function get($ip)
5555

5656
/**
5757
* Get the raw GeoIP info using Maxmind.
58-
*
59-
* @param string $ip
60-
*
58+
*
59+
* @param string $ip
60+
*
6161
* @return mixed
6262
*/
6363
public function getRaw($ip)
@@ -106,7 +106,7 @@ protected function createWebClient()
106106
$licenseKey = array_get($this->config, 'license_key', false);
107107

108108
// check and make sure they are set
109-
if (! $userId || ! $licenseKey) {
109+
if (!$userId || !$licenseKey) {
110110
throw new InvalidCredentialsException();
111111
}
112112

@@ -125,7 +125,7 @@ protected function createDatabase()
125125
$database = array_get($this->config, 'database', false);
126126

127127
// check if file exists first
128-
if (! $database || ! file_exists($database)) {
128+
if (!$database || !file_exists($database)) {
129129
throw new InvalidCredentialsException();
130130
}
131131

src/Drivers/TelizeDriver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function __construct(array $config)
1414
{
1515
parent::__construct($config);
1616

17-
if (! array_get($this->config, 'key')) {
17+
if (!array_get($this->config, 'key')) {
1818
throw new InvalidCredentialsException();
1919
}
2020
}
@@ -49,9 +49,9 @@ public function get($ip)
4949

5050
/**
5151
* Get the raw GeoIP info using telize.
52-
*
53-
* @param string $ip
54-
*
52+
*
53+
* @param string $ip
54+
*
5555
* @return array
5656
*/
5757
public function getRaw($ip)

src/GeoIP.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function getDriver()
5656
* @var string
5757
*
5858
* @param string $ip
59+
*
5960
* @return GeoIP
6061
*/
6162
public function setIp($ip)
@@ -72,7 +73,7 @@ public function setIp($ip)
7273
*/
7374
public function getIp()
7475
{
75-
if (! $this->ip) {
76+
if (!$this->ip) {
7677
if ($this->random) {
7778
$this->ip = long2ip(mt_rand());
7879
} else {
@@ -100,7 +101,7 @@ public function get($property = '')
100101
{
101102
$data = $this->getData();
102103

103-
if (! $property) {
104+
if (!$property) {
104105
return $data;
105106
}
106107

@@ -122,7 +123,7 @@ public function getRaw()
122123
// check ip in memory
123124
$data = array_get($this->storeRaw, $ip);
124125

125-
if (! $data) {
126+
if (!$data) {
126127
try {
127128
$data = $this->getDriver()->getRaw($ip);
128129
} catch (\Exception $e) {
@@ -151,7 +152,7 @@ protected function getData()
151152
// check ip in memory
152153
$data = array_get($this->store, $ip);
153154

154-
if (! $data) {
155+
if (!$data) {
155156
try {
156157
$data = $this->getDriver()->get($ip);
157158
} catch (\Exception $e) {

src/GeoIPManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getDriver($driver = null)
3434

3535
$method = 'create'.ucfirst(camel_case($driver)).'Driver';
3636

37-
if (! method_exists($this, $method)) {
37+
if (!method_exists($this, $method)) {
3838
throw new InvalidDriverException(sprintf('Driver [%s] not supported.', $driver));
3939
}
4040

src/GeoIPServiceProvider.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ class GeoIPServiceProvider extends ServiceProvider
1919
*/
2020
public function boot()
2121
{
22-
$this->app['PulkitJalan\GeoIP\GeoIP'] = function ($app) {
23-
return $app['geoip'];
22+
$this->app['geoip'] = function ($app) {
23+
return $app['PulkitJalan\GeoIP\GeoIP'];
2424
};
2525

26+
if ($this->app->runningInConsole()) {
27+
$this->commands(['PulkitJalan\GeoIP\Console\UpdateCommand']);
28+
}
29+
2630
if (function_exists('config_path')) {
2731
$this->publishes([
2832
__DIR__.'/config/config.php' => config_path('geoip.php'),
@@ -32,8 +36,6 @@ public function boot()
3236

3337
/**
3438
* Register the service provider.
35-
*
36-
* @return void
3739
*/
3840
public function register()
3941
{
@@ -46,28 +48,22 @@ public function register()
4648

4749
/**
4850
* Register the main geoip wrapper.
49-
*
50-
* @return void
5151
*/
5252
protected function registerGeoIP()
5353
{
54-
$this->app->singleton('geoip', function() {
55-
return new GeoIP(config('geoip'));
54+
$this->app->singleton('PulkitJalan\GeoIP\GeoIP', function ($app) {
55+
return new GeoIP($app['config']['geoip']);
5656
});
5757
}
5858

5959
/**
6060
* Register the geoip update console command.
61-
*
62-
* @return void
6361
*/
6462
protected function registerUpdateCommand()
6563
{
66-
$this->app->singleton('geoip', function() {
67-
return new UpdateCommand(config('geoip'));
64+
$this->app->singleton('PulkitJalan\GeoIP\Console\UpdateCommand', function ($app) {
65+
return new UpdateCommand($app['config']['geoip']);
6866
});
69-
70-
$this->commands(['command.geoip.update']);
7167
}
7268

7369
/**
@@ -77,6 +73,10 @@ protected function registerUpdateCommand()
7773
*/
7874
public function provides()
7975
{
80-
return ['geoip', 'command.geoip.update', 'PulkitJalan\GeoIP\GeoIP'];
76+
return [
77+
'PulkitJalan\GeoIP\GeoIP',
78+
'PulkitJalan\GeoIP\Console\UpdateCommand',
79+
'geoip',
80+
];
8181
}
8282
}

src/GeoIPUpdater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function updateMaxmindDatabase()
5252

5353
$database = array_get($this->config, 'maxmind.database', false);
5454

55-
if (! file_exists($dir = pathinfo($database, PATHINFO_DIRNAME))) {
55+
if (!file_exists($dir = pathinfo($database, PATHINFO_DIRNAME))) {
5656
mkdir($dir, 0777, true);
5757
}
5858

0 commit comments

Comments
 (0)