@template T as array

@param scalar|array|object|null $value

@psalm-param class-string<DaftObject> $class_name
172631
public static function ExpectRetrievedValueIsArray(
        string $property,
        $value,
        string $class_name
    ) : array {
        /**
        * @psalm-var T
        */
        $value = static::MaybeThrowIfNotType($property, $value, $class_name, 'array');

        return $value;
    }
80203
public static function toArray($value, $keepEmpty = false, $keepNull = false)
	{
		$array = [];

		foreach ($value as $k => $v)
		{
			$isDictionary = $v instanceof Dictionary;
			if ($v instanceof ConfigProvider)
			{
				$v = $v->asConfig();
			}
			elseif ($v instanceof Traversable || is_array($v))
			{
				$v = self::toArray($v, $keepEmpty, $keepNull);
			}
			elseif (is_scalar($v) || is_null($v))
			{
				// Do nothing
			}
			else
			{
				$type = (is_object($v))
				      ? 'an instance of ' . get_class($v)
				      : 'a ' . gettype($v);

				throw new RuntimeException('Cannot convert ' . $type . ' to array');
			}

			if (!isset($v) && !$keepNull)
			{
				// We don't record NULL values
				continue;
			}

			if (!$keepEmpty && $v === [])
			{
				// We don't record empty structures
				continue;
			}

			$array[$k] = ($isDictionary) ? new Dictionary($v) : $v;
		}

		return $array;
	}
1207343
protected function castArray($value, TypeHandler $typeHandler, $join_string = ',') {
		$list = [];
	
		//build expression list
		foreach ($value as $val) {
			$val = $typeHandler->castParameter($val);
	
			if (is_null($val))
				$new_elem = 'NULL';
			else {
				$new_elem = $typeHandler->setParameter($val);
				if (is_null($new_elem))
					$new_elem = 'NULL';
				elseif (!is_string($new_elem))
					$new_elem = strval($new_elem);
			}
				
			$list[] = $new_elem;
		}
	
		//return joined expression
		return implode($join_string, $list);
	}
234613
function setClass( $value, $params=FALSE ) {
    $this->class['value']  = $value;
    $this->class['params'] = $this->_setParams( $params );
  }
941210
public function setPropertyValue($class, $name, $value)
    {
        $property = $this->findProperty($class, $name);
        $property->setAccessible(true);
        $property->setValue(
            is_object($class) ? $class : null,
            $value
        );
    }
115260
protected function _getType($value)
    {
        if (is_object($value)) {
            try {
                return self::getShortClassname($value);
            } catch (\InvalidArgumentException $e) {
                return null;
            }
        }

        if (is_array($value)) {
            return 'array';
        }

        return 'scalar';
    }
387896
protected function unserializeUserDefinedObject(array $value, $className)
    {
        $ref = new ReflectionClass($className);
        $obj = $ref->newInstanceWithoutConstructor();

        self::$objectMapping[self::$objectMappingIndex++] = $obj;
        $this->setUnserializedObjectProperties($value, $ref, $obj);

        if (\method_exists($obj, '__wakeup')) {
            $obj->__wakeup();
        }

        return $obj;
    }
1272406
public static function toArray($value)
    {
        if (!is_array($value) && !$value instanceof Traversable) {
            $name = static::of($value);
            throw new TypeException("Can only cast Traversable and arrays to array, not $name");
        }

        return is_array($value) ? $value : iterator_to_array($value);
    }
1096355
public static function allToArray($value)
    {
        if ($value instanceof DataSetInterface) {
            $value = $value->dump(true);
        } elseif ($value instanceof DataInterface) {
            $value = $value->dump(true);
        } elseif ($value instanceof \Traversable) {
            $value = iterator_to_array($value);
        } elseif (is_object($value)) {
            $value = get_object_vars($value);
        }

        if (is_array($value)) {
            foreach ($value as &$v) {
                $v = static::allToArray($v);
            }
        }

        return $value;
    }
229039
function apply($value, $instance = null, $attribute = null)
    {
        if(!$instance->$attribute) {
            return null;
        }

        if($instance->$attribute() instanceof MorphMany) {
            // We are handling a list of uploads
            return $instance->$attribute->map(function($upload) {
                $array = $this->transformUpload($upload);

                $file = array_only($array, ["name", "thumbnail", "size"]);

                return [
                    "file" => sizeof($file) ? $file : null,
                ] + array_except($array, ["name", "thumbnail", "size"]);
            })->all();
        };

        return $this->transformUpload($instance->$attribute);
    }
390494
protected function checkType($name, $value, $type = 'string', $class = null)
    {
        if ($value === null) {
            return true;
        }

        $type = strtolower($type);

        $false = false;

        if ($type === 'object') {
            if ($class && !is_subclass_of($value, $class)) {
                $false = true;
            } elseif (!is_object($value)) {
                $false = true;
            }
        } elseif (gettype($value) != $type) {
            $false = true;
        }

        if (!$false) {
            return true;
        }

        if ($class) {
            throw new \InvalidArgumentException(sprintf('%s should be instance of of %s.', $name, $class));
        }

        throw new \InvalidArgumentException(sprintf('%s should be type of %s.', $name, $type));
    }
888158
static public function isArray($value, $message = null, $propertyPath = null)
        {
            if (!Arrays::is($value)) {
                $message = $message ?: sprintf(
                    'Value "%s" is not an array.',
                    static::stringify($value)
                );

                throw static::createException($value, $message, static::INVALID_ARRAY, $propertyPath);
            }
        }
738275
public static function SetClassVar ($name, $value, $const_flag = false) {
		$name = Arrays::AdjustArray($name);
		if ($const_flag && Arrays::AdjustValue(static::$_ApplicationVariableTrait_ConstList, implode('=>', Arrays::AdjustArray($name)))) {
			throw CoreException::RaiseSystemError('%s is constant', [implode(' => ', $name)]);
		}
		static::$_ApplicationVariableTrait_Data = Arrays::SetLowest(static::$_ApplicationVariableTrait_Data, $name, $value);
		static::$_ApplicationVariableTrait_ConstList[implode('=>', Arrays::AdjustArray($name))] = $const_flag;
	}
120724
public static function GetClassVar ($name, $default_value = null) {
		if (is_array($name)) {
			return Arrays::GetLowest(static::$_ClassVariableTrait_Data, $name) ?: $default_value;
		}
		return isset(static::$_ClassVariableTrait_Data[$name]) ? static::$_ClassVariableTrait_Data[$name] : $default_value;
	}
913946
public static <T> T cast(Object value, Class<T> type) {
        if (null == value) {
            return null;
        }
        if (!type.isAssignableFrom(value.getClass())) {
            if (is(type, int.class, Integer.class)) {
                value = Integer.parseInt(value.toString());
            } else if (is(type, long.class, Long.class)) {
                value = Long.parseLong(value.toString());
            } else if (is(type, float.class, Float.class)) {
                value = Float.parseFloat(value.toString());
            } else if (is(type, double.class, Double.class)) {
                value = Double.parseDouble(value.toString());
            } else if (is(type, boolean.class, Boolean.class)) {
                value = Boolean.parseBoolean(value.toString());
            } else if (is(type, String.class)) {
                value = value.toString();
            }
        }
        return (T) value;
    }
779509
protected function createDataObjectFrom($value, $className)
    {
        // If the value is already the correct object, return it unaltered
        if ($value instanceof $className) {
            return $value;
        }

        // Convert object to array so it can be used to set  attributes in the DataObject
        if ($value instanceof Arrayable) {

            $value = $value->toArray();

        }  elseif (is_object($value)) {

            $value = json_decode(json_encode($value), true);
        }

        // Make validation fail if value could not be converted to an array
        if ( ! is_array($value)) {
            return false;
        }


        // Build an instance of the DataObject
        $dataObjectClass = $className;

        try {

            $dataObject = new $dataObjectClass($value);

        } catch (Throwable $e) {

            throw new InvalidArgumentException($dataObjectClass . ' is not instantiable as a DataObject', 0, $e);
        }

        if ( ! ($dataObject instanceof DataObjectInterface)) {

            throw new InvalidArgumentException($dataObjectClass . ' is not a validatable DataObject');
        }

        return $dataObject;
    }
1192625
@SuppressWarnings("unchecked")
	public static <T> ValueArray<T> createValueArray(Class<? extends Value> cls) {
		if (ByteValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new ByteValueArray();
		} else if (CharValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new CharValueArray();
		} else if (DoubleValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new DoubleValueArray();
		} else if (FloatValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new FloatValueArray();
		} else if (IntValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new IntValueArray();
		} else if (LongValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new LongValueArray();
		} else if (NullValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new NullValueArray();
		} else if (ShortValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new ShortValueArray();
		} else if (StringValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new StringValueArray();
		} else {
			throw new IllegalArgumentException("Unable to create unbounded ValueArray for type " + cls);
		}
	}