-
Notifications
You must be signed in to change notification settings - Fork 2
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
11 changed files
with
70 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,42 @@ | |
namespace Glavweb\UploaderBundle\ErrorHandler; | ||
|
||
use Glavweb\UploaderBundle\Response\Response; | ||
use Symfony\Contracts\Translation\TranslatableInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
/** | ||
* Class StandardErrorHandler | ||
* | ||
* @package Glavweb\UploaderBundle | ||
* @author Andrey Nilov <[email protected]> | ||
* @author Andrey Nilov <[email protected]> | ||
*/ | ||
class StandardErrorHandler implements ErrorHandlerInterface | ||
{ | ||
/** | ||
* @var TranslatorInterface | ||
*/ | ||
private $translator; | ||
|
||
/** | ||
* StandardErrorHandler constructor. | ||
*/ | ||
public function __construct(TranslatorInterface $translator) | ||
{ | ||
$this->translator = $translator; | ||
} | ||
|
||
/** | ||
* @param Response $response | ||
* @param \Exception $exception | ||
*/ | ||
public function addException(Response $response, \Exception $exception) | ||
{ | ||
$message = $exception->getMessage(); | ||
if ($exception instanceof TranslatableInterface) { | ||
$message = $exception->trans($this->translator); | ||
} else { | ||
$message = $exception->getMessage(); | ||
} | ||
|
||
$response['error'] = $message; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -12,20 +12,44 @@ | |
namespace Glavweb\UploaderBundle\Exception; | ||
|
||
use Symfony\Component\HttpFoundation\File\Exception\UploadException; | ||
use Symfony\Contracts\Translation\TranslatableInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
use Throwable; | ||
|
||
/** | ||
* Class ValidationException | ||
* | ||
* @package Glavweb\UploaderBundle | ||
* @author Andrey Nilov <[email protected]> | ||
*/ | ||
class ValidationException extends UploadException | ||
class ValidationException extends UploadException implements TranslatableInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $details; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $errorMessage; | ||
|
||
/** | ||
* ValidationException constructor. | ||
* | ||
* @param string $message | ||
* @param array $details | ||
* @param int $code | ||
* @param Throwable|null $previous | ||
*/ | ||
public function __construct($message = "", $details = [], $code = 0, Throwable $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
|
||
$this->details = $details; | ||
} | ||
|
||
|
||
/** | ||
* @param string $message | ||
* @return $this | ||
|
@@ -49,4 +73,9 @@ public function getErrorMessage() | |
|
||
return $this->errorMessage; | ||
} | ||
|
||
public function trans(TranslatorInterface $translator, string $locale = null): string | ||
{ | ||
return $translator->trans($this->getMessage(), $this->details, null, $locale); | ||
} | ||
} |
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,3 @@ | ||
error: | ||
invalid_type: You can't upload files of this type | ||
maxsize: 'File is too big ({filesize} MB). Max filesize: {maxFilesize} MB' |
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,3 @@ | ||
error: | ||
invalid_type: Неверный формат файла | ||
maxsize: Файл слишком большой ({filesize} MB). Максимальный допустимый размер файла {maxFilesize} MB |
Empty file.
Empty file.
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