Compile a object map.

@param Fluent $fluent

@return array
485579
public function compileObject(Fluent $fluent)
    {
        $blueprint = new Blueprint($fluent->type);

        /* @var \Closure $callback */
        $callback = $fluent->callback;

        if (is_callable($callback)) {
            $callback($blueprint);
        }

        return [
            'properties' => $this->compileFields($blueprint->getFields()),
        ];
    }
1134863
protected function buildPropertyMap()
    {
        $map = [];
        $properties = (new ReflectionObject($this))->getProperties(ReflectionProperty::IS_PUBLIC);

        foreach ($properties as $property) {
            $map[$property->getName()] = $property;
        }

        return $map;
    }
885519
public function compileCreate(Blueprint $blueprint, Fluent $command)
    {
        return sprintf('%s table %s (%s%s%s)',
            $blueprint->temporary ? 'create temporary' : 'create',
            $this->wrapTable($blueprint),
            implode(', ', $this->getColumns($blueprint)),
            (string) $this->addForeignKeys($blueprint),
            (string) $this->addPrimaryKeys($blueprint)
        );
    }
1205358
protected function fluentInput($keys = null)
	{
		if ($keys !== null) {
			$input = Input::only($keys);
		} else {
			$input = Input::all();
		}

		return $this->getTransformedInput($input);
	}
265024
public function compileDropColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
    {
        $tableDiff = $this->getDoctrineTableDiff(
            $blueprint, $schema = $connection->getDoctrineSchemaManager()
        );

        foreach ($command->columns as $name) {
            $tableDiff->removedColumns[$name] = $connection->getDoctrineColumn(
                $this->getTablePrefix().$blueprint->getTable(), $name
            );
        }

        return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
    }
218469
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
    {
        $command->algorithm = 'gist';

        return $this->compileIndex($blueprint, $command);
    }
187987
private function buildCustomEntitiesMap(array $entities)
    {
        $map = [];

        foreach ($entities as $entity) {
            $entityClass = ClassUtils::getClass($entity);
            $objectHash = spl_object_hash($entity);

            foreach ($this->getCustomObjectMeta($entityClass) as $targetProperty => $params) {
                $initPropertyValue = $this->getPropertyValue($entity, $params['initPropertyValuePath']);

                if (empty($initPropertyValue)) {
                    continue;
                }
                if (!isset($map[$entityClass])) {
                    $map[$entityClass] = [];
                }
                if (!isset($map[$entityClass][$objectHash])) {
                    $map[$entityClass][$objectHash] = [];
                }

                $map[$entityClass][$objectHash][$targetProperty] = [
                    'class' => !empty($params['class'])
                        ? $params['class']
                        : $this->getPropertyValue($entity, $params['classPropertyPath'])
                    ,
                    'initProperty' => !empty($params['initProperty'])
                        ? $params['initProperty']
                        : $this->extendedMetadataFactory->getIdentifier($entityClass)
                    ,
                    'initPropertyValue' => $initPropertyValue,
                ];
            }
        }

        return $map;
    }
552241
protected function toFluent($id)
    {
        $defaults = Arr::get($this->config, 'defaults', []);
        return new Fluent(array_merge($defaults, [
                    'id'     => $id,
                    'childs' => []
        ]));
    }
31066
public function toArray($entity)
    {
        $firstTime = !$this->entitiesGraph ? true : false;

        if (!in_array(get_class($this), $this->entitiesGraph)) {
            $this->entitiesGraph[] = get_class($this);
        }

        $toArray  = [];
        $newArray = [];

        $refl = new \ReflectionClass($entity);
        foreach ($refl->getProperties() as $property) {
            $property->setAccessible(true);

            $value = $property->getValue($entity);

            if (array_key_exists($property->getName(), $this->propertiesToArrayCallbacks)) {
                $value = call_user_func_array($this->propertiesToArrayCallbacks[$property->getName()], [$value]);
            }

            if (!is_null($value)) {
                $toArray[$property->getName()] = $value;
            }
        }

        foreach ($toArray as $propertyName => $propertyValue) {

            // Simple mappings
            if (
                in_array($propertyName, $this->columnsToProperties) &&
                !array_key_exists($propertyName, $this->propertiesToMappers)
            ) {
                $columnName = array_search($propertyName, $this->columnsToProperties);

                $result = $this->createArrayFromColumnName($columnName, $propertyValue);
                $newArray = array_merge_recursive($newArray, $result);
                continue;
            }

            // Via Classes
            if (array_key_exists($propertyName, $this->propertiesToClasses) && is_object($propertyValue)) {
                $subMapper = $this->propertiesToClasses[$propertyName];
                $subMapper->setEntitiesGraph($this->entitiesGraph);
                $value    = $subMapper->toArray($propertyValue);
                $newArray = array_merge_recursive($newArray, $value);
                continue;
            }

            // via Mappers
            if (array_key_exists($propertyName, $this->propertiesToMappers)) {
                $className = $this->propertiesToMappers[$propertyName];

                if (in_array($className, $this->entitiesGraph)) {
                    continue;
                }

                /** @var DoplioDataMapper $subMapper */
                $subMapper = $this->resolver->resolve($className);
                $subMapper->setEntitiesGraph($this->entitiesGraph);

                if ($subMapper->toArrayResultCallback) {
                    $method        = $subMapper->toArrayResultCallback;
                    $propertyValue = $method($propertyValue);

                    foreach ($propertyValue as $offset => $item) {
                        $value = $subMapper->toArray(
                            $item
                        );
                        $newArray[array_search($propertyName, $this->columnsToProperties)][$offset] = $value;
                    }
                } else {
                    $value = $subMapper->toArray(
                        $propertyValue
                    );
                    $newArray[array_search($propertyName, $this->columnsToProperties)] = $value;
                }

                $this->entitiesGraph = array_merge($this->entitiesGraph, $subMapper->entitiesGraph);
            }
        }

        if ($this->fromClassname) {
            $method = $this->fromClassname;
            $data = $method(get_class($entity));
            $newArray = array_merge_recursive($newArray, $data);
        }


        if ($firstTime) {
            $this->entitiesGraph = [];
        }
        return $newArray;
    }
71884
protected function toFluent($id): Fluent
    {
        $defaults = $this->config['defaults'] ?? [];
        $class = $this->config['fluent'] ?? Fluent::class;

        return new $class(\array_merge($defaults, [
            'id' => $id,
            'childs' => [],
        ]));
    }
400456
public function map(\Closure $callback)
    {
        $result = [];
        foreach ($this->value as $entity) {
            $result[] = $callback($entity);
        }

        return $result;
    }
157246
public function compile()
    {
        $indent    = '    ';
        $getters   = array();
        $instances = $this->dumper->getAllInjectedDefinitions();

        /* @var $instance GeneratorInstance */
        foreach ($instances as $name => $instance) {
            $constructor = $instance->getConstructor();
            $instantiatorParams = $this->buildParams($instance->getParams());

            if ('__construct' !== $constructor) {
                // Constructor callback
                if (is_callable($constructor)) {
                    $callback = $constructor;

                    if (is_array($callback)) {
                        $class = (is_object($callback[0])) ? get_class($callback[0]) : $callback[0];
                        $method = $callback[1];
                    } elseif (is_string($callback) && strpos($callback, '::') !== false) {
                        list($class, $method) = explode('::', $callback, 2);
                    }

                    $callback = var_export(array($class, $method), true);

                    if (count($instantiatorParams)) {
                        $creation = sprintf('$object = call_user_func(%s, %s);', $callback, implode(', ', $instantiatorParams));
                    } else {
                        $creation = sprintf('$object = call_user_func(%s);', $callback);
                    }
                } else if (is_string($constructor) && strpos($constructor, '->') !== false) {
                    list($class, $method) = explode('->', $constructor, 2);

                    if (!class_exists($class)) {
                        throw new InvalidArgumentException('No class found: ' . $class);
                    }

                    if (count($instantiatorParams)) {
                        $creation = sprintf(
                            '$object = $di->get(%s)->%s(%s);',
                            var_export($class, true),
                            $method,
                            implode(', ', $instantiatorParams)
                        );
                    } else {
                        $creation = sprintf('$object = $di->get(%s)->%s();', var_export($class, true), $method);
                    }
                } else {
                    throw new InvalidArgumentException('Invalid instantiator supplied for class: ' . $name);
                }
            } else {
                $className = '\\' . trim($this->reduceAlias($name), '\\');

                if (count($instantiatorParams)) {
                    $creation = sprintf('$object = new %s(%s);', $className, implode(', ', $instantiatorParams));
                } else {
                    $creation = sprintf('$object = new %s();', $className);
                }
            }


            // Create method call code
            if ($instance->isShared()) {
                $creation .= "\n\nif (\$isShared) {\n" . $indent
                    . '$di->instanceManager()->addSharedInstance($object, \'' . $instance->getName() . '\');'
                    . "\n}\n";
            }

            $methods = '';

            foreach ($instance->getMethods() as $methodData) {
                $methodName   = $methodData['method'];
                $methodParams = $methodData['params'];
                // Create method parameter representation
                $params = $this->buildParams($methodParams);

                if (count($params)) {
                    $methods .= sprintf("\$object->%s(%s);\n", $methodName, implode(', ', $params));
                }
            }

            // Start creating getter
            $getterBody = "function (\\Zend\\Di\\Di \$di, \$isShared) {\n";

            // Creation and method calls
            $getterBody .= $indent . str_replace("\n", "\n" . $indent, $creation) . "\n";
            $getterBody .= $indent . str_replace("\n", "\n" . $indent, $methods);

            // End getter body
            $getterBody .= "\n" . $indent . "return \$object;\n}";

            $getters[$name] = $getterBody;
        }

        $fileBody = "return array(\n";

        foreach ($getters as $name => $getterBody) {
            $fileBody .= $indent . var_export($name, true);
            $fileBody .= ' => ' . str_replace("\n", "\n" . $indent, $getterBody) . ",\n\n";
        }

        $fileBody .= ");\n";

        // Create PHP file code generation object
        $generator = $this->getFileGenerator();
        $generator->setBody($fileBody);

        return $generator;
    }
512545
public function compilePrimary(Blueprint $blueprint, Fluent $command)
    {
        $create = $this->getCommandByName($blueprint, 'create');

        if (is_null($create)) {
            $columns = $this->columnize($command->columns);

            $table = $this->wrapTable($blueprint);

            return "alter table {$table} add constraint {$command->index} primary key ({$columns})";
        }
    }
442013
public function compileDate(Fluent $fluent)
    {
        $map = [
            'type'             => 'date',
            'boost'            => $fluent->boost,
            'doc_values'       => $fluent->doc_values,
            'format'           => $fluent->format,
            'ignore_malformed' => $fluent->ignore_malformed,
            'include_in_all'   => $fluent->include_in_all,
            'index'            => $fluent->index,
            'null_value'       => $fluent->null_value,
            'precision_step'   => $fluent->precision_step,
            'store'            => $fluent->store,
        ];

        return $this->formatMap($map);
    }
419178
public function collection()
    {
        if (!empty($this->response['data'])) {
            $data = [];

            foreach ($this->response['data'] as $object) {
                $data[] = new Fluent($this->resource, $object);
            }

            return $data;
        }

        return [];
    }
553341
public function compile($definition)
    {
        $validator = new ExceptionValidator($definition->createValidator());
        $validator->validate($definition);

        // Try to compile map option
        // Just works if map is a validator
        try {
            $definition->map = $this->compiler->compile($definition->map);
        } catch (\RuntimeException $e) {
            // Ignore it if fails
            // Map could be a closure or anything else callable
        }

        return new ArrayValidator($definition->export());
    }
1091594
public function compileIp(Fluent $fluent)
    {
        $map = [
            'type'           => $fluent->type,
            'boost'          => $fluent->boost,
            'doc_values'     => $fluent->doc_values,
            'include_in_all' => $fluent->include_in_all,
            'index'          => $fluent->index,
            'null_value'     => $fluent->null_value,
            'precision_step' => $fluent->precision_step,
            'store'          => $fluent->store,
        ];

        return $this->formatMap($map);
    }