-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
252 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ShlinkMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Schema\SchemaException; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20180801183328 extends AbstractMigration | ||
{ | ||
private const NEW_SIZE = 255; | ||
private const OLD_SIZE = 10; | ||
|
||
/** | ||
* @param Schema $schema | ||
* @throws SchemaException | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
$this->setSize($schema, self::NEW_SIZE); | ||
} | ||
|
||
/** | ||
* @param Schema $schema | ||
* @throws SchemaException | ||
*/ | ||
public function down(Schema $schema): void | ||
{ | ||
$this->setSize($schema, self::OLD_SIZE); | ||
} | ||
|
||
/** | ||
* @param Schema $schema | ||
* @param int $size | ||
* @throws SchemaException | ||
*/ | ||
private function setSize(Schema $schema, int $size): void | ||
{ | ||
$schema->getTable('short_urls')->getColumn('short_code')->setLength($size); | ||
} | ||
} |
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
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,51 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Common\Service; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use Shlinkio\Shlink\Common\Exception\WrongIpException; | ||
|
||
class IpApiLocationResolver implements IpLocationResolverInterface | ||
{ | ||
private const SERVICE_PATTERN = 'http://ip-api.com/json/%s'; | ||
|
||
/** | ||
* @var Client | ||
*/ | ||
private $httpClient; | ||
|
||
public function __construct(Client $httpClient) | ||
{ | ||
$this->httpClient = $httpClient; | ||
} | ||
|
||
/** | ||
* @param string $ipAddress | ||
* @return array | ||
* @throws WrongIpException | ||
*/ | ||
public function resolveIpLocation(string $ipAddress): array | ||
{ | ||
try { | ||
$response = $this->httpClient->get(\sprintf(self::SERVICE_PATTERN, $ipAddress)); | ||
return $this->mapFields(\json_decode((string) $response->getBody(), true)); | ||
} catch (GuzzleException $e) { | ||
throw WrongIpException::fromIpAddress($ipAddress, $e); | ||
} | ||
} | ||
|
||
private function mapFields(array $entry): array | ||
{ | ||
return [ | ||
'country_code' => $entry['countryCode'] ?? '', | ||
'country_name' => $entry['country'] ?? '', | ||
'region_name' => $entry['regionName'] ?? '', | ||
'city' => $entry['city'] ?? '', | ||
'latitude' => $entry['lat'] ?? '', | ||
'longitude' => $entry['lon'] ?? '', | ||
'time_zone' => $entry['timezone'] ?? '', | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.