Scalr\Service\Aws\DataType\ListDataType::typeCastData PHP Method

typeCastData() private method

Type casts an list data object.
private typeCastData ( mixed $v ) : mixed
$v mixed The list member.
return mixed Returns type cast object
    private function typeCastData($v)
    {
        $dataClass = $this->dataClassName;
        if (is_string($v) || is_numeric($v)) {
            $t = new $dataClass();
            $prop = 'set' . ucfirst(is_array($this->propertyName) ? $this->propertyName[0] : (string) $this->propertyName);
            $t->{$prop}($v);
        } else {
            if (is_array($v)) {
                $t = new $dataClass();
                foreach ((array) $this->propertyName as $prop) {
                    if (!array_key_exists($prop, $v)) {
                        //If property value isn't found in the specified array
                        //it will be omitted instead of the error generation.
                        //This is necessary, for an instance, when we specify the list constructor
                        //with the full bunch of the options from the data object which is going to be listed,
                        //and when these properies can be optional at the same time.
                        continue;
                    }
                    $setfn = 'set' . ucfirst($prop);
                    $t->{$setfn}($v[$prop]);
                }
            }
        }
        return isset($t) ? $t : null;
    }