/** * Sets the element that will be validated by this rule * * @param HTML_QuickForm2_Container Container to validate * @throws HTML_QuickForm2_InvalidArgumentException if trying to use * this Rule on something that isn't a Container */ public function setOwner(HTML_QuickForm2_Node $owner) { if (!$owner instanceof HTML_QuickForm2_Container) { throw new HTML_QuickForm2_InvalidArgumentException('Each Rule can only validate Containers, ' . get_class($owner) . ' given'); } parent::setOwner($owner); }
/** * Sets the element that will be validated by this rule * * @param HTML_QuickForm2_Element_InputFile File upload field to validate * @throws HTML_QuickForm2_InvalidArgumentException if trying to use * this Rule on something that isn't a file upload field */ public function setOwner(HTML_QuickForm2_Node $owner) { if (!$owner instanceof HTML_QuickForm2_Element_InputFile) { throw new HTML_QuickForm2_InvalidArgumentException('MaxFileSize Rule can only validate file upload fields, ' . get_class($owner) . ' given'); } parent::setOwner($owner); }
/** * Adds a validation rule * * @param HTML_QuickForm2_Rule|string $rule Validation rule or rule type * @param string|int $messageOrRunAt If first parameter is rule type, * then message to display if validation fails, otherwise constant showing * whether to perfom validation client-side and/or server-side * @param mixed $options Configuration data for the rule * @param int $runAt Whether to perfom validation * server-side and/or client side. Combination of * HTML_QuickForm2_Rule::SERVER and HTML_QuickForm2_Rule::CLIENT constants * * @return HTML_QuickForm2_Rule The added rule * @throws HTML_QuickForm2_InvalidArgumentException if $rule is of a * wrong type or rule name isn't registered with Factory * @throws HTML_QuickForm2_NotFoundException if class for a given rule * name cannot be found */ public function addRule($rule, $messageOrRunAt = '', $options = null, $runAt = HTML_QuickForm2_Rule::SERVER) { if ($rule instanceof HTML_QuickForm2_Rule) { $rule->setOwner($this); $runAt = '' == $messageOrRunAt ? HTML_QuickForm2_Rule::SERVER : $messageOrRunAt; } elseif (is_string($rule)) { $rule = HTML_QuickForm2_Factory::createRule($rule, $this, $messageOrRunAt, $options); } else { throw new HTML_QuickForm2_InvalidArgumentException('addRule() expects either a rule type or ' . 'a HTML_QuickForm2_Rule instance'); } $this->rules[] = array($rule, $runAt); return $rule; }