コード例 #1
0
 public static function initialize()
 {
     if (defined('TESTS_ENV') || self::is_dev()) {
         ini_set('display_errors', 'on');
         error_reporting(E_ALL);
     } else {
         ini_set('display_errors', 'off');
         error_reporting(0);
     }
     require_once ROOT_PATH . DS . 'common' . DS . 'classes' . DS . 'autoloader.php';
     Autoloader::init_autoload();
     FileSystemHelper::init_dirs();
     LIVR::defaultAutoTrim(true);
     /**
      * @var $system \System
      */
     $system = static::get_class(\System::class);
     $system->initialize();
     /**
      * @var $configuration Configuration
      */
     $configuration = Application::get_class(Configuration::class);
     $current_lang = $configuration->language;
     defined('CURRENT_LANG') or define('CURRENT_LANG', $current_lang);
 }
コード例 #2
0
 /**
  * @param array $fields
  * @param null|array $old_fields
  * @throws \InvalidArgumentException
  * @return bool
  */
 private function validate(array $fields, $old_fields = null)
 {
     $validator = new LIVR(['login' => ['required', 'unique_login'], 'password' => 'hash_password', 'credentials' => 'required', 'remember_hash' => 'trim']);
     if (is_array($old_fields)) {
         $is_login_changed = $old_fields['login'] != $fields['login'];
         $validator->registerRules(['unique_login' => function () use($is_login_changed) {
             return function ($value) use($is_login_changed) {
                 if ($is_login_changed && !empty($this->adapter->select()->where(['login' => ['=', $value]])->execute()->get_result())) {
                     return 'LOGIN_EXISTS';
                 }
                 return null;
             };
         }]);
     } else {
         $validator->registerRules(['unique_login' => function () {
             return function ($value) {
                 $user = $this->adapter->select()->where(['login' => ['=', $value]])->execute()->get_result();
                 if ($user) {
                     return 'LOGIN_EXISTS';
                 }
                 return null;
             };
         }]);
     }
     $validator->registerRules(['hash_password' => function () use($fields) {
         return function ($value, $undef, &$output_arr) use($fields) {
             if (trim($value)) {
                 $output_arr = password_hash($value, PASSWORD_BCRYPT);
                 return;
             }
             return null;
         };
     }]);
     /**
      * @var $ext \User
      */
     $ext = Application::get_class(\User::class);
     $lang_vars = new LanguageFile('mapper' . DS . 'usermapper.json', $ext->get_lang_path());
     $result = $validator->validate($fields);
     !$result && ($this->validation_errors = $validator->getErrors($lang_vars['errors']));
     return $result;
 }
コード例 #3
0
ファイル: Validator.php プロジェクト: a-melnichuk/Movies-Demo
 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;
 }
コード例 #4
0
ファイル: bootstrap.php プロジェクト: a-melnichuk/Movies-Demo
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';
        }
    };
}]);