格式化属性值
可以通过重载此方法实现自定义格式化逻辑.

@param string $key       属性名
@param mixed  $value     属性值
@param array  $attribute 属性定义信息

@return mixed 格式化过后的值
551991
protected function normalize($key, $value, array $attribute)
    {
        return Type::factory($attribute['type'])->normalize($value, $attribute);
    }
1151069
public function setAttribute($key, $value)
	{
		// First we will check for the presence of a mutator for the set operation
		// which simply lets the developers tweak the attribute as it is set on
		// the model, such as "json_encoding" an listing of data for storage.
		if ($this->hasSetMutator($key)) {
			$method = 'set' . Str::studly($key) . 'Attribute';

			return $this->{$method}($value);
		}

		// If an attribute is listed as a "date", we'll convert it from a DateTime
		// instance into a form proper for storage on the database tables using
		// the connection grammar's date format. We will auto set the values.
		elseif (in_array($key, $this->getDates()) && $value) {
			$value = $this->fromDateTime($value);
		}

		// Only set if the user can currently access
		if ($this->console_mode || $this->modify_authorizer->canAccess($key)) {
			if ($this->isJsonCastable($key) && ! is_null($value)) {
				$value = json_encode($value);
			}

			$this->attributes[$key] = $value;
		}
	}
1354259
public static function getAttributeByValue($attribute, $value)
    {
        $constant = self::getConstantConfigByValue($value);
        if (isset($constant[$attribute])) {
            return $constant[$attribute];
        }
        return false;
    }
999000
public function attribute($attribute, $value = null)
    {
        $element = clone $this;

        $element->attributes->setAttribute($attribute, (string) $value);

        return $element;
    }
368308
public static function getByAttribute($attribute, $value, $asArray = false)
    {
        if (isset(self::$uniqueAttributeToId[$attribute][$value])) {
            return static::getById(self::$uniqueAttributeToId[$attribute][$value], $asArray);
        }
        $row = static::find()
            ->where([$attribute => $value])
            ->asArray($asArray)
            ->one();
        static::addRowToMap($row);
        return $row;
    }
102015
function set($attribute, $value = null) {
    $attributes = is_array($attribute)
                ? $attribute
                : [$attribute => $value];

    foreach ($attributes as $attr => $val) {

      if ($this->getPropertyFor($attr, 'accepts')) {
          $acceptsConstraint = new Attributes\Constraint\Accepts($this->getPropertyFor($attr, 'accepts'));
          if (!$acceptsConstraint->isValid($val)) {
              throw new InvalidArgumentException(__CLASS__ . " does not accept {$val} as value for the property {$attr}");
          }
      }

      if ($this->getPropertyFor($attr, 'minimum')) {
          $minimumConstraint = new Attributes\Constraint\Minimum($this->getPropertyFor($attr, 'minimum'));
          if (!$minimumConstraint->isValid($val)) {
              throw new InvalidArgumentException(__CLASS__ . " does not accept {$val} as value for the property {$attr}");
          }
      }

      if ($this->getPropertyFor($attr, 'maximum')) {
          $maximumConstraint = new Attributes\Constraint\Maximum($this->getPropertyFor($attr, 'maximum'));
          if (!$maximumConstraint->isValid($val)) {
              throw new InvalidArgumentException(__CLASS__ . " does not accept {$val} as value for the property {$attr}");
          }
      }

      $this->setPropertyFor($attr, 'value', $val, 'set');
    }

    return $this;
  }
358143
public function setAttribute($attribute, $value)
    {
        switch ($attribute) {
            case self::ATTR_DEFAULT_FETCH_MODE:
                $this->attributes['defaultFetchMode'] = $value;
                break;

            case self::ATTR_ERRMODE:
                $this->attributes['errorMode'] = $value;
                break;

            case self::ATTR_TIMEOUT:
                $this->attributes['timeout'] = (int)$value;
                break;

            case self::CRATE_ATTR_HTTP_BASIC_AUTH:
                if (!is_array($value) && $value !== null) {
                    throw new InvalidArgumentException(
                        'Value probided to CRATE_ATTR_HTTP_BASIC_AUTH must be null or an array'
                    );
                }

                $this->attributes['auth'] = $value;
                break;

            case self::CRATE_ATTR_DEFAULT_SCHEMA:
                $this->attributes['defaultSchema'] = $value;
                break;

            case self::CRATE_ATTR_SSL_MODE:
                $this->attributes['sslMode'] = $value;
                break;

            case self::CRATE_ATTR_SSL_CA_PATH:
                $this->attributes['sslCa'] = $value;
                break;

            case self::CRATE_ATTR_SSL_CA_PASSWORD:
                $this->attributes['sslCaPassword'] = $value;
                break;

            case self::CRATE_ATTR_SSL_CERT_PATH:
                $this->attributes['sslCert'] = $value;
                break;

            case self::CRATE_ATTR_SSL_CERT_PASSWORD:
                $this->attributes['sslCertPassword'] = $value;
                break;

            case self::CRATE_ATTR_SSL_KEY_PATH:
                $this->attributes['sslKey'] = $value;
                break;

            case self::CRATE_ATTR_SSL_KEY_PASSWORD:
                $this->attributes['sslKeyPassword'] = $value;
                break;

            default:
                throw new Exception\PDOException('Unsupported driver attribute');
        }

        // A setting changed so we need to reconfigure the server pool
        $this->server->configure($this);
    }
508371
public function setTableAttribute($attribute, $value = null)
    {
        if (is_array($attribute)) {
            return $this->setTableAttributes($attribute);
        }

        $this->tableAttributes[$attribute] = $value;

        return $this;
    }
552469
protected function validateArray( $attribute, $value )
	{
		if ( !$this->hasAttribute( $attribute ) )
		{
			return true;
		}

		return is_null( $value ) || is_array( $value );
	}
1092078
public static function create($attribute, $value)
    {
        $attributesType = self::getAllAttributeType();
        foreach ($attributesType as $attributeType) {
            if ($attributeType->isMember($attribute)) {
                return $attributeType->create($value);
            }
        }

        return $value;
    }
481914
public function setAttribute($path, $attribute, $value) {
		if ($attribute === 'system.dos_attr.mode' and is_int($value)) {
			$value = '0x' . dechex($value);
		}

		return $this->getState()->setxattr($this->buildUrl($path), $attribute, $value);
	}
1278221
public function setHtmlAttribute($key, $attribute)
    {
        $attribute = $this->prepareHtmlAttributeValue($attribute);

        if ($key == 'class') {
            $this->htmlAttributes[$key][] = $attribute;
        } else {
            $this->htmlAttributes[$key] = $attribute;
        }

        return $this;
    }
470804
public function setAttribute($key, $value)
    {
        list($attribute, $locale) = $this->getAttributeAndLocale($key);

        if ($this->isTranslationAttribute($attribute)) {
            $this->getTranslationOrNew($locale)->$attribute = $value;
        } else {
            return parent::setAttribute($key, $value);
        }

        return $this;
    }
1109932
public function setAttribute($key, $value)
    {
        if ($value !== null && $this->isSerializeCastable($key)) {
            $value = $this->asSerialize($value);
        }

        return parent::setAttribute($key, $value);
    }
695137
protected function validateDistinct( $attribute, $value, $parameters )
	{
		$attributeName = $this->getPrimaryAttribute( $attribute );

		$explicitPath = $this->getLeadingExplicitAttributePath( $attributeName );

		$attributeData = $this->extractDataFromPath( $explicitPath );

		$data = Arr::where( Arr::dot( $attributeData ), function ( $key ) use ( $attribute, $attributeName )
		{
			return $key != $attribute && Str::is( $attributeName, $key );
		} );

		return !in_array( $value, array_values( $data ) );
	}
789704
public function setAttribute($key, $value)
    {
        // First we will check for the presence of a mutator for the set operation
        // which simply lets the developers tweak the attribute as it is set on
        // the model, such as "json_encoding" an listing of data for storage.
        if ($this->hasSetMutator($key)) {
            $method = 'set'.str_studly($key).'Attribute';

            return $this->{$method}($value);
        }
        // If an attribute is listed as a "date", we'll convert it from a DateTime
        // instance into a form proper for storage on the database tables using
        // the connection grammar's date format. We will auto set the values.
        elseif ($value && (in_array($key, $this->getDates()) || $this->isDateCastable($key))) {
            $value = $this->fromDateTime($value);
        }

        if ($this->isJsonCastable($key) && ! is_null($value)) {
            $value = $this->castAttributeAsJson($value);
        }

        // If this attribute contains a JSON ->, we'll set the proper value in the
        // attribute's underlying array. This takes care of properly nesting an
        // attribute in the array's value in the case of deeply nested items.
        if (mb_strpos($key, '->') !== false) {
            return $this->fillJsonAttribute($key, $value);
        }

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

        return $this;
    }
617764
public function set_attribute( $key, $value ) {
		$this->attributes[ $key ] = $this->sanitize_attribute( $key, $value );

		return $this;
	}