当前位置: 首页>>代码示例>>PHP>>正文


PHP ValidationResult类代码示例

本文整理汇总了PHP中ValidationResult的典型用法代码示例。如果您正苦于以下问题:PHP ValidationResult类的具体用法?PHP ValidationResult怎么用?PHP ValidationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ValidationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的ValidationResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。