Moved some exceptions from core to common

This commit is contained in:
Alejandro Celaya 2016-07-20 10:13:53 +02:00
parent c290bed354
commit 06fa33877b
16 changed files with 24 additions and 17 deletions

View file

@ -4,6 +4,7 @@ use Doctrine\Common\Cache\Cache;
use Doctrine\ORM\EntityManager;
use Shlinkio\Shlink\Common\Factory\CacheFactory;
use Shlinkio\Shlink\Common\Factory\EntityManagerFactory;
use Shlinkio\Shlink\Common\Service\IpLocationResolver;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
@ -13,6 +14,7 @@ return [
EntityManager::class => EntityManagerFactory::class,
GuzzleHttp\Client::class => InvokableFactory::class,
Cache::class => CacheFactory::class,
IpLocationResolver::class => AnnotatedFactory::class,
],
'aliases' => [
'em' => EntityManager::class,

View file

@ -0,0 +1,6 @@
<?php
namespace Shlinkio\Shlink\Common\Exception;
interface ExceptionInterface
{
}

View file

@ -1,5 +1,5 @@
<?php
namespace Shlinkio\Shlink\Core\Exception;
namespace Shlinkio\Shlink\Common\Exception;
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{

View file

@ -1,5 +1,5 @@
<?php
namespace Shlinkio\Shlink\Core\Exception;
namespace Shlinkio\Shlink\Common\Exception;
class RuntimeException extends \RuntimeException implements ExceptionInterface
{

View file

@ -1,6 +0,0 @@
<?php
namespace Shlinkio\Shlink\Core\Exception;
interface ExceptionInterface
{
}

View file

@ -1,6 +1,8 @@
<?php
namespace Shlinkio\Shlink\Core\Exception;
use Shlinkio\Shlink\Common\Exception\RuntimeException;
class InvalidShortCodeException extends RuntimeException
{
public static function fromShortCode($shortCode, $charSet, \Exception $previous = null)

View file

@ -1,6 +1,8 @@
<?php
namespace Shlinkio\Shlink\Core\Exception;
use Shlinkio\Shlink\Common\Exception\RuntimeException;
class InvalidUrlException extends RuntimeException
{
public static function fromUrl($url, \Exception $previous = null)

View file

@ -7,10 +7,10 @@ use Doctrine\ORM\ORMException;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\UriInterface;
use Shlinkio\Shlink\Common\Exception\RuntimeException;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
use Shlinkio\Shlink\Core\Exception\RuntimeException;
class UrlShortener implements UrlShortenerInterface
{

View file

@ -2,9 +2,9 @@
namespace Shlinkio\Shlink\Core\Service;
use Psr\Http\Message\UriInterface;
use Shlinkio\Shlink\Common\Exception\RuntimeException;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
use Shlinkio\Shlink\Core\Exception\RuntimeException;
interface UrlShortenerInterface
{

View file

@ -3,9 +3,9 @@ namespace Shlinkio\Shlink\Core\Service;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
use Zend\Paginator\Paginator;
class VisitsTracker implements VisitsTrackerInterface

View file

@ -4,7 +4,7 @@ namespace Shlinkio\Shlink\Rest\Action;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Core\Service\VisitsTracker;
use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface;
use Shlinkio\Shlink\Rest\Util\RestUtils;

View file

@ -1,7 +1,7 @@
<?php
namespace Shlinkio\Shlink\Rest\Exception;
use Shlinkio\Shlink\Core\Exception\ExceptionInterface;
use Shlinkio\Shlink\Common\Exception\ExceptionInterface;
class AuthenticationException extends \RuntimeException implements ExceptionInterface
{

View file

@ -4,7 +4,7 @@ namespace Shlinkio\Shlink\Rest\Middleware;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Rest\Service\RestTokenService;
use Shlinkio\Shlink\Rest\Service\RestTokenServiceInterface;
use Shlinkio\Shlink\Rest\Util\RestUtils;

View file

@ -3,8 +3,8 @@ namespace Shlinkio\Shlink\Rest\Service;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Core\Entity\RestToken;
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Rest\Exception\AuthenticationException;
class RestTokenService implements RestTokenServiceInterface

View file

@ -1,8 +1,8 @@
<?php
namespace Shlinkio\Shlink\Rest\Service;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Core\Entity\RestToken;
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Rest\Exception\AuthenticationException;
interface RestTokenServiceInterface

View file

@ -1,6 +1,7 @@
<?php
namespace Shlinkio\Shlink\Rest\Util;
use Shlinkio\Shlink\Common\Exception as Common;
use Shlinkio\Shlink\Core\Exception as Core;
use Shlinkio\Shlink\Rest\Exception as Rest;
@ -13,7 +14,7 @@ class RestUtils
const INVALID_AUTH_TOKEN_ERROR = 'INVALID_AUTH_TOKEN_ERROR';
const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
public static function getRestErrorCodeFromException(Core\ExceptionInterface $e)
public static function getRestErrorCodeFromException(Common\ExceptionInterface $e)
{
switch (true) {
case $e instanceof Core\InvalidShortCodeException: