/*
Add form elements

@param  $key
@param  $rule set up your validation rule
@return $this
974695
public function addElement(string $type, string $key, array $array = []) : FormInterface
    {
        $array['type'] = $type;

        if ($type == 'openTag') {
            $key = $key.'_'.mt_rand(1, 2000);
        } elseif ($type == 'closeTag') {
            $key = $key.'_'.mt_rand(2000, 4000);
        }

        $this->value[$key] = $array;

        return $this;
    }
968172
public function add($key, $element): self
    {
        $callback = $this->callback;

        $this->index[$callback($element)] = $key;

        return $this;
    }
513981
public function addRules(array $rules)
    {
        foreach ($rules as $character => $replacement) {
            $this->addRule($character, $replacement);
        }

        return $this;
    }
237914
protected function addRequiredAttribute($rules)
    {
        if (!in_array('required', $rules)) {
            return;
        }

        if ($this instanceof Form\Field\MultipleFile
            || $this instanceof Form\Field\File) {
            return;
        }

        $this->required();
    }
972708
private function parseRule($rule, $input, $key)
    {
        $ruleExp = explode(':', $rule);
        if (count($ruleExp) > 1) {
            switch ($ruleExp[0]) {
                case 'match':
                $this->_errors[$key][] = $this->_parser->match($input, $key, $ruleExp[1], $this->_lang['match']);
                break;
                case 'min':
                $this->_errors[$key][] = $this->_parser->min($input, $key, $ruleExp[1], $this->_lang['min']);
                break;
                case 'max':
                $this->_errors[$key][] = $this->_parser->max($input, $key, $ruleExp[1], $this->_lang['max']);
                break;
                case 'from':
                $this->_errors[$key][] = $this->_parser->from($input, $key, $rule, $this->_lang['from']);
                break;
            }
        } else {
            switch ($rule) {
                case 'required':
                $this->_errors[$key][] = $this->_parser->required($input, $key, $this->_lang['required']);
                break;
                case 'email':
                $this->_errors[$key][] = $this->_parser->email($input, $key, $this->_lang['email']);
                break;
                case 'url':
                $this->_errors[$key][] = $this->_parser->url($input, $key, $this->_lang['url']);
                break;
            }
        }
    }
664076
public function validate($rule = null)
    {
        if (is_null($rule)) {
            throw $this->exception('Incorrect usage of field validation');
        }

        if (is_string($rule)) {
            // If string is passed, prefix with the field name
            $rule = $this->short_name.'|'.$rule;
        } elseif (is_array($rule)) {
            // if array is passed, prepend with the rule
            array_unshift($rule, $this->short_name);
            $rule = array($rule);
        } elseif (is_callable($rule)) {
            // callable or something else is passed. Wrap into array.
            $rule = array(array($this->short_name, $rule));
        }

        $this->form->validate($rule);

        return $this;
    }
1089922
public function add($element, $key = null)
    {
        if ($key == null) {
            $this->items[] = $element;

            return;
        }
        $this->set($key, $element);
    }
283592
public synchronized ValidationRuleStore addRule(ValidationRule rule) {
        rule.setOrderIdx(this.rules.size());
        this.rules.add(rule);
        this.checkHashMap.put(rule.getRuleName(), rule.getValidationCheck());
        return this;
    }
774126
protected function converterRules($rule, $keys = null) {
        if (is_integer($keys) && is_array($rule)) {
            $keys = array_shift($rule);
        }
        $rules = $this->converterRule($rule);
        $rules['keys'] = $keys;
        return $rules;
    }
750669
public function setFieldKeyFormat($format)
    {
        $this->validator->isFormatValid($format);
        $this->fieldKeyFormat = $format;
        return $this;
    }
846822
protected function extendValidator($rule)
    {
        $method = studly_case($rule);
        $translation = $this->app['translator']->trans('image-validator::validation.' . $rule);
        $this->app['validator']->extend($rule, 'Cviebrock\ImageValidator\ImageValidator@validate' . $method,
            $translation);
        $this->app['validator']->replacer($rule, 'Cviebrock\ImageValidator\ImageValidator@replace' . $method);
    }
1334654
protected function setValidationError($key, $val)
    {
        if (!in_array('submit', $val)) {
            // Is $validator is instance of ValidatorInterface and given key has error associated
            // then add a span tag below the input element and display error.
            if ($this->validator instanceof ValidatorInterface && $this->validator->hasError($key)) {
                $this->elements[self::$formHolder[self::$formName]][$key.'.error'] =
                    '<span class="'.$this->errorClass.'">'.$this->validator->getErrors($key).'</span>'.PHP_EOL;
            }
        }
    }
61645
protected function makeValidationRuleDataFromSpecialArraySyntax(array $rules, $key)
    {
        $data = new ValidationRuleData(
            array_get($rules, 'rules', []),
            array_get($rules, 'key', is_numeric($key) ? null : $key)
        );

        if (array_has($rules, 'translated')) {
            $data->setIsTranslated((bool) $rules['translated']);
        }

        if (array_has($rules, 'locale_index')) {

            // @codeCoverageIgnoreStart
            if ((int) $rules['locale_index'] < 1) {
                throw new UnexpectedValueException(
                    "Locale index for configured validation data cannot be less than 1 (key/index: {$key})"
                );
            }
            // @codeCoverageIgnoreEnd

            $data->setLocaleIndex((int) $rules['locale_index']);
        }

        return $data;
    }
1284206
public function setRules( $rules )
    {
        $this->rules = array();

        foreach ( $rules as $rule )
        {
            $this->addRule( $rule );
        }

        return $this;
    }
811599
public function addRules($rules, $append = true)
    {
        foreach ($rules as $key => $rule) {
            if (is_array($rule) && isset($rule['composition'])) {
                foreach ($rule['composition'] as $composition => $pattern) {
                    $rules[] = [
                        'pattern' => $pattern,
                        'route' => $composition.'/'.$rule['route'],
                    ];
                }
            }
        }

        return parent::addRules($rules, $append);
    }
144876
public function validationRules(array $rules = array())
    {
        if (empty($rules)) {
            return $this->validationRules;
        }

        $this->validationRules = $rules;

        return $this;
    }
621949
public function addAttribute($key, $value = null)
    {
        $this->element->addAttribute($key, $value);

        return $this;
    }