for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Thinktomorrow\Vine\Branch;
class BuildArray
{
public static function fromCollection(BranchCollection $collection = null,array $mapping = [])
$array = [];
if(empty($collection)) return $array;
foreach($collection as $branch)
$children = $branch->hasBranches() ? self::fromCollection($branch->branches,$mapping) : null;
$record = ['id' => $branch->key,'slug' => $branch->value,'name' => $branch->label];
if($children) $record['children'] = $children;
$array[] = $record;
}
return $array;