SHARE
TWEET
Untitled
a guest
Jan 29th, 2018
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- <?php
- declare(strict_types=1);
- namespace Reports\Common\Application\Validator;
- final class StringFilter
- {
- const EMPTYSTRING = 'EmptyString';
- const NOTNULL = 'NotNull';
- const VALIDATIONCODE = 422;
- /** @var string $value */
- private $value;
- /**
- * @var array
- */
- protected $messageTemplates = [
- self::EMPTYSTRING => 'Given value cannot be empty string',
- self::NOTNULL => 'Given value cannot be null',
- ];
- public function __construct(string $valueToValid)
- {
- $this->isValid($valueToValid);
- $this->translate($valueToValid);
- }
- private function isValid(string $valueToValid)
- {
- if ($valueToValid === '') {
- throw new \Exception($this->messageTemplates[self::EMPTYSTRING], self::VALIDATIONCODE);
- }
- if (!$valueToValid) {
- throw new \Exception($this->messageTemplates[self::NOTNULL], self::VALIDATIONCODE);
- }
- }
- private function translate(string $valueToTranslate)
- {
- $this->value = strtr($valueToTranslate, 'ĘÓĄŚŁŻŹĆŃęóąśłżźćń', 'EOASLZZCNeoaslzzcn');
- }
- public function getValue(): string{
- return $this->value;
- }
- }
RAW Paste Data

