Source of file MinLengthConstraint.php
Size: 0,802 Bytes - Last Modified: 2021-12-23T10:26:26+00:00
/var/www/docs.ssmods.com/process/src/src/SilverStripeAustralia/Constraints/Constraints/MinLengthConstraint.php
1234567891011121314151617181920212223242526272829303132 | <?php namespace SilverStripeAustralia\Constraints\Constraints; use SilverStripeAustralia\Constraints\Constraint; /** * * * @author <marcus@silverstripe.com.au> * @license BSD License http://www.silverstripe.org/bsd-license */ class MinLengthConstraint extends Constraint { public function holds() { $length = $this->opt('length', 0); $convertNewlines = $this->opt('convertnewlines', 1); $val = $convertNewlines ? str_replace("\r\n", "\n", $this->getValue()) : $this->getValue(); return mb_strlen($val, 'utf-8') >= $length; } public function message() { $item = $this->fieldLabel(); $length = $this->opt('length', 0); $message = $this->opt('message', _t('Constraints.MIN_LENGTH', "%s must be at least %s characters long")); return sprintf($message, $item, $length); } } |