-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from homeappcorporate/task/PHP-1167
[php-1167] Рефактор JsonApi Exceptions
- Loading branch information
Showing
8 changed files
with
106 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace Homeapp\JsonApi\Exception; | ||
|
||
use Symfony\Component\Asset\Exception\InvalidArgumentException; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
abstract class JsonApiBaseException extends InvalidArgumentException | ||
{ | ||
protected ?string $parameter = null; | ||
protected ?string $pointer = null; | ||
|
||
public static function create(string $message, ?string $parameter = null): self | ||
{ | ||
$exception = new static(); | ||
$exception->message = $message; | ||
$exception->parameter = $parameter; | ||
$exception->code = static::getHttpCode(); | ||
|
||
return $exception; | ||
} | ||
|
||
public static function createWithPointer(string $message, string $pointer): self | ||
{ | ||
$exception = new static(); | ||
$exception->message = $message; | ||
$exception->pointer = $pointer; | ||
$exception->code = static::getHttpCode(); | ||
|
||
return $exception; | ||
} | ||
|
||
abstract protected static function getHttpCode(): int; | ||
|
||
public function getParameter(): ?string | ||
{ | ||
return $this->parameter; | ||
} | ||
|
||
public function getPointer(): ?string | ||
{ | ||
return $this->pointer; | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace Homeapp\JsonApi\Exception; | ||
|
||
use Symfony\Component\Asset\Exception\InvalidArgumentException; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class JsonApiConflictException extends JsonApiBaseException | ||
{ | ||
protected static function getHttpCode(): int | ||
{ | ||
return Response::HTTP_CONFLICT; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
<?php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace Homeapp\JsonApi\Exception; | ||
|
||
use Symfony\Component\Asset\Exception\InvalidArgumentException; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class JsonApiNotFoundException extends InvalidArgumentException | ||
class JsonApiNotFoundException extends JsonApiBaseException | ||
{ | ||
public static function create(string $message): self | ||
protected static function getHttpCode(): int | ||
{ | ||
$exception = new self(); | ||
$exception->message = $message; | ||
$exception->code = Response::HTTP_NOT_FOUND; | ||
|
||
return $exception; | ||
return Response::HTTP_NOT_FOUND; | ||
} | ||
} | ||
|
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace Homeapp\JsonApi\Exception; | ||
|
||
use Symfony\Component\Asset\Exception\InvalidArgumentException; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class JsonApiServerException extends JsonApiBaseException | ||
{ | ||
protected static function getHttpCode(): int | ||
{ | ||
return Response::HTTP_INTERNAL_SERVER_ERROR; | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,18 +1,15 @@ | ||
<?php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace Homeapp\JsonApi\Exception; | ||
|
||
use Symfony\Component\Asset\Exception\InvalidArgumentException; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class JsonApiUnsupportedMediaTypeException extends InvalidArgumentException | ||
class JsonApiUnsupportedMediaTypeException extends JsonApiBaseException | ||
{ | ||
public static function create(string $message): self | ||
protected static function getHttpCode(): int | ||
{ | ||
$exception = new self(); | ||
$exception->message = $message; | ||
$exception->code = Response::HTTP_UNSUPPORTED_MEDIA_TYPE; | ||
|
||
return $exception; | ||
return Response::HTTP_UNSUPPORTED_MEDIA_TYPE; | ||
} | ||
} | ||
} |