/** * Add validation rules on the basis of ORM annotation mappings. * * @access private * @param Form\Field $oField * @param array $aMappings * @return bool * @since 1.0.0-alpha * @version 1.0.0-alpha */ private function addValidationByMapping(Form\Field &$oField, array $aMappings) { $iLength = Arrays::get($aMappings, 'length'); $sType = Arrays::get($aMappings, 'type'); // if there are no field mappings if (empty($aMappings) || $oField instanceof Form\Field\Hidden) { return FALSE; } // 'required' validation rule if (Arrays::get($aMappings, 'nullable', FALSE) === FALSE) { $oField->setRequired(); } // validation rules by type switch ($sType) { case 'string': if ($iLength !== NULL) { $oField->addRulesSet(RulesSetBuilder\String::factory()->max(':value', $iLength)); } break; case 'integer': if ($iLength !== NULL) { $oField->addRulesSet(RulesSetBuilder\Number::factory()->max(':value', $iLength)); } break; } return TRUE; }