public static function buildStructure($array, Structure $structure)
    {
        switch ($structure->getType()) {
            case Structure::TYPE_LIST:
                $result = self::buildList($array, $structure);
                break;
            case Structure::TYPE_ARRAY:
                $result = self::buildArray($array, $structure);
                break;
            default:
                throw new Exception('Unknown structure type ' . $structure->getType());
        }

        return $result;
    }