Mongolid\DataMapper\SchemaMapper::mapToSchema PHP Method

mapToSchema() protected method

Instantiate another SchemaMapper with the given $schemaClass and maps the given $value.
protected mapToSchema ( mixed $value, string $schemaClass ) : mixed
$value mixed Value that will be mapped.
$schemaClass string Class that will be passed to the new SchemaMapper constructor.
return mixed
    protected function mapToSchema($value, string $schemaClass)
    {
        $value = (array) $value;
        $schema = Ioc::make($schemaClass);
        $mapper = Ioc::make(self::class, [$schema]);
        if (!isset($value[0])) {
            $value = [$value];
        }
        foreach ($value as $key => $subValue) {
            $value[$key] = $mapper->map($subValue);
        }
        return $value;
    }