本文整理汇总了PHP中ValidationResult类的典型用法代码示例。如果您正苦于以下问题:PHP ValidationResult类的具体用法?PHP ValidationResult怎么用?PHP ValidationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ValidationResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: validate
public function validate(ValidationResult $validationResult)
{
if ($this->owner->ID > 0 && $this->hasTokenChanged()) {
$validationResult->combineAnd(new ValidationResult(false, _t('OptimisticLocking.NOSAVEREFRESH', "Save aborted as information has changed. Please refresh the page and try again.", 'User tried to save the dataobject but it had changed since they started working on it.')));
}
return $validationResult;
}
开发者ID:svandragt,项目名称:silverstripe-optimisticlocking,代码行数:7,代码来源:OptimisticLocking.php
示例2: validate
/**
* @param String $password
* @param Member $member
* @return ValidationResult
*/
public function validate($password, $member)
{
$valid = new ValidationResult();
if ($this->minLength) {
if (strlen($password) < $this->minLength) {
$valid->error(sprintf("Password is too short, it must be %s or more characters long.", $this->minLength), "TOO_SHORT");
}
}
if ($this->minScore) {
$score = 0;
$missedTests = array();
foreach ($this->testNames as $name) {
if (preg_match(self::$character_strength_tests[$name], $password)) {
$score++;
} else {
$missedTests[] = $name;
}
}
if ($score < $this->minScore) {
$valid->error("You need to increase the strength of your passwords by adding some of the following characters: " . implode(", ", $missedTests), "LOW_CHARACTER_STRENGTH");
}
}
if ($this->historicalPasswordCount) {
$previousPasswords = DataObject::get("MemberPassword", "\"MemberID\" = {$member->ID}", "\"Created\" DESC, \"ID\" Desc", "", $this->historicalPasswordCount);
if ($previousPasswords) {
foreach ($previousPasswords as $previousPasswords) {
if ($previousPasswords->checkPassword($password)) {
$valid->error("You've already used that password in the past, please choose a new password", "PREVIOUS_PASSWORD");
break;
}
}
}
}
return $valid;
}
开发者ID:normann,项目名称:sapphire,代码行数:40,代码来源:PasswordValidator.php
示例3: add
/**
* Add errors from a validation object
*
* @param ValidationResult $validation
* @param string $prefix
*/
public function add(ValidationResult $validation, $prefix = null)
{
$prefix = $this->translate($prefix);
foreach ($validation->getErrors() as $err) {
$this->errors[] = ($prefix ? trim($prefix) . ' ' : '') . $err;
}
}
开发者ID:jasny,项目名称:validation-result,代码行数:13,代码来源:ValidationResult.php
示例4: validate
/**
* Validate the owner object - check for existence of infinite loops.
*/
function validate(ValidationResult $validationResult)
{
if (!$this->owner->ID) {
return;
}
// The object is new, won't be looping.
if (!$this->owner->ParentID) {
return;
}
// The object has no parent, won't be looping.
if (!$this->owner->isChanged('ParentID')) {
return;
}
// The parent has not changed, skip the check for performance reasons.
// Walk the hierarchy upwards until we reach the top, or until we reach the originating node again.
$node = $this->owner;
while ($node) {
if ($node->ParentID == $this->owner->ID) {
// Hierarchy is looping.
$validationResult->error(_t('Hierarchy.InfiniteLoopNotAllowed', 'Infinite loop found within the "{type}" hierarchy. Please change the parent to resolve this', 'First argument is the class that makes up the hierarchy.', array('type' => $this->owner->class)), 'INFINITE_LOOP');
break;
}
$node = $node->ParentID ? $node->Parent() : null;
}
// At this point the $validationResult contains the response.
}
开发者ID:nomidi,项目名称:sapphire,代码行数:29,代码来源:Hierarchy.php
示例5: validate
/**
* @param String $password
* @param Member $member
* @return ValidationResult
*/
public function validate($password, $member)
{
$valid = new ValidationResult();
if ($this->minLength) {
if (strlen($password) < $this->minLength) {
$valid->error(sprintf(_t('PasswordValidator.TOOSHORT', 'Password is too short, it must be %s or more characters long'), $this->minLength), 'TOO_SHORT');
}
}
if ($this->minScore) {
$score = 0;
$missedTests = array();
foreach ($this->testNames as $name) {
if (preg_match(self::config()->character_strength_tests[$name], $password)) {
$score++;
} else {
$missedTests[] = _t('PasswordValidator.STRENGTHTEST' . strtoupper($name), $name, 'The user needs to add this to their password for more complexity');
}
}
if ($score < $this->minScore) {
$valid->error(sprintf(_t('PasswordValidator.LOWCHARSTRENGTH', 'Please increase password strength by adding some of the following characters: %s'), implode(', ', $missedTests)), 'LOW_CHARACTER_STRENGTH');
}
}
if ($this->historicalPasswordCount) {
$previousPasswords = DataObject::get("MemberPassword", "\"MemberID\" = {$member->ID}", "\"Created\" DESC, \"ID\" DESC", "", $this->historicalPasswordCount);
if ($previousPasswords) {
foreach ($previousPasswords as $previousPasswords) {
if ($previousPasswords->checkPassword($password)) {
$valid->error(_t('PasswordValidator.PREVPASSWORD', 'You\'ve already used that password in the past, please choose a new password'), 'PREVIOUS_PASSWORD');
break;
}
}
}
}
return $valid;
}
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:40,代码来源:PasswordValidator.php
示例6: authenticate_member
/**
* Attempt to find and authenticate member if possible from the given data.
*
* @param array $data
* @param Form $form
* @param bool &$success Success flag
* @return Member Found member, regardless of successful login
* @see MemberAuthenticator::authenticate_member()
*/
protected static function authenticate_member($data, $form, &$success)
{
// Default success to false
$success = false;
// Attempt to identify by temporary ID
$member = null;
$email = null;
if (!empty($data['tempid'])) {
// Find user by tempid, in case they are re-validating an existing session
$member = Member::member_from_tempid($data['tempid']);
if ($member) {
$email = $member->Email;
}
}
// Otherwise, get email from posted value instead
if (!$member && !empty($data['Email'])) {
$email = $data['Email'];
}
// Check default login (see Security::setDefaultAdmin()) the standard way and the "extension"-way :-)
$asDefaultAdmin = $email === Security::default_admin_username();
if ($asDefaultAdmin || isset($GLOBALS['_DEFAULT_ADMINS']) && array_key_exists($email, $GLOBALS['_DEFAULT_ADMINS'])) {
// If logging is as default admin, ensure record is setup correctly
$member = Member::default_admin();
$success = Security::check_default_admin($email, $data['Password']);
// If not already true check if one of the extra admins match
if (!$success) {
$success = $GLOBALS['_DEFAULT_ADMINS'][$email] == $data['Password'];
}
if ($success) {
return $member;
}
}
// Attempt to identify user by email
if (!$member && $email) {
// Find user by email
$member = Member::get()->filter(Member::config()->unique_identifier_field, $email)->first();
}
// Validate against member if possible
if ($member && !$asDefaultAdmin) {
$result = $member->checkPassword($data['Password']);
$success = $result->valid();
} else {
$result = new ValidationResult(false, _t('Member.ERRORWRONGCRED'));
}
// Emit failure to member and form (if available)
if (!$success) {
if ($member) {
$member->registerFailedLogin();
}
if ($form) {
$form->sessionMessage($result->message(), 'bad');
}
} else {
if ($member) {
$member->registerSuccessfulLogin();
}
}
return $member;
}
开发者ID:helpfulrobot,项目名称:level51-more-admins,代码行数:68,代码来源:MoreAdminsAuthenticator.php
示例7: validate
public function validate()
{
$result = new ValidationResult();
if (!$this->Title || !$this->Currency || !$this->Rate) {
$result->error('Please fill in all fields', 'ExchangeRateInvalidError');
}
return $result;
}
开发者ID:helpfulrobot,项目名称:mediabeast-silverstripe-shop-currency,代码行数:8,代码来源:ExchangeRate.php
示例8: validate
public function validate(\ValidationResult $validationResult)
{
$constraints = $this->getConstraints();
foreach ($constraints as $constraint) {
if (!$constraint->holds()) {
$validationResult->error($constraint->message());
}
}
}
开发者ID:helpfulrobot,项目名称:silverstripe-australia-silverstripe-constraints,代码行数:9,代码来源:ConstraintsExtension.php
示例9: validateData
public function validateData(Order $order, array $data)
{
$result = new ValidationResult();
//TODO: validate credit card data
if (!Helper::validateLuhn($data['number'])) {
$result->error('Credit card is invalid');
throw new ValidationException($result);
}
}
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:9,代码来源:OnsitePaymentCheckoutComponent.php
示例10: canLogIn
/**
* Check if the user has verified their email address.
*
* @param ValidationResult $result
* @return ValidationResult
*/
public function canLogIn(&$result)
{
if (!$this->owner->Verified) {
// Don't require administrators to be verified
if (Permission::checkMember($this->owner, 'ADMIN')) {
return $result;
}
$result->error(_t('MemberEmailVerification.ERROREMAILNOTVERIFIED', 'Sorry, you need to verify your email address before you can log in.'));
}
return $result;
}
开发者ID:jordanmkoncz,项目名称:silverstripe-memberemailverification,代码行数:17,代码来源:EmailVerificationMemberExtension.php
示例11: validate
public function validate(ValidationResult $validationResult)
{
$mailblockRecipients = $this->owner->getField('MailblockRecipients');
if (!$this->validateEmailAddresses($mailblockRecipients)) {
$validationResult->error(_t('Mailblock.RecipientError', 'There are invalid email addresses in the Recipient(s) field.'));
}
$whitelist = $this->owner->getField('MailblockWhitelist');
if (!$this->validateEmailAddresses($whitelist)) {
$validationResult->error(_t('Mailblock.WhitelistError', 'There are invalid email addresses in the Whitelist field.'));
}
}
开发者ID:signify-nz,项目名称:silverstripe-mailblock,代码行数:11,代码来源:MailblockSiteConfig.php
示例12: validateData
public function validateData(Order $order, array $data)
{
$result = new ValidationResult();
if (!isset($data['ShippingMethodID'])) {
$result->error(_t('ShippingCheckoutComponent.ShippingMethodNotProvidedMessage', "Shipping method not provided"), _t('ShippingCheckoutComponent.ShippingMethodErrorCode', "ShippingMethod"));
throw new ValidationException($result);
}
if (!ShippingMethod::get()->byID($data['ShippingMethodID'])) {
$result->error(_t('ShippingCheckoutComponent.ShippingMethodDoesNotExistMessage', "Shipping Method does not exist"), _t('ShippingCheckoutComponent.ShippingMethodErrorCode', "ShippingMethod"));
throw new ValidationException($result);
}
}
开发者ID:burnbright,项目名称:silverstripe-shop-shipping,代码行数:12,代码来源:ShippingCheckoutComponent.php
示例13: canLogIn
/**
* Check if the user has verified their email address.
*
* @param ValidationResult $result
* @return ValidationResult
*/
function canLogIn(&$result)
{
if (!Permission::check('ADMIN')) {
if (!$this->owner->Verified) {
$result->error(_t('EmailVerifiedMember.ERRORNOTEMAILVERIFIED', 'Please verify your email address before login.'));
}
if (!$this->owner->Moderated && $this->owner->requiresModeration()) {
$result->error(_t('EmailVerifiedMember.ERRORNOTMODERATED', 'A moderator needs to approve your account before you can log in.'));
}
}
return $result;
}
开发者ID:helpfulrobot,项目名称:exadium-emailverifiedmember,代码行数:18,代码来源:EmailVerifiedMember.php
示例14: validateData
public function validateData(Order $order, array $data)
{
$result = new ValidationResult();
if (!isset($data['PaymentMethod'])) {
$result->error("Payment method not provided", "PaymentMethod");
throw new ValidationException($result);
}
$methods = GatewayInfo::get_supported_gateways();
if (!isset($methods[$data['PaymentMethod']])) {
$result->error("Gateway not supported", "PaymentMethod");
throw new ValidationException($result);
}
}
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:13,代码来源:PaymentCheckoutComponent.php
示例15: testCombineResults
/**
* Test combining validation results together
*/
public function testCombineResults()
{
$result = new ValidationResult();
$anotherresult = new ValidationResult();
$yetanotherresult = new ValidationResult();
$anotherresult->error("Eat with your mouth closed", "EATING101");
$yetanotherresult->error("You didn't wash your hands", "BECLEAN");
$this->assertTrue($result->valid());
$this->assertFalse($anotherresult->valid());
$this->assertFalse($yetanotherresult->valid());
$result->combineAnd($anotherresult)->combineAnd($yetanotherresult);
$this->assertFalse($result->valid());
$this->assertEquals(array("EATING101" => "Eat with your mouth closed", "BECLEAN" => "You didn't wash your hands"), $result->messageList());
}
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:17,代码来源:ValidationExceptionTest.php
示例16: validateData
/**
* @param Order $order
* @param array $data
*
* @throws ValidationException
*/
public function validateData(Order $order, array $data)
{
$result = ValidationResult::create();
$existingID = !empty($data[$this->addresstype . "AddressID"]) ? (int) $data[$this->addresstype . "AddressID"] : 0;
if ($existingID) {
// If existing address selected, check that it exists in $member->AddressBook
if (!Member::currentUserID() || !Member::currentUser()->AddressBook()->byID($existingID)) {
$result->error("Invalid address supplied", $this->addresstype . "AddressID");
throw new ValidationException($result);
}
} else {
// Otherwise, require the normal address fields
$required = parent::getRequiredFields($order);
$addressLabels = singleton('Address')->fieldLabels(false);
foreach ($required as $fieldName) {
if (empty($data[$fieldName])) {
// attempt to get the translated field name
$fieldLabel = isset($addressLabels[$fieldName]) ? $addressLabels[$fieldName] : $fieldName;
$errorMessage = _t('Form.FIELDISREQUIRED', '{name} is required', array('name' => $fieldLabel));
$result->error($errorMessage, $fieldName);
throw new ValidationException($result);
}
}
}
}
开发者ID:NobrainerWeb,项目名称:silverstripe-shop,代码行数:31,代码来源:AddressBookCheckoutComponent.php
示例17: validateData
public function validateData(Order $order, array $data)
{
if (Member::currentUserID()) {
return;
}
$result = ValidationResult::create();
if (Checkout::membership_required() || !empty($data['Password'])) {
$member = Member::create($data);
$idfield = Member::config()->unique_identifier_field;
$idval = $data[$idfield];
if (ShopMember::get_by_identifier($idval)) {
// get localized field labels
$fieldLabels = $member->fieldLabels(false);
// if a localized value exists, use this for our error-message
$fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
$result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), $fieldLabel, $idval), $idval);
}
$passwordresult = $this->passwordvalidator->validate($data['Password'], $member);
if (!$passwordresult->valid()) {
$result->error($passwordresult->message(), "Password");
}
}
if (!$result->valid()) {
throw new ValidationException($result);
}
}
开发者ID:NobrainerWeb,项目名称:silverstripe-shop,代码行数:26,代码来源:MembershipCheckoutComponent.php
示例18: validateData
public function validateData(Order $order, array $data)
{
if (isset($data['RegisterAnAccount']) && $data['RegisterAnAccount']) {
return parent::validateData($order, $data);
}
return ValidationResult::create();
}
开发者ID:helpfulrobot,项目名称:milkyway-multimedia-ss-shop-checkout-extras,代码行数:7,代码来源:DependantMembershipCheckoutComponent.php
示例19: validate
/**
* Validate
* @return ValidationResult
**/
protected function validate()
{
$valid = true;
$message = null;
$result = ValidationResult::create($valid, $message);
return $result;
}
开发者ID:helpfulrobot,项目名称:silverstripe-australia-ba-sis,代码行数:11,代码来源:CustomMenuBlockItem.php
示例20: __construct
/**
* Construct a new ValidationException with an optional ValidationResult object
*
* @param ValidationResult|string $result The ValidationResult containing the
* failed result. Can be substituted with an error message instead if no
* ValidationResult exists.
* @param string|integer $message The error message. If $result was given the
* message string rather than a ValidationResult object then this will have
* the error code number.
* @param integer $code The error code number, if not given in the second parameter
*/
public function __construct($result = null, $message = null, $code = 0)
{
// Check arguments
if (!$result instanceof ValidationResult) {
// Shift parameters if no ValidationResult is given
$code = $message;
$message = $result;
// Infer ValidationResult from parameters
$result = new ValidationResult(false, $message);
} elseif (empty($message)) {
// Infer message if not given
$message = $result->message();
}
// Construct
$this->result = $result;
parent::__construct($message, $code);
}
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:28,代码来源:ValidationException.php
注:本文中的ValidationResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论