/** * Creates a mapping from given type. * * @param string $type The type * * @return Mapping */ public function of($type) { $isArray = '[]' === substr($type, -2); if ($isArray) { $type = substr($type, 0, -2); } if (array_key_exists($type, $this->mappings)) { $mapping = clone $this->mappings[$type]; } else { $refl = new \ReflectionClass($type); $mapping = new Mapping(new Emitter(), $this->extensions); foreach ($refl->getProperties() as $prop) { if ($child = $this->mappingFromProp($prop)) { $mapping->addChild($prop->getName(), $child); } } $mapping->transformTo($type); $this->mappings[$type] = clone $mapping; } if ($isArray) { $mapping = $mapping->multiple(); } return $mapping; }