attachment form
@param  string $name
@param  string $value
@param  array  $settings
@return string
332849
static public function attachment($name, $value=null, $settings=[])
    {
        $settings['media_type'] = 'attachment';
        if (!isset($settings['preview_url'])) $settings['preview_url'] = Ioc::url('preview?metia_type=attachment');
        return static::image($name, $value, $settings);
    }
1135014
public function getFormValue(string $name, $default = null, string $separator = null)
    {
        $value = parent::getFormValue($name, null, $separator);

        if ($name === 'avatar') {
            return $this->parseFileProperty($value);
        }

        if (null === $value) {
            if ($name === 'media_order') {
                return implode(',', $this->getMediaOrder());
            }
        }

        return $value ?? $default;
    }
300267
static public function tuieditor($name, $value=null, $settings=array())
    {
        $form_id    = isset($settings['id']) ? static::formatId($settings['id']) : static::formatId($name);
        if (empty($value)) {
            $value = "### 编辑内容";
        }
        
        $defultSettings = array(
            'width'     => "100%",
            'height'    => "400",
        );
        $settings = array_merge($defultSettings, $settings);
        
        $str = "";
        
        $str .= <<<EOF
        <div id="tuieditor_box">

        </div>
EOF;
        // 此处动态加载有问题，不能直接运行脚本
        if (!isset(static::$isLoaded['tuieditor']) || !static::$isLoaded['tuieditor']) {
            $base_url = Config::getRootUrl() . '/static/tui-editor';
            $str .= <<<EOF
<link rel="stylesheet" type="text/css" href="${base_url}/dist/tui-editor.min.css" />
<link rel="stylesheet" type="text/css" href="${base_url}/dist/tui-editor-contents.min.css" />
<script type="text/javascript">
require(["tui-editor"], function () {
    var editor = new Editor({
        el: document.querySelector('#tuieditor_box'),
        initialEditType: 'markdown',
        previewStyle: 'vertical',
        height: '400px'
    });
});

/*
$(function () {
    var editor = new tui.Editor({
        el: document.querySelector('#tuieditor_box'),
        initialEditType: 'markdown',
        previewStyle:    'vertical',
        height:          '400px'
    });
});
*/
</script>
EOF;
            static::$isLoaded['tuieditor'] = true;
        }
        
        return $str;
    }
1213398
public function mergeAttachmentOptions(array $settings)
    {
        // Make sure default options are loaded.
        if ($this->attachmentOptions === null) {
            $this->attachmentOptions();
        }

        $this->attachmentOptions = array_merge(
            $this->attachmentOptions,
            $this->parseAttachmentOptions($settings)
        );

        return $this;
    }
85119
public function checkbox($name = null, $value = null, $items = array()) 
	{
		Argument::i()
			->test(1, 'string', 'null')
			->test(2, 'scalar', 'array', 'null')
			->test(3, 'string', 'array');
		
		$field = Checkbox::i()->setItems($items);
		
		if(!is_null($name)) {
			$field->setName($name);
		}
		
		if(!is_null($value)) {
			$field->setValue($value);
		}
		
		return $field;
	}
1236813
protected static function formatFieldValue($name, $value) {
		$field	= static::$validator->getField($name);
		if( $field ) {
			$field->getType()->formatValue($field, $value);
		}
		return parent::formatFieldValue($name, $value);
	}
378393
static public function textarea($name, $value=null, $settings=[])
    {
        $settings = static::formatSettings($settings);
        $settings['class'] = isset($settings['class']) ? $settings['class'] . ' form-control' : ' form-control';
        $settings['id'] = isset($settings['id']) ? static::formatId($settings['id']) : static::formatId($name);
        
        $str = '<textarea name="' . $name . '" style="min-height:100px;"';
        foreach($settings as $k => $v) {
            if (in_array($k, array('class', 'id', 'readonly', 'rows', 'style', 'placeholder'))) {
                $str .= " $k=\"$v\"";
            }
        }
        $str .= '>';
        $str .= (isset($value) ? trim($value) : '') . '</textarea>' . PHP_EOL;
        return $str;
    }
820613
protected static function parseFieldValue($name, $value) {
		$field	= static::$validator->getField($name);
		if( $field ) {
			$field->getType()->parseValue($field, $value);
		}
		return parent::parseFieldValue($name, $value);
	}
135998
public function button($name, $value = null, $attributes = null)
    {
        return '<input type="button" name="'.$name.'" '.(($attributes !== null) ? $this->attributes($attributes) : "").' value="'.$this->getValue($name, $value).'" />';
    }
1173613
public function submit($name, $value = null, $attributes = null)
    {
        return '<input type="submit" name="'.$name.'" '.(($attributes !== null) ? $this->attributes($attributes) : "").' value="'.$this->getValue($name, $value).'" />';
    }
383961
public static function insert(String $name = NULL, $value = NULL) : Bool
    {
        $name  = self::$settings['name']  ?? $name;
        $input = self::$settings['input'] ?? false;
        $value = self::$settings['value'] ?? $value;

        self::$settings = [];

        return Method::$input($name, $value);
    }
991297
public static function submit($name, $value, array $attributes = null)
    {
        // Set the input type
        $attributes['type'] = 'submit';

        return Form::input($name, $value, $attributes);
    }
1110139
public function setHeader(string $name, $value, bool $append = false)
    {
        if (!$name || \preg_match('#[^a-z0-9-]#i', $name)) {
            throw new InvalidArgumentException("Header name must be non-empty alphanumeric string, '$name' given.");
        }

        if ($value == null) { // intentionally ==
            if (!$append) {
                unset($this->headers[$name]);
            }

        } elseif (\is_array($value)) { // email
            $tmp = &$this->headers[$name];
            if (!$append || !\is_array($tmp)) {
                $tmp = [];
            }

            foreach ($value as $email => $recipient) {
                if ($recipient === null) {
                    // continue
                } elseif (!Strings::checkEncoding($recipient)) {
                    if (!\preg_match('##u', $recipient)) {
                        throw new InvalidArgumentException('Name is not valid unicode string.');
                    }
                } elseif (\preg_match('#[\r\n]#', $recipient)) {
                    throw new InvalidArgumentException('Name must not contain line separator.');
                }

                if (!\filter_var($email, \FILTER_VALIDATE_EMAIL)) {
                    throw new InvalidArgumentException('Name must match the email structure.');
                }

                $tmp[$email] = $recipient;
            }

        } else {
            $value = (string) $value;
            if (!Strings::checkEncoding($value)) {
                throw new InvalidArgumentException('Header is not valid UTF-8 string.');
            }
            $this->headers[$name] = \preg_replace('#[\r\n]+#', ' ', $value);
        }

        return $this;
    }
105256
public function label( $name, $value = null, $options = [] ) {
		$this->labels[] = $name;

		$value = $this->format_label( $name, $value );

		return $this->to_html_string( '<label for="' . $name . '"' . $this->attributes( $options ) . '>' . $value . '</label>' );
	}
700178
static public function auto($name, $value=null, $settings=[])
    {
        !isset($settings['form_type']) && $settings['form_type'] = 'text';
        if (isset($settings['with_multi']) && $settings['with_multi']) {
            $method = 'multi';
        } else {
            $method = $settings['form_type'];
        }
        
        return call_user_func_array(get_called_class() . '::' . $method, [$name, $value, $settings]);
    }
174465
public function addAttribute($name, $value)
    {
        if ($name === 'class') {
            $this->addAttributeClass($value);
        } elseif ($name === 'style') {
            $value = rtrim($value, ';') . ';';
            $value = explode(';', $value);
            $value = array_filter($value);

            foreach ($value as $style) {
                if (preg_match_all("/(.*)(: )(.*)/", $style, $match)) {
                    $this->addAttributeStyle($match[ 1 ][ 0 ], $match[ 3 ][ 0 ]);
                } elseif (preg_match_all("/(.*)(:)(.*)/", $style, $match)) {
                    $this->addAttributeStyle($match[ 1 ][ 0 ], $match[ 3 ][ 0 ]);
                }
            }
        } elseif (is_string($value)) {
            $this->storage[ $name ] = trim($value);
        } else {
            $this->storage[ $name ] = $value;
        }

        return $this;
    }
353116
protected function processArrayValue(
        array $value,
        array $settings,
        /*# bool */ $between = false
    )/*# : string */ {
        if ($between) {
            $v1 = $this->processValue($value[0], $settings);
            $v2 = $this->processValue($value[1], $settings);
            return $v1 . ' AND ' . $v2;
        } else {
            $result = [];
            foreach ($value as $val) {
                $result[] = $this->processValue($val, $settings);
            }
            return '(' . join(', ', $result) . ')';
        }
    }