當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。