'No dependent field set', self::IS_EMPTY => 'This is a required field', ); public function __construct($dependentFieldName = null) { if (null !== $dependentFieldName) { $this->setDependentFieldName($dependentFieldName); } } public function setDependentFieldName($fieldName) { $this->_dependentFieldName = (string)$fieldName; return $this; } public function getDependentFieldName() { return $this->_dependentFieldName; } public function isValid($value, $context = null) { $value = (string)$value; $this->_setValue($value); $dependentFieldName = $this->getDependentFieldName(); if (empty($dependentFieldName)) { $this->_error(self::MISSING_FIELD_NAME); return false; } $dependentFieldValue = ''; if (is_array(($context))) { $dependentFieldValue = $context[$dependentFieldName]; } else if (is_string($context)) { $dependentFieldValue = $context; } if (empty($dependentFieldValue)) { return true; } if (empty($value)) { $this->_error(self::IS_EMPTY); return false; } return true; } }