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 input is equals to (==) the specified value
13:  *
14:  * @author      Twin Huang <twinhuang@qq.com>
15:  */
16: class EqualTo extends BaseValidator
17: {
18:     protected $invalidMessage = '%name% must be equals %value%';
19: 
20:     protected $negativeMessage = '%name% must not be equals %value%';
21: 
22:     /**
23:      * The value to be compared
24:      *
25:      * @var mixed
26:      */
27:     protected $value;
28: 
29:     /**
30:      * {@inheritdoc}
31:      */
32:     public function __invoke($input, $value = null)
33:     {
34:         // Sets $this->equals only when the second argument provided
35:         func_num_args() > 1 && $this->storeOption('value', $value);
36: 
37:         return $this->isValid($input);
38:     }
39: 
40:     /**
41:      * {@inheritdoc}
42:      */
43:     protected function doValidate($input)
44:     {
45:         if (!$this->doCompare($input)) {
46:             $this->addError('invalid');
47:             return false;
48:         }
49:         return true;
50:     }
51: 
52:     /**
53:      * Compare input and option value
54:      *
55:      * @param mixed $input
56:      * @return bool
57:      */
58:     protected function doCompare($input)
59:     {
60:         return $input == $this->value;
61:     }
62: }
63: 
Wei Framework API documentation generated by ApiGen