File tree Expand file tree Collapse file tree 5 files changed +48
-43
lines changed Expand file tree Collapse file tree 5 files changed +48
-43
lines changed Original file line number Diff line number Diff line change @@ -39,16 +39,16 @@ There is a Laravel service provider and facade available.
3939Add the following to the ` providers ` array in your ` config/app.php `
4040
4141``` php
42- ' PulkitJalan\GeoIP\GeoIPServiceProvider'
42+ PulkitJalan\GeoIP\GeoIPServiceProvider::class
4343```
4444
4545Next add the following to the ` aliases ` array in your ` config/app.php `
4646
4747``` php
48- 'GeoIP' => ' PulkitJalan\GeoIP\Facades\GeoIP'
48+ 'GeoIP' => PulkitJalan\GeoIP\Facades\GeoIP:class
4949```
5050
51- Next run ` php artisan vendor:publish --provider="pulkitjalan\geoip \GeoIPServiceProvider" ` to publish the config file.
51+ Next run ` php artisan vendor:publish --provider="PulkitJalan\GeoIP \GeoIPServiceProvider" --tag="config " ` to publish the config file.
5252
5353#### Looking for a Laravel 4 compatible version?
5454
Original file line number Diff line number Diff line change 2323 "autoload" : {
2424 "psr-4" : {
2525 "PulkitJalan\\ GeoIP\\ " : " src"
26- },
27- "files" : [
28- " helpers.php"
29- ]
26+ }
3027 },
3128 "extra" : {
3229 "branch-alias" : {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 44
55use GuzzleHttp \Client as GuzzleClient ;
66use PulkitJalan \Requester \Requester ;
7+ use Exception ;
78
89class GeoIPUpdater
910{
@@ -52,10 +53,49 @@ protected function updateMaxmindDatabase()
5253
5354 $ database = array_get ($ this ->config , 'maxmind.database ' , false );
5455
56+ if (!file_exists ($ dir = pathinfo ($ database , PATHINFO_DIRNAME ))) {
57+ mkdir ($ dir , 0777 , true );
58+ }
59+
5560 $ file = $ this ->requester ->url ($ maxmindDatabaseUrl )->get ()->getBody ();
5661
57- @file_put_contents ($ database , gzdecode ($ file ));
62+ try {
63+ file_put_contents ($ database , $ this ->gzdecode ($ file ));
64+ } catch (Exception $ e ) {
65+ return false ;
66+ }
5867
5968 return $ database ;
6069 }
70+
71+ /**
72+ * gzdecode function.
73+ *
74+ * @param mixed $data
75+ * @return mixed
76+ */
77+ protected function gzdecode ($ data )
78+ {
79+ do {
80+ $ tempName = uniqid ('temp ' );
81+ } while (file_exists ($ tempName ));
82+
83+ if (file_put_contents ($ tempName , $ data )) {
84+ try {
85+ ob_start ();
86+ @readgzfile ($ tempName );
87+ $ uncompressed = ob_get_clean ();
88+ } catch (Exception $ e ) {
89+ $ ex = $ e ;
90+ }
91+
92+ unlink ($ tempName );
93+
94+ if (isset ($ ex )) {
95+ throw $ ex ;
96+ }
97+
98+ return $ uncompressed ;
99+ }
100+ }
61101}
Original file line number Diff line number Diff line change 4040 | Only applicable with the Pro service
4141 |
4242 */
43- 'secure ' => env ('GEOIP_IPAPI_SECURE ' ),
43+ 'secure ' => env ('GEOIP_IPAPI_SECURE ' , true ),
4444 ],
4545
4646 /*
5757 | Use http or https
5858 |
5959 */
60- 'secure ' => env ('GEOIP_TELIZE_SECURE ' ),
60+ 'secure ' => env ('GEOIP_TELIZE_SECURE ' , true ),
6161 ],
6262
6363 /*
7474 | Example: app_path().'/database/maxmind/GeoLite2-City.mmdb'
7575 |
7676 */
77- 'database ' => env ('GEOIP_MAXMIND_DATABASE ' ),
77+ 'database ' => base_path (). ' / ' . env ('GEOIP_MAXMIND_DATABASE ' , ' database/geoip/GeoLite2-City.mmdb ' ),
7878
7979 /*
8080 |--------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments