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


PHP ValidationResult::error方法代码示例

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


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

示例1: 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

示例2: create

 /**
  * Create member account from data array.
  * Data must contain unique identifier.
  *
  * @throws ValidationException
  * @param $data - map of member data
  * @return Member|boolean - new member (not saved to db), or false if there is an error.
  */
 public function create($data)
 {
     $result = new ValidationResult();
     if (!Checkout::member_creation_enabled()) {
         $result->error(_t("Checkout.MEMBERSHIPSNOTALLOWED", "Creating new memberships is not allowed"));
         throw new ValidationException($result);
     }
     $idfield = Config::inst()->get('Member', 'unique_identifier_field');
     if (!isset($data[$idfield]) || empty($data[$idfield])) {
         $result->error(sprintf(_t("Checkout.IDFIELDNOTFOUND", "Required field not found: %s"), $idfield));
         throw new ValidationException($result);
     }
     if (!isset($data['Password']) || empty($data['Password'])) {
         $result->error(_t("Checkout.PASSWORDREQUIRED", "A password is required"));
         throw new ValidationException($result);
     }
     $idval = $data[$idfield];
     if (ShopMember::get_by_identifier($idval)) {
         $result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), _t("Member." . $idfield, $idfield), $idval));
         throw new ValidationException($result);
     }
     $member = new Member(Convert::raw2sql($data));
     $validation = $member->validate();
     if (!$validation->valid()) {
         //TODO need to handle i18n here?
         $result->error($validation->message());
     }
     if (!$result->valid()) {
         throw new ValidationException($result);
     }
     return $member;
 }
开发者ID:renskorswagen,项目名称:silverstripe-shop,代码行数:40,代码来源:ShopMemberFactory.php

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: validate

 public function validate(ValidationResult $valid)
 {
     if (!$valid->valid()) {
         return $valid;
     }
     if (empty($this->owner->Title)) {
         return $valid->error('Title is empty!');
     }
     if (intval($this->owner->ReleaseID) === 0) {
         return $valid->error('You must select a release');
     }
     if (intval($this->owner->CuratorID) === 0) {
         return $valid->error('You must select a Curator');
     }
     return $valid;
 }
开发者ID:Thingee,项目名称:openstack-org,代码行数:16,代码来源:OpenStackSampleConfigAdminUI.php

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: validateData

 public function validateData(Order $order, array $data)
 {
     $result = new ValidationResult();
     $code = $data['Code'];
     if ($this->validwhenblank && !$code) {
         return $result;
     }
     //check the coupon exists, and can be used
     if ($coupon = OrderCoupon::get_by_code($code)) {
         if (!$coupon->validateOrder($order, array("CouponCode" => $code))) {
             $result->error($coupon->getMessage(), "Code");
             throw new ValidationException($result);
         }
     } else {
         $result->error(_t("OrderCouponModifier.NOTFOUND", "Coupon could not be found"), "Code");
         throw new ValidationException($result);
     }
     return $result;
 }
开发者ID:helpfulrobot,项目名称:silvershop-discounts,代码行数:19,代码来源:CouponCheckoutComponent.php

示例14: 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

示例15: validate

 /**
  *	Confirm that the tag has been given a title and doesn't already exist.
  */
 public function validate(ValidationResult $result)
 {
     // Determine the field to use, based on the configuration defined tag types.
     $validate = 'Title';
     $class = $this->owner->ClassName;
     foreach (Config::inst()->get('FusionService', 'custom_tag_types') as $type => $field) {
         if ($type === $class) {
             $validate = $field;
         }
     }
     // Confirm that the tag has been given a title and doesn't already exist.
     if ($result->valid() && !$this->owner->{$validate}) {
         $result->error("\"{$validate}\" required!");
     } else {
         if ($result->valid() && $class::get_one($class, array('ID != ?' => $this->owner->ID, "LOWER({$validate}) = ?" => strtolower($this->owner->{$validate})))) {
             $result->error('Tag already exists!');
         }
     }
     // Allow extension.
     $this->owner->extend('validateFusionExtension', $result);
     return $result;
 }
开发者ID:nglasl,项目名称:silverstripe-fusion,代码行数:25,代码来源:FusionExtension.php


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