<?php
    namespace App\Utils;
    
    use Doctrine\Common\Collections\Collection;

    class ConvertHelper {
        public static function coll2json(Collection $collection) : string 
        {
            if (!$collection) return "[]";
            $ts = [];
            foreach ($collection as $item) {
                $ts[] = $item->__serialize();
            }
            return json_encode($ts);
        }

        public static function array2json(array $array) : string 
        {
            if (!$array) return "[]";
            $ts = [];
            foreach ($array as $item) {
                if (is_array($item)) {
                    $ts[] = $item;
                } else {
                    if (is_string($item)) {
                        $ts[] = $item;
                    } else {
                        $ts[] = $item->__serialize();
                    }
                }
            }
            // dump($ts);
            $res = json_encode($ts);
            // dump($res);
            return $res;
        }
    }
