mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Decoupled Common module from any other module
This commit is contained in:
parent
97a362617d
commit
cb715c0877
5 changed files with 10 additions and 9 deletions
|
@ -7,8 +7,8 @@ use Doctrine\DBAL\DBALException;
|
|||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use PDO;
|
||||
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
|
@ -60,7 +60,7 @@ final class Version20180913205455 extends AbstractMigration
|
|||
|
||||
try {
|
||||
return (string) IpAddress::fromString($addr)->getObfuscatedCopy();
|
||||
} catch (WrongIpException $e) {
|
||||
} catch (InvalidArgumentException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shlinkio\Shlink\Common\Util;
|
||||
|
||||
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||
|
||||
use function count;
|
||||
use function explode;
|
||||
use function implode;
|
||||
use function sprintf;
|
||||
use function trim;
|
||||
|
||||
final class IpAddress
|
||||
|
@ -36,14 +37,14 @@ final class IpAddress
|
|||
/**
|
||||
* @param string $address
|
||||
* @return IpAddress
|
||||
* @throws WrongIpException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function fromString(string $address): self
|
||||
{
|
||||
$address = trim($address);
|
||||
$parts = explode('.', $address);
|
||||
if (count($parts) !== self::IPV4_PARTS_COUNT) {
|
||||
throw WrongIpException::fromIpAddress($address);
|
||||
throw new InvalidArgumentException(sprintf('Provided IP "%s" is invalid', $address));
|
||||
}
|
||||
|
||||
return new self(...$parts);
|
||||
|
|
|
@ -9,7 +9,6 @@ use GuzzleHttp\ClientInterface;
|
|||
use GuzzleHttp\RequestOptions;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Shlinkio\Shlink\Rest\Authentication\Plugin\ApiKeyHeaderPlugin;
|
||||
|
||||
use function Shlinkio\Shlink\Common\json_decode;
|
||||
use function sprintf;
|
||||
|
@ -48,7 +47,7 @@ abstract class ApiTestCase extends TestCase implements StatusCodeInterface, Requ
|
|||
protected function callApiWithKey(string $method, string $uri, array $options = []): ResponseInterface
|
||||
{
|
||||
$headers = $options[RequestOptions::HEADERS] ?? [];
|
||||
$headers[ApiKeyHeaderPlugin::HEADER_NAME] = 'valid_api_key';
|
||||
$headers['X-Api-Key'] = 'valid_api_key';
|
||||
$options[RequestOptions::HEADERS] = $headers;
|
||||
|
||||
return $this->callApi($method, $uri, $options);
|
||||
|
|
|
@ -6,11 +6,11 @@ namespace Shlinkio\Shlink\Core\Entity;
|
|||
use Cake\Chronos\Chronos;
|
||||
use JsonSerializable;
|
||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\UnknownVisitLocation;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
||||
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||
|
||||
class Visit extends AbstractEntity implements JsonSerializable
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ class Visit extends AbstractEntity implements JsonSerializable
|
|||
|
||||
try {
|
||||
return (string) IpAddress::fromString($address)->getObfuscatedCopy();
|
||||
} catch (WrongIpException $e) {
|
||||
} catch (InvalidArgumentException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase;
|
||||
|
||||
use function explode;
|
||||
|
||||
class OptionsRequestTest extends ApiTestCase
|
||||
|
|
Loading…
Add table
Reference in a new issue