本文整理汇总了PHP中Validator::check方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::check方法的具体用法?PHP Validator::check怎么用?PHP Validator::check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validator
的用法示例。
在下文中一共展示了Validator::check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertNotValid
function assertNotValid($data, $errors)
{
$validator = new Validator();
$validator->check($data, $this->schema);
$this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(), true));
$this->assertFalse($validator->isValid());
}
示例2: Validator
<?php
require '_inc.php';
$errors = [];
$spam = [];
$validator = new Validator($_POST);
$validator->check('nom', 'required');
$validator->check('prénom', 'required');
$validator->check('email', 'email');
$validator->check('email', 'required');
$validator->check('description', 'required');
$validator->specialcheck('arbitraryfield', 'empty');
$errors = $validator->errors();
$spam = $validator->spam();
if (!empty($spam)) {
$_SESSION['spam'] = $spam;
// redirection
header('Location:success.php');
} else {
if (!empty($errors)) {
$_SESSION['errors'] = $errors;
$_SESSION['inputs'] = $_POST;
// redirection
header('Location:index.php');
} else {
$_SESSION['success'] = 1;
$email_contact = "\r\nContact: " . $_POST['email'] . "\r\n";
$nom_prenom = "\r\nNom et prénom: " . $_POST['nom'] . " " . $_POST['prénom'] . "\r\n";
$message = "\r\nMessage: " . $_POST['description'] . "\r\n";
$message_compiled = $message . $nom_prenom . $email_contact;
$headers = 'FROM: site@localdev';
示例3: array
/*
Account
*/
Route::get('account', array('before' => 'check', 'main' => function () {
// check we have a database
if (!Session::get('install.metadata')) {
Notify::error('Please enter your site details');
return Response::redirect('metadata');
}
$vars['messages'] = Notify::read();
return Layout::create('account', $vars);
}));
Route::post('account', array('before' => 'check', 'main' => function () {
$account = Input::get(array('username', 'email', 'password'));
$validator = new Validator($account);
$validator->check('username')->is_max(3, 'Please enter a username');
$validator->check('email')->is_email('Please enter a valid email address');
$validator->check('password')->is_max(6, 'Please enter a password, at least 6 characters long');
if ($errors = $validator->errors()) {
Input::flash();
Notify::error($errors);
return Response::redirect('account');
}
Session::put('install.account', $account);
// run install process
try {
Installer::run();
} catch (Exception $e) {
Input::flash();
Notify::error($e->getMessage());
return Response::redirect('account');
示例4: ErrorHandler
<?php
require '../../classes/Database.php';
require '../../classes/Validator.php';
require '../../classes/ErrorHandler.php';
require '../../classes/AdminGui.php';
require '../../functions/security.php';
$errorHandler = new ErrorHandler();
$db = new Database();
$gui = new AdminGui($db);
$media_types_records = $gui->select('media_types');
if (!empty($_POST)) {
$db->table('media_types');
$validator = new Validator($db, $errorHandler);
$validation = $validator->check($_POST, ['media_type' => ['required' => true]]);
if ($validation->fails()) {
echo '<pre>', print_r($validation->errors()->all()), '</pre>';
} else {
if ($db->insert($_POST)) {
header('Location: create_media_types.php');
die;
}
}
}
?>
<!doctype html>
<html>
<head>
<title>Create media types</title>
<link rel="stylesheet" type="text/css" href="../../public/front/css/admin.css">
示例5: function
});
Route::post('admin/posts/add', function () {
$input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js', 'category', 'status', 'comments', 'company', 'department'));
// if there is no slug try and create one from the title
if (empty($input['slug'])) {
$input['slug'] = $input['title'];
}
// convert to ascii
$input['slug'] = slug($input['slug']);
// encode title
$input['title'] = e($input['title'], ENT_COMPAT);
$validator = new Validator($input);
$validator->add('duplicate', function ($str) {
return Post::where('slug', '=', $str)->count() == 0;
});
$validator->check('title')->is_max(3, __('posts.title_missing'));
$validator->check('slug')->is_max(3, __('posts.slug_missing'))->is_duplicate(__('posts.slug_duplicate'))->not_regex('#^[0-9_-]+$#', __('posts.slug_invalid'));
if ($errors = $validator->errors()) {
Input::flash();
Notify::error($errors);
return Response::redirect('admin/posts/add');
}
if (empty($input['created'])) {
$input['created'] = Date::mysql('now');
}
$user = Auth::user();
$input['author'] = $user->id;
if (is_null($input['comments'])) {
$input['comments'] = 0;
}
if (empty($input['html'])) {
示例6: array
$vars['dashboard_page_options'] = array('panel' => 'Welcome', 'posts' => 'Posts', 'pages' => 'Pages');
$vars['meta'] = Config::get('meta');
$vars['pages'] = Page::dropdown();
$vars['themes'] = Themes::all();
return View::create('extend/metadata/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
});
/*
Update Metadata
*/
Route::post('admin/extend/metadata', function () {
$input = Input::get(array('sitename', 'description', 'home_page', 'posts_page', 'posts_per_page', 'auto_published_comments', 'theme', 'comment_notifications', 'comment_moderation_keys', 'show_all_posts', 'dashboard_page'));
foreach ($input as $key => $value) {
$input[$key] = eq($value);
}
$validator = new Validator($input);
$validator->check('sitename')->is_max(3, __('metadata.sitename_missing'));
$validator->check('description')->is_max(3, __('metadata.sitedescription_missing'));
$validator->check('posts_per_page')->is_regex('#^[0-9]+$#', __('metadata.missing_posts_per_page', 'Please enter a number for posts per page'));
if ($errors = $validator->errors()) {
Input::flash();
Notify::error($errors);
return Response::redirect('admin/extend/metadata');
}
// convert double quotes so we dont break html
$input['sitename'] = e($input['sitename'], ENT_COMPAT);
$input['description'] = e($input['description'], ENT_COMPAT);
foreach ($input as $key => $v) {
$v = is_null($v) ? 0 : $v;
Query::table(Base::table('meta'))->where('key', '=', $key)->update(array('value' => $v));
}
Notify::success(__('metadata.updated'));
示例7: function
$vars['pagetype'] = Query::table(Base::table('pagetypes'))->where('key', '=', $key)->fetch();
return View::create('extend/pagetypes/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
});
Route::post('admin/extend/pagetypes/edit/(:any)', function ($key) {
$input = Input::get(array('key', 'value'));
$input['key'] = slug($input['key'], '_');
$validator = new Validator($input);
$validator->add('valid_key', function ($str) use($key) {
// no change
if ($str == $key) {
return true;
}
// check the new key $str is available
return Query::table(Base::table('pagetypes'))->where('key', '=', $str)->count() == 0;
});
$validator->check('key')->is_max(2, __('extend.key_missing'))->is_valid_key(__('extend.key_exists'));
$validator->check('value')->is_max(1, __('extend.name_missing'));
if ($errors = $validator->errors()) {
Input::flash();
Notify::error($errors);
return Response::redirect('admin/extend/pagetypes/edit/' . $key);
}
Query::table(Base::table('pagetypes'))->where('key', '=', $key)->update($input);
Notify::success(__('extend.pagetype_updated'));
return Response::redirect('admin/extend/pagetypes');
});
/*
Delete Var
*/
Route::get('admin/extend/pagetypes/delete/(:any)', function ($key) {
Query::table(Base::table('pagetypes'))->where('key', '=', $key)->delete();
示例8: Validator
<?php
require_once 'app/init.php';
if (!empty($_POST)) {
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$validator = new Validator($database, $errorHandler);
$validation = $validator->check($_POST, ['email' => ['required' => true, 'maxlength' => 255, 'unique' => 'tblTeamMembers', 'email' => true], 'username' => ['required' => true, 'minlength' => 3, 'unique' => 'tblTeamMembers'], 'password' => ['required' => true, 'minlength' => 5]]);
if ($validation->fails()) {
echo '<pre>', print_r($validator->errors()->all(), true), '</pre>';
} else {
$created = $auth->create(['Email_Address' => $email, 'Login_Name' => $username, 'Web_Password' => $password]);
if ($created) {
header('Location:index.php');
}
//echo $hash->make($password);
//echo $hash->make($_POST['password']);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sign In</title>
</head>
<body>
<form action="signup.php" method="post">
示例9: slug
$input['js'] = " ";
}
// if there is no slug try and create one from title
if (empty($input['slug'])) {
$input['slug'] = slug($input['title']);
}
// convert to ascii
$input['slug'] = slug($input['slug']);
do {
//Check for duplication
$isDuplicate = Post::where('slug', '=', $input['slug'])->count() > 0;
if ($isDuplicate) {
$input['slug'] = slug(noise(10));
}
} while ($isDuplicate);
$validator->check('slug')->not_regex('#^[0-9_-]+$#', __('posts.slug_invalid'));
if ($errors = $validator->errors()) {
Input::flash();
Notify::error($errors);
return Response::redirect('admin/posts/add');
}
if (empty($input['created'])) {
$input['created'] = Date::mysql('now');
}
$user = Auth::user();
$input['author'] = $user->id;
if (is_null($input['comments'])) {
$input['comments'] = 0;
}
$post = Post::create($input);
Extend::process('post', $post->id);
示例10: substr
$vars['variable']->user_key = substr($vars['variable']->key, strlen('custom_'));
return View::create('extend/variables/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
});
Route::post('admin/extend/variables/edit/(:any)', function ($key) {
$input = Input::get(array('key', 'value'));
$input['key'] = 'custom_' . slug($input['key'], '_');
$validator = new Validator($input);
$validator->add('valid_key', function ($str) use($key) {
// no change
if ($str == $key) {
return true;
}
// check the new key $str is available
return Query::table(Base::table('meta'))->where('key', '=', $str)->count() == 0;
});
$validator->check('key')->is_max(8, __('extend.name_missing'))->is_valid_key(__('extend.name_exists'));
if ($errors = $validator->errors()) {
Input::flash();
Notify::error($errors);
return Response::redirect('admin/extend/variables/edit/' . $key);
}
Query::table(Base::table('meta'))->where('key', '=', $key)->update($input);
Notify::success(__('extend.variable_updated'));
return Response::redirect('admin/extend/variables');
});
/*
Delete Var
*/
Route::get('admin/extend/variables/delete/(:any)', function ($key) {
Query::table(Base::table('meta'))->where('key', '=', $key)->delete();
Notify::success(__('extend.variable_deleted'));
示例11: array
if ($token != $key) {
Notify::error(__('users.recovery_expired'));
return Response::redirect('admin/login');
}
return View::create('users/reset', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
}));
Route::post('admin/reset/(:any)', array('before' => 'csrf', 'main' => function ($key) {
$password = Input::get('pass');
$token = Session::get('token');
$user = Session::get('user');
if ($token != $key) {
Notify::error(__('users.recovery_expired'));
return Response::redirect('admin/login');
}
$validator = new Validator(array('password' => $password));
$validator->check('password')->is_max(6, __('users.password_too_short', 6));
if ($errors = $validator->errors()) {
Input::flash();
Notify::error($errors);
return Response::redirect('admin/reset/' . $key);
}
User::update($user, array('password' => Hash::make($password)));
Session::erase('user');
Session::erase('token');
Notify::success(__('users.password_reset'));
return Response::redirect('admin/login');
}));
/*
Upgrade
*/
Route::get('admin/upgrade', function () {
示例12: ErrorHandler
<?php
require '../../classes/Database.php';
require '../../classes/Validator.php';
require '../../classes/ErrorHandler.php';
require '../../classes/AdminGui.php';
require '../../functions/security.php';
$errorHandler = new ErrorHandler();
$db = new Database();
$gui = new AdminGui($db);
$categories_records = array();
if (!empty($_POST)) {
$db->table('categories');
$validator = new Validator($db, $errorHandler);
$validation = $validator->check($_POST, ['category' => ['required' => true, 'unique' => 'categories']]);
if ($validation->fails()) {
echo '<pre>', print_r($validation->errors()->all()), '</pre>';
} else {
if ($db->insert($_POST)) {
header('Location: create_categories.php');
die;
}
}
}
if ($results = $db->table('categories')->select()) {
foreach ($results as $row) {
$categories_records[] = $row;
}
}
?>
示例13: ErrorHandler
<?php
require '../../classes/Database.php';
require '../../classes/Validator.php';
require '../../classes/ErrorHandler.php';
require '../../classes/AdminGui.php';
require '../../functions/security.php';
$errorHandler = new ErrorHandler();
$db = new Database();
$gui = new AdminGui($db);
$technologies_records = $gui->select('technologies');
if (!empty($_POST)) {
$db->table('technologies');
$validator = new Validator($db, $errorHandler);
$validation = $validator->check($_POST, ['technology' => ['required' => true]]);
if ($validation->fails()) {
echo '<pre>', print_r($validation->errors()->all()), '</pre>';
} else {
if ($db->insert($_POST)) {
header('Location: create_technologies.php');
die;
}
}
}
?>
<!doctype html>
<html>
<head>
<title>Create technologies</title>
<link rel="stylesheet" type="text/css" href="../../public/front/css/admin.css">
示例14: check
public static function check($subject, $pattern)
{
// check require if set
if (isset($pattern['require']) && $pattern['require']) {
if (empty($subject) || !isset($subject)) {
return 'require';
}
}
$check_type = $pattern['type'];
// check pattern
if (!isset($check_type) || empty($check_type)) {
return 'wrong_pattern : unknown type';
}
if (isset($pattern['min']) && !empty($pattern['min'])) {
if (Validator::check($pattern['min'], array('type' => 'INT'))) {
return 'wrong_pattern : min must be INT';
}
}
if (isset($pattern['max']) && !empty($pattern['max'])) {
if (Validator::check($pattern['max'], array('type' => 'INT'))) {
return 'wrong_pattern : max must be INT';
}
}
if (isset($pattern['M']) && !empty($pattern['M'])) {
if (Validator::check($pattern['M'], array('type' => 'INT'))) {
return 'wrong_pattern : M of DECIMAL must be INT';
}
}
if (isset($pattern['D']) && !empty($pattern['D'])) {
if (Validator::check($pattern['D'], array('type' => 'INT'))) {
return 'wrong_pattern : D of DECIMAL must be INT';
}
}
if (isset($pattern['limit']) && !empty($pattern['limit'])) {
if (Validator::check($pattern['limit'], array('type' => 'INT'))) {
return 'wrong_pattern : limit of NUMERIC must be INT';
}
}
// check subject
if (get_magic_quotes_gpc()) {
$val = stripslashes($subject);
} else {
$val = $subject;
}
if ($check_type == 'VARCHAR') {
$val = strip_tags($val);
if (isset($pattern['min']) && !empty($pattern['min'])) {
$min = $pattern['min'];
} else {
$min = 0;
}
if (isset($pattern['max']) && !empty($pattern['max'])) {
$max = $pattern['max'];
} else {
$max = 2147483647;
}
if (strlen($val) < $min || strlen($val) > $max) {
return 'VARCHAR: min | max';
}
} elseif ($check_type == 'TEXT') {
$val = strip_tags($val);
if (isset($pattern['min']) && !empty($pattern['min'])) {
$min = $pattern['min'];
} else {
$min = 0;
}
if (isset($pattern['max']) && !empty($pattern['max'])) {
$max = $pattern['max'];
} else {
$max = 65535;
}
if (strlen($val) < $min || strlen($val) > $max) {
return 'TEXT: min | max';
}
} elseif ($check_type == 'HTML') {
} elseif ($check_type == 'INT') {
if (isset($pattern['signed']) && $pattern['signed']) {
$min = -2147483648.0;
$max = 2147483647;
} else {
$min = 0;
$max = 4294967295.0;
}
if (preg_match("/-/", substr($val, 1)) || preg_match("/[^0-9\\-]/", $val)) {
return '!INT';
}
if ($val < $min || $val > $max) {
return 'INT: min | max';
}
} elseif ($check_type == 'TINYINT') {
if (isset($pattern['signed']) && $pattern['signed']) {
$min = -128;
$max = 127;
} else {
$min = 0;
$max = 255;
}
if (preg_match("/-/", substr($val, 1)) || preg_match("/[^0-9\\-]/", $val)) {
return '!TINYINT';
}
//.........这里部分代码省略.........
示例15: update
/**
* update - update this ProjectTask in the database.
*
* @param string The summary of this task.
* @param string The detailed description of this task.
* @param int The Priority of this task.
* @param int The Hours estimated to complete this task.
* @param int The (unix) start date of this task.
* @param int The (unix) end date of this task.
* @param int The status_id of this task.
* @param int The category_id of this task.
* @param int The percentage of completion in integer format of this task.
* @param array An array of user_id's that are assigned this task.
* @param array An array of project_task_id's that this task depends on.
* @param int The GroupProjectID of a new subproject that you want to move this Task to.
* @param int The duration of the task in days.
* @param int The id of the parent task, if any.
* @return boolean success.
*/
function update($summary, $details, $priority, $hours, $start_date, $end_date, $status_id, $category_id, $percent_complete, &$assigned_arr, &$depend_arr, $new_group_project_id, $duration = 0, $parent_id = 0)
{
$has_changes = false;
// if any of the values passed is different from
$v = new Validator();
$v->check($summary, "summary");
$v->check($priority, "priority");
$v->check($hours, "hours");
$v->check($start_date, "start date");
$v->check($end_date, "end date");
$v->check($status_id, "status");
$v->check($category_id, "category");
if (!$v->isClean()) {
$this->setError($v->formErrorMsg("Must include "));
return false;
}
if (!$parent_id) {
$parent_id = 0;
}
if ($this->getParentID() != $parent_id) {
$has_changes = true;
}
if (!$duration) {
$duration = 0;
}
if ($this->getDuration() != $duration) {
$has_changes = true;
}
if (!$this->ProjectGroup->userIsAdmin()) {
$this->setPermissionDeniedError();
return false;
}
/*if ( ($this->getSummary() != $summary) || ($this->getDetails() != $details) ||
($this->getPriority() != $priority) || ($this->getHours() != $hours) ||
($this->getStartDate() != $start_date) || ($this->getEndDate() != $end_date) ||
($this->getStatusID() != $status_id) || ($this->getCategoryID() != $category_id) ||
($this->getPercentComplete() != $percent_complete) ) {
$has_changes = true;
}*/
db_begin();
//
// Attempt to move this Task to a new Subproject
// need to instantiate new ProjectGroup obj and test if it works
//
$group_project_id = $this->ProjectGroup->getID();
if ($new_group_project_id != $group_project_id) {
$newProjectGroup = new ProjectGroup($this->ProjectGroup->getGroup(), $new_group_project_id);
if (!is_object($newProjectGroup) || $newProjectGroup->isError()) {
$this->setError('ProjectTask: Could not move to new ProjectGroup' . $newProjectGroup->getErrorMessage());
db_rollback();
return false;
}
/* do they have perms for new ArtifactType?
if (!$newArtifactType->userIsAdmin()) {
$this->setPermissionDeniedError();
db_rollback();
return false;
}*/
//
// Now set ProjectGroup, Category, and Assigned to 100 in the new ProjectGroup
//
$status_id = 1;
$category_id = '100';
unset($assigned_to);
$assigned_to = array('100');
$this->ProjectGroup =& $newProjectGroup;
$this->addHistory('group_project_id', $group_project_id);
$has_changes = true;
}
if ($details) {
$has_changes = true;
if (!$this->addMessage($details)) {
db_rollback();
return false;
}
}
if ($this->getStatusID() != $status_id) {
$this->addHistory('status_id', $this->getStatusID());
$has_changes = true;
}
//.........这里部分代码省略.........