Overview

Namespaces

  • None
  • PHP
  • Wei
    • Validator

Classes

  • All
  • AllOf
  • Alnum
  • Alpha
  • BaseValidator
  • Between
  • Blank
  • Callback
  • CharLength
  • Chinese
  • Color
  • Contains
  • CreditCard
  • Date
  • DateTime
  • Decimal
  • Digit
  • Dir
  • DivisibleBy
  • DoubleByte
  • Email
  • EndsWith
  • EqualTo
  • Exists
  • FieldExists
  • File
  • GreaterThan
  • GreaterThanOrEqual
  • IdCardCn
  • IdCardHk
  • IdCardMo
  • IdCardTw
  • IdenticalTo
  • Image
  • In
  • Ip
  • Length
  • LessThan
  • LessThanOrEqual
  • Lowercase
  • Luhn
  • MaxLength
  • MinLength
  • MobileCn
  • NaturalNumber
  • NoneOf
  • Null
  • Number
  • OneOf
  • Password
  • Phone
  • PhoneCn
  • PlateNumberCn
  • PositiveInteger
  • PostcodeCn
  • Present
  • QQ
  • RecordExists
  • Regex
  • Required
  • SomeOf
  • StartsWith
  • Time
  • Tld
  • Type
  • Uppercase
  • Url
  • Uuid
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Wei Framework
 4:  *
 5:  * @copyright   Copyright (c) 2008-2013 Twin Huang
 6:  * @license     http://opensource.org/licenses/mit-license.php MIT License
 7:  */
 8: 
 9: namespace Wei\Validator;
10: 
11: /**
12:  * Check if the length (or size) of input is lower than specified length
13:  *
14:  * @author      Twin Huang <twinhuang@qq.com>
15:  */
16: class MaxLength extends Length
17: {
18:     protected $tooLongMessage = '%name% must have a length lower than %max%';
19: 
20:     protected $tooManyMessage = '%name% must contain no more than %max% items';
21: 
22:     protected $max;
23: 
24:     /**
25:      * {@inheritdoc}
26:      */
27:     public function __invoke($input, $max = null, $__ = null)
28:     {
29:         $max && $this->storeOption('max', $max);
30: 
31:         return $this->isValid($input);
32:     }
33: 
34:     /**
35:      * {@inheritdoc}
36:      */
37:     protected function doValidate($input)
38:     {
39:         if (false === ($len = $this->getLength($input))) {
40:             $this->addError('notDetected');
41:             return false;
42:         }
43: 
44:         if ($this->max < $len) {
45:             $this->addError(is_scalar($input) ? 'tooLong' : 'tooMany');
46:             return false;
47:         }
48: 
49:         return true;
50:     }
51: }
52: 
Wei Framework API documentation generated by ApiGen