function create($source, $required = true) { $flat = new flat(); $this->traverse(function ($path, $property) use($source, $flat) { $closure = is_array($source) ? isset($source[$path]) ? $source[$path] : $source['*'] : $source; $closure = is_array($closure) ? isset($closure[$property->type]) ? $closure[$property->type] : $closure['*'] : $closure; if (($result = $closure($path, $property)) !== null) { if ($property->type == 'number') { $result = floatval(preg_replace('/[^0-9\\.\\-]/', '', $result)); } elseif ($property->type == 'integer') { $result = intval(preg_replace('/[^0-9\\-]/', '', $result)); } $flat[$path] = $result; } }); return $required ? $flat->render() : $flat; }
static function denormalize($object) { $flat = new flat(); $flat->unwind($object); return $flat; }