public static function valid($rules, $data) { static::$errors = []; Event::triggerOnce('core.check.init'); self::$data = $data; foreach ($rules as $field_name => $rule) { $current = isset($data[$field_name]) ? $data[$field_name] : null; if (is_callable($rule)) { static::$errors[$field_name] = call_user_func($rule, $current); continue; } elseif (is_string($rule)) { $current_rules = array_flip(preg_split('/\\s*\\|\\s*/', $rule)); } else { $current_rules = (array) $rule; } static::$errors[$field_name] = true; foreach ($current_rules as $method => $message) { $meth_name = strtok($method, ':'); $meth_opts = array_merge([$current], json_decode('[' . strtok(':') . ']')); if (static::$errors[$field_name] !== true) { continue 2; } static::$errors[$field_name] = true; if (isset(static::$methods[$meth_name])) { static::$errors[$field_name] = call_user_func_array(static::$methods[$meth_name], $meth_opts); } } } self::$data = []; // Clean non-errors static::$errors = array_filter(static::$errors, function ($v) { return $v !== true; }); return empty(static::$errors); }
public static function &connection() { if (null === static::$pdo) { static::$pdo = new PDO(static::$connection['dsn'], static::$connection['username'], static::$connection['password'], static::$connection['options']); Event::triggerOnce('core.sql.connect'); } return static::$pdo; }