-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: ipapi-pro single lookup * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
de4535c
commit b2b6cad
Showing
8 changed files
with
105 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/geoip. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\GeoIP\Listeners; | ||
|
||
use Flarum\Post\Event\Saving as PostSaving; | ||
use FoF\GeoIP\Jobs; | ||
use FoF\GeoIP\Repositories\GeoIPRepository; | ||
use Illuminate\Contracts\Events\Dispatcher; | ||
use Illuminate\Contracts\Queue\Queue; | ||
|
||
class RetrieveIP | ||
{ | ||
/** | ||
* @var Queue | ||
*/ | ||
protected $queue; | ||
|
||
/** | ||
* @var GeoIPRepository | ||
*/ | ||
protected $geo; | ||
|
||
public function __construct(Queue $queue, GeoIPRepository $geo) | ||
{ | ||
$this->queue = $queue; | ||
$this->geo = $geo; | ||
} | ||
|
||
public function subscribe(Dispatcher $events) | ||
{ | ||
$events->listen(PostSaving::class, [$this, 'handlePost']); | ||
} | ||
|
||
public function retrieveIP(string $ip): void | ||
{ | ||
if ($this->geo->isValidIP($ip) && !$this->geo->recordExistsForIP($ip)) { | ||
$this->queue->push(new Jobs\RetrieveIP($ip)); | ||
} | ||
} | ||
|
||
public function handlePost(PostSaving $event) | ||
{ | ||
$this->retrieveIP($event->post->ip_address); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters