yii\behaviors\AttributeTypecastBehavior::typecastAttributes PHP Method

typecastAttributes() public method

Typecast owner attributes according to [[attributeTypes]].
public typecastAttributes ( array $attributeNames = null )
$attributeNames array list of attribute names that should be type-casted. If this parameter is empty, it means any attribute listed in the [[attributeTypes]] should be type-casted.
    public function typecastAttributes($attributeNames = null)
    {
        $attributeTypes = [];
        if ($attributeNames === null) {
            $attributeTypes = $this->attributeTypes;
        } else {
            foreach ($attributeNames as $attribute) {
                if (!isset($this->attributeTypes[$attribute])) {
                    throw new InvalidParamException("There is no type mapping for '{$attribute}'.");
                }
                $attributeTypes[$attribute] = $this->attributeTypes[$attribute];
            }
        }
        foreach ($attributeTypes as $attribute => $type) {
            $value = $this->owner->{$attribute};
            if ($this->skipOnNull && $value === null) {
                continue;
            }
            $this->owner->{$attribute} = $this->typecastValue($value, $type);
        }
    }