protected function toAssocRecursive($input, SplObjectStorage $list): array
    {
        $values = is_iterable($input)
            ? i\iterable_to_array($input)
            : object_get_properties($input, $input instanceof stdClass || $input instanceof DynamicEntity);

        foreach ($values as $key => &$value) {
            if ($value instanceof Entity) {
                $value = $list->contains($value) ? $list[$value] : $this->toAssocEntity($value, $list);

                if ($value === null && !is_int($key)) {
                    unset($values[$key]);
                }
            } elseif (is_iterable($value) || $value instanceof stdClass) {
                $value = $this->toAssocRecursive($value, $list);
            }
        }

        return $values;
    }