Created
August 14, 2020 09:56
-
-
Save kobus1998/ea81b174f84504ebffcbf1d712d071b6 to your computer and use it in GitHub Desktop.
use baberlei/assert library to internationalise your validation messages
This file contains hidden or 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
| <?php | |
| /** @see https://github.com/beberlei/assert */ | |
| require __DIR__ . '/vendor/autoload.php'; | |
| use Assert\Assertion as A; | |
| $sLang = 'en'; | |
| $aReturnMsg = [ | |
| 'en' => [ | |
| A::INVALID_KEY_ISSET => 'could not find key!', | |
| A::VALUE_EMPTY => 'value not filled in!', | |
| A::INVALID_EMAIL => 'email is not valid!' | |
| ] | |
| ]; | |
| try { | |
| A::keyIsset($_REQUEST, 'email'); | |
| A::notEmpty($_REQUEST['email']); | |
| A::email($_REQUEST['email']); | |
| header('Content-type: text/plain'); | |
| echo "hi, " . explode('@', $_REQUEST['email'])[0]; | |
| die; | |
| } catch (\Assert\AssertionFailedException $e) { | |
| echo $aReturnMsg[$sLang][$e->getCode()] . "\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment