本文整理汇总了PHP中Validator::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::isValid方法的具体用法?PHP Validator::isValid怎么用?PHP Validator::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validator
的用法示例。
在下文中一共展示了Validator::isValid方法的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: img_profil
public function img_profil($db, $user_id, $image, $path)
{
$validator = new Validator($_POST);
$validator->isSize($image, 'Votre photo est trop lourde.');
$validator->isExtension($image, 'Vous ne pouvez mettre que des fichiers avec les extensions suivantes : png, gif, jpg, jpeg.');
$uploadfile = basename($_FILES[$image]['name']);
$uploadfile = strtr($uploadfile, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$img = $path . $uploadfile;
if ($validator->isValid()) {
$this->field_img($db, $user_id, $img, $image);
move_uploaded_file($_FILES[$image]['tmp_name'], $img);
$info_user = $this->checkId($db, $user_id);
return $info_user->image = $img;
} else {
return $errors = $validator->getErrors();
}
}
示例3: validate
public function validate()
{
require_once 'validator.class.php';
$data = $_POST;
// $data = array(
// "emailId"=>"rbsuryawanshiindia@gmail.com",
// "password" => "",
// "fullName" => "",
// );
// define the rules
$rules = array("emailId" => "email", "password" => "require", "fullName" => "require");
$message = array("email" => array("require" => "Email Id is Required", "email" => 'Valid EmailId Only'), "password" => "Password is Required", "fullName" => "Full Name is Required");
$objValidator = new Validator($rules, $message);
if (!$objValidator->isValid($data)) {
return false;
} else {
return true;
}
}
示例4: Tweet
<?php
require_once '../autoload.php';
require_once '../include/results.php';
//rajouter order bye et condition si reply ou origine et recuper donner(function dans class)
$tweet = new Tweet($user_id);
// $tweet->getIdTweet();
/*var_dump($p = new Tweet($user_id, 2));
var_dump($p->getIdTweet());*/
// var_dump($p = new Tweet($user_id));
// var_dump($p->Tweet_follower($user_id));
if (isset($_FILES['file-input']) && !empty($_FILES['file-input']['name'])) {
$uploaddir = '../view/img-user/tweet/';
$validator = new Validator($_POST);
$validator->isSize('file-input', 'You picture is too oversized');
$validator->isExtension('file-input', 'You must upload a type of picture with png, gif, jpg, jpeg, please.');
$uploadfile = basename($_FILES['file-input']['name']);
$uploadfile = strtr($uploadfile, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$img_tweet = $uploaddir . $uploadfile;
if ($validator->isValid()) {
move_uploaded_file($_FILES['file-input']['tmp_name'], $img_tweet);
$tweet->newTweet($img_tweet);
/*$info_user->avatar = $avatar;*/
} else {
$errors = $validator->getErrors();
}
} else {
$tweet->newTweet();
}
require_once '../view/accueil.php';
示例5: getResult
/**
* @return bool
*/
protected function getResult()
{
return $this->validator->isValid($this->account);
}
示例6: getResult
/**
* @return bool
*/
protected function getResult()
{
return !is_null($this->validator) && $this->validator->isValid($this->account);
}
示例7: deleteUserGenericData
/**
* Delete one or more users.
* @param array $data user data
* @return array
*/
function deleteUserGenericData($data)
{
Debug::Arr($data, 'DataA: ', __FILE__, __LINE__, __METHOD__, 10);
if (is_numeric($data)) {
$data = array($data);
}
if (!is_array($data)) {
return $this->returnHandler(FALSE);
}
Debug::Text('Received data for: ' . count($data) . ' Users', __FILE__, __LINE__, __METHOD__, 10);
Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
$total_records = count($data);
$validator_stats = array('total_records' => $total_records, 'valid_records' => 0);
if (is_array($data)) {
foreach ($data as $key => $id) {
$primary_validator = new Validator();
$lf = TTnew('UserGenericDataListFactory');
$lf->StartTransaction();
if (is_numeric($id)) {
//Modifying existing object.
//Get user object, so we can only modify just changed data for specific records if needed.
$lf->getByUserIdAndId($this->getCurrentUserObject()->getId(), $id);
if ($lf->getRecordCount() == 1) {
//Object exists
Debug::Text('User Generic Data Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10);
$lf = $lf->getCurrent();
} else {
//Object doesn't exist.
$primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, generic data does not exist'));
}
} else {
$primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, generic data does not exist'));
}
//Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10);
$is_valid = $primary_validator->isValid();
if ($is_valid == TRUE) {
//Check to see if all permission checks passed before trying to save data.
Debug::Text('Attempting to delete user generic data...', __FILE__, __LINE__, __METHOD__, 10);
$lf->setDeleted(TRUE);
$is_valid = $lf->isValid();
if ($is_valid == TRUE) {
Debug::Text('User Deleted...', __FILE__, __LINE__, __METHOD__, 10);
$save_result[$key] = $lf->Save();
$validator_stats['valid_records']++;
}
}
if ($is_valid == FALSE) {
Debug::Text('User Generic Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10);
$lf->FailTransaction();
//Just rollback this single record, continue on to the rest.
if ($primary_validator->isValid() == FALSE) {
$validator[$key] = $primary_validator->getErrorsArray();
} else {
$validator[$key] = $lf->Validator->getErrorsArray();
}
}
$lf->CommitTransaction();
}
if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) {
if ($validator_stats['total_records'] == 1) {
return $this->returnHandler($save_result[$key]);
//Single valid record
} else {
return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats);
//Multiple valid records
}
} else {
return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats);
}
}
return $this->returnHandler(FALSE);
}
示例8: define
<?php
/// Copyright (c) 2004-2016, Needlworks / Tatter Network Foundation
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/documents/LICENSE, /documents/COPYRIGHT)
define('__TEXTCUBE_ADMINPANEL__', true);
require ROOT . '/library/preprocessor.php';
importlib('model.blog.comment');
$IV = array('POST' => array('name' => array('string', 'default' => ''), 'comment' => array('string', 'default' => ''), 'mode' => array(array('commit'), 'default' => ''), 'homepage' => array('string', 'default' => ''), 'password' => array('string', 'default' => ''), 'secret' => array(array('on'), 'default' => null)));
$context = Model_Context::getInstance();
$customIV = fireEvent('ManipulateIVRules', $IV, $context->getProperty('uri.interfaceRoute'));
Validator::addRule($customIV);
if (!Validator::isValid()) {
Respond::PrintResult(array('error' => 1, 'description' => 'Illegal parameters'));
}
requireStrictRoute();
if (!Setting::getBlogSettingGlobal('acceptComments', 0) && !doesHaveOwnership()) {
Respond::PrintResult(array('error' => 0, 'commentBlock' => '', 'recentCommentBlock' => ''));
exit;
}
$pool = DBModel::getInstance();
if ((doesHaveMembership() || !empty($_POST['name'])) && !empty($_POST['comment']) && !empty($_POST['mode']) && $_POST['mode'] == 'commit') {
if (!empty($_POST['name'])) {
setcookie('guestName', $_POST['name'], time() + 2592000, $context->getProperty('uri.blog') . "/");
}
if (!empty($_POST['homepage']) && $_POST['homepage'] != 'http://') {
if (strpos($_POST['homepage'], 'http://') === 0) {
setcookie('guestHomepage', $_POST['homepage'], time() + 2592000, $context->getProperty('uri.blog') . "/");
} else {
setcookie('guestHomepage', 'http://' . $_POST['homepage'], time() + 2592000, $context->getProperty('uri.blog') . "/");
}
示例9: Validator
include_once '../autoloader.php';
// Test data
$v = new Validator(['name' => 'asdfsdf', 'age' => '20', 'phone' => '123123', 'email' => 'aoidsf@213.com', 'password' => 'wang1@']);
// Validate one field with multiple rules
$v->validate('name', ['notEmpty', ['greaterThan', 100], ['between', 0, 20]]);
$v->validate('age', ['notEmpty', ['between', 0, 100]]);
//length validation
//equal validation
$v->validate('name', [['length', 7]]);
$v->validate('name', [['equal', true]]);
// Email
$v->email()->validate('age', [['EmailValidator', '123.com']]);
// Call additional validator
echo $v->address()->street(3) . '<br>';
// Use getKey method to validate key value
echo $v->phone()->phoneNumber('12345') . '<br>';
echo $v->phone()->phoneNumber($v->getKey('phone')) . '<br>';
echo 'street', $v->address()->validate('email', ['street']) . '<br>';
//password validation
echo $v->password()->password($v->getKey('password')) . '<br>';
// Errors
echo '<hr/>';
if ($v->isValid()) {
echo 'all valid';
} else {
echo 'error on age field: ';
$v->displayError('age');
echo 'All errors';
$v->displayErrorAll();
}
echo '<hr/>';
示例10: isValid
<?php
echo "welcome to VALIDATOR";
class Validator
{
private $pattern = "Sean";
function isValid($string)
{
if ($string == $this->pattern) {
return true;
} else {
return false;
}
}
}
$myValidator = new Validator();
if ($myValidator->isValid('Sean')) {
echo "You are valid";
} else {
echo "You are NOT valid!!!!";
}
示例11: Validator
if (preg_match($this->pattern, $string)) {
return true;
} else {
return false;
}
}
}
$puppyValidator = new Validator();
if (isset($_SESSION["dogs"])) {
$dogs = $_SESSION["dogs"];
}
if (isset($_POST["pup_name"])) {
$name = $_POST["pup_name"];
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($puppyValidator->isValid($name)) {
array_push($dogs, $name);
$_SESSION["dogs"] = $dogs;
} else {
$msg = "bad puppy name";
}
}
foreach ($dogs as $value) {
$list .= "<li>" . $value . "<button class='remove'>X</button>" . "</li>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
示例12: setLog
/**
* Set log data for one or more loges.
* @param array $data log data
* @return array
*/
function setLog($data, $validate_only = FALSE)
{
$validate_only = (bool) $validate_only;
if (!is_array($data)) {
return $this->returnHandler(FALSE);
}
if ($validate_only == TRUE) {
Debug::Text('Validating Only!', __FILE__, __LINE__, __METHOD__, 10);
}
extract($this->convertToMultipleRecords($data));
Debug::Text('Received data for: ' . $total_records . ' Logs', __FILE__, __LINE__, __METHOD__, 10);
Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
$validator_stats = array('total_records' => $total_records, 'valid_records' => 0);
if (is_array($data)) {
$this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records);
foreach ($data as $key => $row) {
$primary_validator = new Validator();
$lf = TTnew('LogListFactory');
$lf->StartTransaction();
//Can add log entries only.
unset($row['id']);
Debug::Arr($row, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
Debug::Text('Setting object data...', __FILE__, __LINE__, __METHOD__, 10);
$lf->setObjectFromArray($row);
//Force Company ID to current company.
$lf->setUser($this->getCurrentUserObject()->getId());
$is_valid = $lf->isValid();
if ($is_valid == TRUE) {
Debug::Text('Saving data...', __FILE__, __LINE__, __METHOD__, 10);
if ($validate_only == TRUE) {
$save_result[$key] = TRUE;
} else {
$save_result[$key] = $lf->Save();
}
$validator_stats['valid_records']++;
}
if ($is_valid == FALSE) {
Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10);
$lf->FailTransaction();
//Just rollback this single record, continue on to the rest.
if ($primary_validator->isValid() == FALSE) {
$validator[$key] = $primary_validator->getErrorsArray();
} else {
$validator[$key] = $lf->Validator->getErrorsArray();
}
}
$lf->CommitTransaction();
$this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
}
$this->getProgressBarObject()->stop($this->getAMFMessageID());
if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) {
if ($validator_stats['total_records'] == 1) {
return $this->returnHandler($save_result[$key]);
//Single valid record
} else {
return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats);
//Multiple valid records
}
} else {
return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats);
}
}
return $this->returnHandler(FALSE);
}
示例13: deleteRecurringScheduleControl
/**
* Delete one or more recurring_schedule_controls.
* @param array $data recurring_schedule_control data
* @return array
*/
function deleteRecurringScheduleControl($data)
{
if (is_numeric($data)) {
$data = array($data);
}
if (!is_array($data)) {
return $this->returnHandler(FALSE);
}
if (!$this->getPermissionObject()->Check('recurring_schedule', 'enabled') or !($this->getPermissionObject()->Check('recurring_schedule', 'delete') or $this->getPermissionObject()->Check('recurring_schedule', 'delete_own') or $this->getPermissionObject()->Check('recurring_schedule', 'delete_child'))) {
return $this->getPermissionObject()->PermissionDenied();
}
//Get Permission Hierarchy Children first, as this can be used for viewing, or editing.
$permission_children_ids = $this->getPermissionChildren();
Debug::Text('Received data for: ' . count($data) . ' RecurringScheduleControls', __FILE__, __LINE__, __METHOD__, 10);
Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
$total_records = count($data);
$validator_stats = array('total_records' => $total_records, 'valid_records' => 0);
if (is_array($data)) {
$this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records);
foreach ($data as $key => $tmp_id) {
$primary_validator = new Validator();
$lf = TTnew('RecurringScheduleControlListFactory');
$lf->StartTransaction();
//Need to support deleting the entire recurring schedule, or just one user from it.
if (is_array($tmp_id)) {
$id = $key;
$user_id = $tmp_id;
Debug::Arr($tmp_id, 'ID is an array, with User ID specified as well, deleting just this one user: ID: ' . $id . ' User IDs: ', __FILE__, __LINE__, __METHOD__, 10);
} else {
$id = $tmp_id;
$user_id = FALSE;
}
if (is_numeric($id)) {
//Modifying existing object.
//Get recurring_schedule_control object, so we can only modify just changed data for specific records if needed.
$lf->getByIdAndCompanyId($id, $this->getCurrentCompanyObject()->getId());
if ($lf->getRecordCount() == 1) {
//Object exists, check edit permissions
if ($this->getPermissionObject()->Check('recurring_schedule', 'delete') or $this->getPermissionObject()->Check('recurring_schedule', 'delete_own') and $this->getPermissionObject()->isOwner($lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID()) === TRUE or $this->getPermissionObject()->Check('recurring_schedule', 'delete_child') and $this->getPermissionObject()->isChild($user_id, $permission_children_ids) === TRUE) {
//if ( $this->getPermissionObject()->Check('recurring_schedule','delete')
// OR ( $this->getPermissionObject()->Check('recurring_schedule','delete_own') AND $this->getPermissionObject()->isOwner( $lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID() ) === TRUE ) ) {
Debug::Text('Record Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10);
$lf = $lf->getCurrent();
} else {
$primary_validator->isTrue('permission', FALSE, TTi18n::gettext('Delete permission denied'));
}
} else {
//Object doesn't exist.
$primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
}
} else {
$primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
}
//Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10);
$is_valid = $primary_validator->isValid();
if ($is_valid == TRUE) {
//Check to see if all permission checks passed before trying to save data.
Debug::Text('Attempting to delete record...', __FILE__, __LINE__, __METHOD__, 10);
if ($user_id > 0) {
//Remove this user_id from the user array.
$new_user_ids = array_diff((array) $lf->getUser(), (array) $user_id);
Debug::Arr($new_user_ids, 'Removing individual users from schedule, remaining users are: ', __FILE__, __LINE__, __METHOD__, 10);
if (count($new_user_ids) > 0) {
$lf->setUser($new_user_ids);
} else {
//No users left, delete the entire recurring schedule.
Debug::Text('No users left in schedule, removing entire schedule...', __FILE__, __LINE__, __METHOD__, 10);
$lf->setDeleted(TRUE);
}
unset($new_user_ids);
} else {
$lf->setDeleted(TRUE);
}
$is_valid = $lf->isValid();
if ($is_valid == TRUE) {
Debug::Text('Record Deleted...', __FILE__, __LINE__, __METHOD__, 10);
$save_result[$key] = $lf->Save();
$validator_stats['valid_records']++;
}
}
if ($is_valid == FALSE) {
Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10);
$lf->FailTransaction();
//Just rollback this single record, continue on to the rest.
if ($primary_validator->isValid() == FALSE) {
$validator[$key] = $primary_validator->getErrorsArray();
} else {
$validator[$key] = $lf->Validator->getErrorsArray();
}
}
$lf->CommitTransaction();
$this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
}
$this->getProgressBarObject()->stop($this->getAMFMessageID());
if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) {
//.........这里部分代码省略.........
示例14: doTestIsNotValid
protected function doTestIsNotValid(Validator $validator, $value, $errorMessages)
{
$this->assertFalse($validator->isValid($value));
$this->assertNotEquals(0, count($validator->getMessages()));
$this->assertEquals($errorMessages, $validator->getMessages());
}
示例15: deleteUserPreference
/**
* Delete one or more UserPreferences.
* @param array $data UserPreference data
* @return array
*/
function deleteUserPreference($data)
{
if (is_numeric($data)) {
$data = array($data);
}
if (!is_array($data)) {
return $this->returnHandler(FALSE);
}
if (!$this->getPermissionObject()->Check('user_preference', 'enabled') or !($this->getPermissionObject()->Check('user_preference', 'delete') or $this->getPermissionObject()->Check('user_preference', 'delete_own') or $this->getPermissionObject()->Check('user_preference', 'delete_child'))) {
return $this->getPermissionObject()->PermissionDenied();
}
Debug::Text('Received data for: ' . count($data) . ' UserPreferences', __FILE__, __LINE__, __METHOD__, 10);
Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
$total_records = count($data);
$validator_stats = array('total_records' => $total_records, 'valid_records' => 0);
if (is_array($data)) {
$this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records);
foreach ($data as $key => $id) {
$primary_validator = new Validator();
$lf = TTnew('UserPreferenceListFactory');
$lf->StartTransaction();
if (is_numeric($id)) {
//Modifying existing object.
//Get UserPreference object, so we can only modify just changed data for specific records if needed.
$lf->getByIdAndCompanyId($id, $this->getCurrentCompanyObject()->getId());
if ($lf->getRecordCount() == 1) {
//Object exists, check edit permissions
if ($this->getPermissionObject()->Check('user_preference', 'delete') or $this->getPermissionObject()->Check('user_preference', 'delete_own') and $this->getPermissionObject()->isOwner($lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID()) === TRUE) {
Debug::Text('Record Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10);
$lf = $lf->getCurrent();
} else {
$primary_validator->isTrue('permission', FALSE, TTi18n::gettext('Delete permission denied'));
}
} else {
//Object doesn't exist.
$primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
}
} else {
$primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
}
//Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10);
$is_valid = $primary_validator->isValid();
if ($is_valid == TRUE) {
//Check to see if all permission checks passed before trying to save data.
Debug::Text('Attempting to delete record...', __FILE__, __LINE__, __METHOD__, 10);
$lf->setDeleted(TRUE);
$is_valid = $lf->isValid();
if ($is_valid == TRUE) {
Debug::Text('Record Deleted...', __FILE__, __LINE__, __METHOD__, 10);
$save_result[$key] = $lf->Save();
$validator_stats['valid_records']++;
}
}
if ($is_valid == FALSE) {
Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10);
$lf->FailTransaction();
//Just rollback this single record, continue on to the rest.
if ($primary_validator->isValid() == FALSE) {
$validator[$key] = $primary_validator->getErrorsArray();
} else {
$validator[$key] = $lf->Validator->getErrorsArray();
}
}
$lf->CommitTransaction();
$this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
}
$this->getProgressBarObject()->stop($this->getAMFMessageID());
if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) {
if ($validator_stats['total_records'] == 1) {
return $this->returnHandler($save_result[$key]);
//Single valid record
} else {
return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats);
//Multiple valid records
}
} else {
return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats);
}
}
return $this->returnHandler(FALSE);
}