| 12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace yiins\components;
- use CModel;
- use yiins\exceptions\InvalidValueException;
- class EnumValidator extends \CValidator
- {
- public $enumClass;
- public $useStrictMode = true;
- /**
- * Validates a single attribute.
- * This method should be overridden by child classes.
- * @param CModel $object the data object being validated
- * @param string $attribute the name of the attribute to be validated.
- */
- protected function validateAttribute($object, $attribute)
- {
- $className = $this->enumClass;
- try {
- new $className($object->$attribute, $this->useStrictMode);
- } catch (InvalidValueException $e) {
- $this->addError($object, $attribute, $e->getMessage());
- } catch (\UnexpectedValueException $e) {
- $this->addError($object, $attribute, $e->getMessage());
- }
- }
- }
|