Map and respond.

@param string|mixed $mapper
@param mixed        $data

@throws ApiException

@return Illuminate\Http\JsonResponse
504370
public function respond($mapper, $data)
    {
        $arguments = [];
        // if data is instance of Paginator then get the values of the total and the page from the paginator,
        // and add them to the arguments array (total, page)
        if ($this->isPaginatorInstance($data)) {
            $arguments[0] = $data->total();
            $arguments[1] = $data->currentPage();
            $arguments[2] = $data->perPage();
        }
        // skip the first 2 arguments and save the rest to the 'arguments array':
        // > in case data is instance of Paginator then this will append all the arguments to the 'arguments array'
        // starting by the third arguments which should be the 'status'.
        // > in case data is is not instance of Paginator (means total and page and per_page are added manually as
        // arguments) then this will add all the arguments to the 'arguments array' starting by the third arguments
        // which should be the 'page'.
        foreach (array_slice(func_get_args(), 2) as $arg) {
            $arguments[count($arguments)] = $arg;
        }
        $result[] = $this->data($mapper, $data);

        return call_user_func_array([$this->response_handler, 'respond'], array_merge($result, $arguments));
    }
96639
protected function mapPointers(&$data)
    {
        $scope = $this->scope;

        if ($data instanceof static) {
            $data = &$data->closure;
        } elseif (is_array($data)) {
            if(isset($data[self::ARRAY_RECURSIVE_KEY])){
                return;
            }
            $data[self::ARRAY_RECURSIVE_KEY] = true;
            foreach ($data as $key => &$value){
                if($key === self::ARRAY_RECURSIVE_KEY){
                    continue;
                } elseif ($value instanceof static) {
                    $data[$key] = &$value->closure;
                } elseif ($value instanceof SelfReference && $value->hash === $this->code['self']){
                    $data[$key] = &$this->closure;
                } else {
                    $this->mapPointers($value);
                }
            }
            unset($value);
            unset($data[self::ARRAY_RECURSIVE_KEY]);
        } elseif ($data instanceof \stdClass) {
            if(isset($scope[$data])){
                return;
            }
            $scope[$data] = true;
            foreach ($data as $key => &$value){
                if ($value instanceof SelfReference && $value->hash === $this->code['self']){
                    $data->{$key} = &$this->closure;
                } elseif(is_array($value) || is_object($value)) {
                    $this->mapPointers($value);
                }
            }
            unset($value);
        } elseif (is_object($data) && !($data instanceof Closure)){
            if(isset($scope[$data])){
                return;
            }
            $scope[$data] = true;
            $reflection = new ReflectionObject($data);
            do{
                if(!$reflection->isUserDefined()){
                    break;
                }
                foreach ($reflection->getProperties() as $property){
                    if($property->isStatic() || !$property->getDeclaringClass()->isUserDefined()){
                        continue;
                    }
                    $property->setAccessible(true);
                    $item = $property->getValue($data);
                    if ($item instanceof SerializableClosure || ($item instanceof SelfReference && $item->hash === $this->code['self'])) {
                        $this->code['objects'][] = array(
                            'instance' => $data,
                            'property' => $property,
                            'object' => $item instanceof SelfReference ? $this : $item,
                        );
                    } elseif (is_array($item) || is_object($item)) {
                        $this->mapPointers($item);
                        $property->setValue($data, $item);
                    }
                }
            } while($reflection = $reflection->getParentClass());
        }
    }
505276
public function injectDataMapper(DataMapper $dataMapper)
    {
        $this->dataMapper = $dataMapper;
        $this->dataMapper->setPersistenceManager($this);
    }
664217
public function sendRequest(array $data): ResponseInterface
    {
        $options[RequestOptions::BODY] = $this->encodingService->encodeJson($data);

        return $this->send($options);
    }
238367
public function prepare(Mapper $mapper)
    {
        if ($this->isPrepared()) {
            throw new DataSetPreparationException('DataSet is already prepared');
        }
        //Split each row of the dataSet into inputs and outputs based on the mapper and the policies
        //Then re-parse the dataSet to fill in all the fields that used special policies (like Avg) and create the instances
        $this->map($mapper)->createInstances();

        //mark the dataSet as prepared
        $this->isPrepared = true;
    }
983258
protected function processMapper(CommandMapper $mapper) {
        $command = $mapper->getCommand();
        try {
            $mapper->delete();
            $command->execute();
        } catch (Exception $ex) {
            $this->erroneousMappers->push($mapper);
            Yii::getLogger()->log(
                    'An error ocurred while processing command [' . get_class($command) . '].'
                    . PHP_EOL
                    . 'Exception: [' . $ex->getTraceAsString() . ']', Logger::LEVEL_ERROR, 'command'
            );
        }
    }
976288
public function setMapper($mapperClass, array $options = [])
    {
        $sl             = $this->getServiceLocator();
        $mapperManager  = $sl->get(MapperManager::class);

        $defaultOptions = [
            'model' => $this->model ?? $this->serviceAlias,
            'hydrator' => $this->hydrator ?? $this->serviceAlias,
        ];

        $options    = array_merge($defaultOptions, $options);
        $mapper     = $mapperManager->get($mapperClass, $options);

        $this->mappers[$mapperClass] = $mapper;

        return $this;
    }
1075040
public static function createInstance($data, $table, Connection $connection, IMapper $mapper)
    {
        $dataArray = [];
        $primaryKey = $mapper->getPrimaryKey($table);
        if ($data instanceof DibiRow) {
            $dataArray = [isset($data->$primaryKey) ? $data->$primaryKey : self::DETACHED_ROW_ID => $data->toArray()];
        } else {
            $e = new InvalidArgumentException(
                'Invalid type of data given, only \Dibi\Row, \Dibi\Row[], ArrayAccess[] or array of arrays is supported at this moment.'
            );
            if (!is_array($data)) {
                throw $e;
            }
            if (!empty($data)) {
                $record = reset($data);
                if (!($record instanceof DibiRow) and !is_array($record) and (!$record instanceof ArrayAccess)) {
                    throw $e;
                }
            }
            foreach ($data as $record) {
                $record = (array)$record;
                if (isset($record[$primaryKey])) {
                    $dataArray[$record[$primaryKey]] = $record;
                } else {
                    $dataArray[] = $record;
                }
            }
        }
        return new static($dataArray, $table, $connection, $mapper);
    }
1229842
public function create($data)
    {
        $descriptor = new MethodDescriptor($data->getName());
        $descriptor->setDescription($data->getDescription());
        $descriptor->setMethodName($data->getMethodName());
        $descriptor->setStatic($data->isStatic());

        $response = new ReturnDescriptor('return');
        $response->setType($data->getReturnType());
        $descriptor->setResponse($response);

        foreach ($data->getArguments() as $argument) {
            if (array_key_exists('name', $argument) && array_key_exists('type', $argument)) {
                $argumentDescriptor = $this->createArgumentDescriptorForMagicMethod(
                    $argument['name'],
                    $argument['type']
                );
                $descriptor->getArguments()->set($argumentDescriptor->getName(), $argumentDescriptor);
            }
        }

        return $descriptor;
    }
715810
public function transform($data = null, $transformer = null):SuccessResponseBuilder
    {
        return app(Responder::class)->transform($data, $transformer);
    }
1064283
public function update($id, $data)
	{
		$this->getResponse()
			->setStatusCode(Response::STATUS_CODE_201);
		
		//$data = $this->getModel()->;
		
		return new JsonModel(array(
			'data' => "Update object resource " . $id // chiamata a this->get
		));
	}
279450
public function respondWithData(array $data)
    {

        $responseData = $this->getResponseStructure(true, $data, '');
        $response = new JsonResponse($responseData, $this->getStatusCode(), $this->getHeaders());
        return $response;
    }
346816
public function respond(array $data = [], array $headers = []): JsonResponse
    {
        $meta = [
            'meta' => [
                'server_time' => time(),
                'server_timezone' => date_default_timezone_get(),
                'api_version' => 'v1',
            ],
        ];

        return response()->json(array_merge($data, $meta), $this->getStatusCode(), $headers);
    }
1076176
public function map($data)
    {
        $data = $this->parseToArray($data);
        $this->clearDynamic($data);

        // Parse each specified field
        foreach ($this->schema->fields as $key => $fieldType) {
            $data[$key] = $this->parseField($data[$key] ?? null, $fieldType);
        }

        return $data;
    }
1240980
public function setFormMapper(FormMapper $mapper)
	{
		$this->formMapper = $mapper;
		$mapper->setAdmin($this);
		return $this;
	}
1186982
private static function buildNodes(array $data): MapInterface
    {
        $nodes = new Map('int', Node::class);

        foreach ($data as $response) {
            foreach ($response['graph']['nodes'] as $node) {
                $labels = Set::of('string', ...\array_values($node['labels']));

                $nodes = $nodes->put(
                    (int) $node['id'],
                    new Node\Node(
                        new Id((int) $node['id']),
                        $labels,
                        self::buildProperties($node['properties'])
                    )
                );
            }
        }

        return $nodes;
    }
420306
protected function jsonResponse($data = array())
    {
        $this->view->disable();
        $this->response->setContentType('application/json', 'UTF-8');

        return $this->response->setJsonContent($data);
    }