格式化并补全属性定义数组.

@param array $attribute

@return array
551330
public static function normalizeAttribute(array $attribute)
    {
        $defaults = [
            // 是否允许为空
            'allow_null' => false,

            // 安全特性
            // 是否允许内容包含html/xml tag
            'allow_tags' => false,

            // 是否自动生成属性值，例如mysql里面的auto increase
            'auto_generate' => false,

            // 默认值
            'default' => null,

            // 标记为“废弃”属性
            'deprecated' => false,

            // 正则表达式检查
            'regexp' => null,

            // 是否主键
            'primary_key' => false,

            // 安全特性
            // 标记为protected的属性会在输出时被自动忽略
            // 避免不小心把敏感数据泄漏到客户端
            'protected' => false,

            // 保存之后不允许修改
            'refuse_update' => false,

            // 安全特性
            // 标记为strict的属性只能在严格开关被打开的情况下才能够赋值
            // 避免不小心被误修改到
            'strict' => null,

            // 数据类型
            'type' => null,
        ];

        $type = isset($attribute['type']) ? $attribute['type'] : null;

        if (isset($attribute['pattern'])) {
            $attribute['regexp'] = $attribute['pattern'];
            unset($attribute['pattern']);
        }

        $attribute = array_merge(
            $defaults,
            self::factory($type)->normalizeAttribute($attribute)
        );

        if ($attribute['allow_null']) {
            $attribute['default'] = null;
        }

        if ($attribute['primary_key']) {
            $attribute['allow_null'] = false;
            $attribute['refuse_update'] = true;
            $attribute['strict'] = true;
        }

        if ($attribute['protected'] && $attribute['strict'] === null) {
            $attribute['strict'] = true;
        }

        return $attribute;
    }
1209081
public static function attributes(array $attributes)
    {
        // 对属性进行排序
        $sorted = [];
        foreach (self::$attributeOrder as $key)
        {
            if (isset($attributes[$key]))
            {
                $sorted[$key] = $attributes[$key];
            }
        }
        // 再合并
        $attributes = $sorted + $attributes;

        $compiled = '';
        foreach ($attributes as $key => $value)
        {
            if (null === $value)
            {
                continue;
            }

            $compiled .= ' ' . strtolower($key);

            if ($value)
            {
                $compiled .= '="' . self::chars($value) . '"';
            }
        }

        return $compiled;
    }
897165
public function attributes(array $attributes)
    {
        foreach ($attributes as $attribute => &$data) {
            $data = implode(' ', (array) $data);
            $data = $attribute . '="' . htmlspecialchars($data, ENT_QUOTES, 'UTF-8') . '"';
        }

        return empty($attributes) ? '' : ' ' . implode(' ', $attributes);
    }
940864
protected function getAttributeId($attribute)
	{
		return isset($this->htmlOptions['id'])
			? $this->htmlOptions['id']
			: CHtml::getIdByName(CHtml::resolveName($this->model, $attribute));
	}
1288171
protected function getExplicitKeys($attribute)
    {
        $pattern = str_replace('\*', '([^\.]+)', preg_quote($this->getPrimaryAttribute($attribute), '/'));

        if (preg_match('/^'.$pattern.'/', $attribute, $keys)) {
            array_shift($keys);

            return $keys;
        }

        return [];
    }
715090
public function getAttribute($attribute)
    {
        switch ($attribute) {
            case self::PROPEL_ATTR_CACHE_PREPARES:
                return $this->cachePreparedStatements;
                break;
            case self::PROPEL_ATTR_CONNECTION_NAME:
                return $this->connectionName;
                break;
            default:
                return parent::getAttribute($attribute);
        }
    }
495107
public function getValuesFor($attributes)
	{
		$ret = array();
		foreach ($attributes as $name) {
			if (array_key_exists($name, $this->_attributes)) {
				$ret[$name] = $this->_attributes[$name];
			}
		}
		return $ret;
	}
1368482
public function getSetterInnerValidationCodeLines(PHPAttribute $attribute)
    {
        $lines = [];

        if (null === $attribute->getPhpParameterType()) {
            if ('boolean' === $attribute->getPhpType()) {
                if (!$attribute->getNull()) {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['boolean']));
                } else {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['boolean', 'null']));
                }
            } elseif ('integer' === $attribute->getPhpType()) {
                if (!$attribute->getNull()) {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['integer']));
                } else {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['integer', 'null']));
                }
            } elseif ('float' === $attribute->getPhpType()) {
                if (!$attribute->getNull()) {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['float']));
                } else {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['float', 'null']));
                }
            } elseif ('string' === $attribute->getPhpType()) {
                if ('string' === $attribute->getType()) {
                    if (!$attribute->getNull()) {
                        $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string']));

                        if (null !== $attribute->getMinSize()) {
                            $lines[] = '';

                            $lines[] = 'if (strlen($' . $attribute->getLowerFullName() . ') < ' . $attribute->getMinSize() . ') {';
                            $lines[] =     'throw new \InvalidArgumentException(\'On the attribute ' . $attribute->getLowerFullName() . ', the length of the string \' . $' . $attribute->getLowerFullName() . ' . \' is \' . strlen($' . $attribute->getLowerFullName() . ') . \' which is shorter than the minimum allowed (' . $attribute->getMinSize() . ').\');';
                            $lines[] = '}';
                        }
                    } else {
                        $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string', 'null']));

                        if (null !== $attribute->getMinSize()) {
                            $lines[] = '';

                            $lines[] = 'if (strlen($' . $attribute->getLowerFullName() . ') < ' . $attribute->getMinSize() . ') {';
                            $lines[] =     'throw new \InvalidArgumentException(\'On the attribute ' . $attribute->getLowerFullName() . ', the length of the string \' . $' . $attribute->getLowerFullName() . ' . \' is \' . strlen($' . $attribute->getLowerFullName() . ') . \' which is shorter than the minimum allowed (' . $attribute->getMinSize() . ').\');';
                            $lines[] = '}';
                        }
                    }
                } elseif ('text' === $attribute->getType()) {
                    if (!$attribute->getNull()) {
                        $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string']));
                    } else {
                        $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string', 'null']));
                    }
                }
            } elseif ('OneToOne' === $attribute->getForeign()) {
                if ($attribute->getOwnerSide()) {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => $attribute->getForeignEntity()->getName()], 'null']));
                } else {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => $attribute->getForeignEntity()->getName()], 'null']));
                }
            }elseif ('ManyToOne' === $attribute->getForeign()) {
                if ($attribute->getOwnerSide()) {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => $attribute->getForeignEntity()->getName()], 'null']));
                } else {
                    $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => 'Collection'], 'null']));
                }
            }
        }

        return $lines;
    }
187187
protected function validateAttribute($object, $attribute)
    {
        $value = $object->{$attribute};
        if ($this->isEmpty($value)) {
            $this->validateEmpty($object, $attribute);
            return;
        }
        if (!is_array($this->range)) {
            throw new Exception('属性"range"必须定义为数组', 101400301);
        }

        if (is_array($value)) {
            $noIn = [];
            foreach ($value as $v) {
                if (false === $this->inArray($v)) {
                    $noIn[] = $v;
                }
            }
            $isIn = empty($noIn);
        } else {
            $isIn = $this->inArray($value);
        }

        if (!$isIn) {
            $this->addError($object, $attribute, $this->message);
            return;
        }
    }
990370
protected function parseAttributes(array $attributes)
    {
        $result = [];

        foreach ($attributes as $attribute => $value) {
            $result[$this->parseConstantValue($attribute)] = $value;
        }

        return $result;
    }
51825
public function validateEmails($attribute)
    {
        $items = $this->$attribute;

        if (!is_array($items)) {
            $items = [];
        }

        foreach ($items as $index => $item) {
            $validator = new EmailValidator();
            $error = null;
            $validator->validate($item, $error);
            if (!empty($error)) {
                $key = $attribute . '[' . $index . ']';
                $this->addError($key, $error);
            }
        }
    }
352617
protected function replaceAttribute($attribute)
	{
		if (array_key_exists($attribute, $this->replacements)) {
			return $this->replacements[$attribute];
		}

		return $attribute;
	}
1071697
public function fetchValues($tag, $attribute)
    {
        $values = array();

        // loop through each tag in the dom and add it to the array
        foreach ($this->getElementsByTagName($tag) as $element) {
            /* @var $element \DOMElement */
            $values[] = $element->getAttribute($attribute);
        }

        return $values;
    }
898663
public function translate($attribute)
    {
        $translationCode = $this->translationCodeFor($attribute);
        $translation     = $translationCode ? trans($translationCode) : false;
        return $translation ?: parent::getAttribute($attribute);
    }
1085778
public function __toArray($attributes = array()){

        if( empty($attributes) ){
            $data = $this->_data;
        }else{

            $data = array();
            foreach( $attributes as $attribute ){
                if( isset($this->_data[$attribute]) ){
                    $data[$attribute] = $this->_data[$attribute];
                } else {
                    $data[$attribute] = NULL;
                }
            }

        }

        foreach( $data as $key => $item ){
            if( $item instanceof AppObject ){
                $item = $item->toArray();
                $data[$key] = $item;
            }
        }

        return $data;
    }
426900
public function getErrors($attribute = null)
    {
        $itemErrors = [];

        foreach ($this->getItems() as $item) {
            if ($item->hasErrors($attribute)) {
                $itemErrors[$this->getItemId($item)] = $item->getErrors($attribute);
            }
        }

        return array_merge(
            $this->_traitGetErrors($attribute),
            $itemErrors
        );
    }
627618
public function attr(array $attributes)
    {
        $result = '';

        foreach ($attributes as $attribute => $value) {
            $result .= ' '.(is_int($attribute) ? $value : $attribute.'="'.str_replace('"', '&quot;', $value).'"');
        }

        return $result;
    }