protected function initSchema(array $schema, $data) { foreach ($schema as $key => $value) { if ($value === 'collection') { $iv = $ov = Tools::getInitValue($data, $key, []); if ('s' === substr($key, -1)) { try { $iv = []; foreach ($ov as $y) { $iv[] = $this->factoryNeighborObject(ucfirst(rtrim($key, "s")), $y); } } catch (\Exception $e) { $iv = $ov; } } $schema[$key] = $this->factoryCollection($iv); } elseif ($value === 'object') { $schema[$key] = $this->factoryNeighborObject(ucfirst($key), Tools::getInitValue($data, $key, [])); } elseif ($value === 'array') { $schema[$key] = Tools::getInitValue($data, $key, []); } elseif (in_array($value, ['string', 'integer', 'number', 'boolean', 'datetime'], true)) { $schema[$key] = Tools::normalizeType(Tools::getInitValue($data, $key), $value); } } return $schema; }
protected function initSchema(array $schema, $data) { foreach ($schema as $key => $value) { if ($value === 'collection') { $schema[$key] = $this->factoryCollection(Tools::getInitValue($data, $key, [])); } elseif ($value === 'object') { $schema[$key] = $this->factoryNeighborObject(ucfirst($key), Tools::getInitValue($data, $key, [])); } elseif ($value === 'array') { $schema[$key] = Tools::getInitValue($data, $key, []); } elseif (in_array($value, ['string', 'integer', 'number', 'boolean'], true)) { $schema[$key] = Tools::normalizeType(Tools::getInitValue($data, $key), $value); } } return $schema; }
/** * @dataProvider dataProviderInformacao */ public function testNormalizaTiposDeInformacao($value, $type, $expected) { $this->assertTrue(Tools::normalizeType($value, $type) === $expected); }