public static function validate($data, $livr) { \Validator\LIVR::registerDefaultRules(['latin_string' => function () { return function ($value) { if (!isset($value) || $value === '') { return; } if (!is_string($value)) { return 'FORMAT_ERROR'; } $validStringReg = '/^[a-zA-Z0-9\\-\\_\\+\\#№"\']+$/'; if (!preg_match($validStringReg, $value)) { return 'WRONG_STRING'; } return; }; }, 'phone' => function () { return function ($value) { if (!isset($value) || $value === '') { return; } if (!is_string($value)) { return 'FORMAT_ERROR'; } $reg = '/^[0-9]{10}$/'; if (!preg_match($reg, $value)) { return 'WRONG_FORMAT'; } return; }; }]); $validator = new \Validator\LIVR($livr); $validated = $validator->validate($data); $errors = $validator->getErrors(); if ($errors) { throw new X(['Type' => 'FORMAT_ERROR', 'Fields' => $errors]); } return $validated; }
date_default_timezone_set('Europe/Kiev'); require_once __DIR__ . '/../vendor/autoload.php'; $appConf = (require_once __DIR__ . '/../etc/app-conf.php'); Engine::init($appConf['dbConfig']['test']); require_once 'TestHelper.php'; require_once 'LocalWebTestCase.php'; \Validator\LIVR::registerDefaultRules(['equals' => function ($expected) { return function ($got) use($expected) { if ($got != $expected) { return 'NOT_EQUILAS'; } }; }, 'strict_equals' => function ($expected) { return function ($got) use($expected) { if ($got !== $expected) { return 'NOT_EQUILAS'; } }; }, 'empty_array' => function () { return function ($got) { if (!is_array($got) || count($got)) { return 'NOT_EMPTY_ARRAY'; } }; }, 'array' => function () { return function ($got) { if (!is_array($got)) { return 'NOT_ARRAY'; } }; }]);