Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created August 14, 2020 09:56
Show Gist options
  • Select an option

  • Save kobus1998/ea81b174f84504ebffcbf1d712d071b6 to your computer and use it in GitHub Desktop.

Select an option

Save kobus1998/ea81b174f84504ebffcbf1d712d071b6 to your computer and use it in GitHub Desktop.
use baberlei/assert library to internationalise your validation messages
<?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