-
Notifications
You must be signed in to change notification settings - Fork 5
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 #1 from m1x0n/feature/translator-support
Added translator support.
- Loading branch information
Showing
49 changed files
with
292 additions
and
357 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,10 @@ | ||
<?xml version="1.0"?> | ||
|
||
<ruleset name="Opis Error Presenter"> | ||
<description>Opis Error Presenter Rules</description> | ||
|
||
<rule ref="PSR12"/> | ||
|
||
<file>./src</file> | ||
<file>./tests</file> | ||
</ruleset> |
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpisErrorPresenter\Contracts; | ||
|
||
interface MessageTranslator | ||
{ | ||
public function translate(string $key, array $replacements = [], $locale = null): string; | ||
} |
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,4 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpisErrorPresenter\Contracts; | ||
|
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 |
---|---|---|
@@ -1,24 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
declare(strict_types=1); | ||
|
||
namespace OpisErrorPresenter\Implementation\Formatters; | ||
|
||
use Opis\JsonSchema\ValidationError; | ||
use OpisErrorPresenter\Contracts\MessageFormatter; | ||
|
||
class Constant implements MessageFormatter | ||
class Constant extends Formatter | ||
{ | ||
private const MESSAGE = "The attribute value expected to be ':expected:'."; | ||
public const MESSAGE = "The attribute value expected to be ':expected:'."; | ||
|
||
public function format(ValidationError $error): string | ||
public function replacements(): array | ||
{ | ||
$expected = $error->keywordArgs()['expected']; | ||
|
||
$replacements = [ | ||
':expected:' => $expected | ||
return [ | ||
':expected:' => $this->error->keywordArgs()['expected'] | ||
]; | ||
|
||
return strtr(self::MESSAGE, $replacements); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpisErrorPresenter\Implementation\Formatters; | ||
|
||
use Opis\JsonSchema\ValidationError; | ||
use OpisErrorPresenter\Contracts\MessageFormatter; | ||
|
||
class Enum implements MessageFormatter | ||
class Enum extends Formatter | ||
{ | ||
private const MESSAGE = 'The attribute must be one of the following values: :expected:.'; | ||
public const MESSAGE = 'The attribute must be one of the following values: :expected:.'; | ||
|
||
public function format(ValidationError $error): string | ||
public function replacements(): array | ||
{ | ||
$expected = $error->keywordArgs()['expected']; | ||
$keywordArgs = $this->error->keywordArgs(); | ||
$expected = (array)$keywordArgs['expected']; | ||
|
||
$replacements = [ | ||
':expected:' => "'" . implode ("', '", $expected) . "'", | ||
return [ | ||
':expected:' => implode(', ', array_map( | ||
function ($item) { | ||
return "'{$item}'"; | ||
}, | ||
$expected | ||
)), | ||
]; | ||
|
||
return strtr(self::MESSAGE, $replacements); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpisErrorPresenter\Implementation\Formatters; | ||
|
||
use Opis\JsonSchema\ValidationError; | ||
use OpisErrorPresenter\Contracts\MessageFormatter; | ||
|
||
abstract class Formatter implements MessageFormatter | ||
{ | ||
/** | ||
* @var ValidationError | ||
*/ | ||
protected $error; | ||
|
||
public function __construct(ValidationError $error) | ||
{ | ||
$this->error = $error; | ||
} | ||
|
||
public function keyword(): string | ||
{ | ||
return $this->error->keyword(); | ||
} | ||
|
||
public function replacements(): array | ||
{ | ||
return []; | ||
} | ||
} |
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,17 +1,10 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace OpisErrorPresenter\Implementation\Formatters; | ||
declare(strict_types=1); | ||
|
||
use Opis\JsonSchema\ValidationError; | ||
use OpisErrorPresenter\Contracts\MessageFormatter; | ||
namespace OpisErrorPresenter\Implementation\Formatters; | ||
|
||
class InvalidAttribute implements MessageFormatter | ||
class InvalidAttribute extends Formatter | ||
{ | ||
private const MESSAGE = 'The attribute is invalid.'; | ||
|
||
public function format(ValidationError $error): string | ||
{ | ||
return self::MESSAGE; | ||
} | ||
public const MESSAGE = 'The attribute is invalid.'; | ||
} |
Oops, something went wrong.