Bind an item to a transformer and start building a response.

@param object                 $item
@param string|callable|object $transformer
@param array                  $parameters
@param \Closure               $after

@return \Dingo\Api\Http\Response
191264
public function item($item, $transformer, $parameters = [], Closure $after = null)
    {
        $class = get_class($item);

        if ($parameters instanceof \Closure) {
            $after = $parameters;
            $parameters = [];
        }

        $binding = $this->transformer->register($class, $transformer, $parameters, $after);

        return new Response($item, 200, [], $binding);
    }
221010
function after(results, next) {
    item.trigger('after:' + method, function done(error) {
      next(error, results);
    });
  }
1323333
public function _handleItemAfterSync($item, $result)
    {
        $curlError = $this->_checkCurlError($item);

        if (!$curlError) {
            if (isset($result->message) && !isset($result->id)) {
                $item->setImportStatus(\Dotdigitalgroup\Email\Model\Importer::FAILED)
                    ->setMessage($result->message);

                $this->importerResource->save($item);
            } elseif (isset($result->id) && !isset($result->message)) {
                $item->setImportStatus(\Dotdigitalgroup\Email\Model\Importer::IMPORTING)
                    ->setImportId($result->id)
                    ->setImportStarted(time())
                    ->setMessage('');
                $this->importerResource->save($item);
            } else {
                $message = (isset($result->message)) ? $result->message : 'Error unknown';
                $item->setImportStatus(\Dotdigitalgroup\Email\Model\Importer::FAILED)
                    ->setMessage($message);

                //If result id
                if (isset($result->id)) {
                    $item->setImportId($result->id);
                }

                $this->importerResource->save($item);
            }
        }
    }
1188136
public function items($items)
    {
        if ($items instanceof Closure) {
            $items = $items();
        }

        array_map(array($this, 'item'), (array) $items);

        return $this;
    }
919012
protected function respondWithSuccess($data, TransformerAbstract $transformer = null, array $headers = [])
    {
        if ($transformer) {
            return $this->respondTransformer($data, SymfonyResponse::HTTP_OK, $transformer, $headers);
        }
        return $this->respondWithSimpleSuccess($data);
    }
1028300
protected function transform($instance, string $transformer, ?string $serializer = null, array $options = [])
    {
        if (\is_null($serializer)) {
            $serializer = $transformer;
        }

        return $this->serializeWith(
            $this->transformWith($instance, $transformer, $options),
            $serializer,
            $options
        );
    }
1118704
public static function after($clazz, $actions, $afterClazz, $warpAction, $call = null) {
        $actions = static::actionsBuild($actions);
        if (!isset(static::$afterActions[ $clazz ])) {
            static::$afterActions[ $clazz ] = array();
        }
        if (!isset(static::$afterActions[ $clazz ][ $actions[ 'type' ] ])) {
            static::$afterActions[ $clazz ][ $actions[ 'type' ] ] = array();
        }
        $info = array('methods' => $actions[ 'methods' ],
                      'class' => $afterClazz,
                      'action' => $warpAction,
                      "call" => $call,
                      "range" => static::$range);
        static::$range++;
        static::$afterActions[ $clazz ][ $actions[ 'type' ] ][] = $info;
    }
331085
protected function lookInDeep(array $elements, $after, $item, &$buffer = [], &$return = '', $current = null)
    {
        $branch = array();

        foreach ($elements as $key => $element) {
            $return = strlen($return) <= 0 ? $current : $return . '.' . $current;
            if ($return . '.' . $key == $after) {
                $this->buffer($buffer, $elements, $item, $after, $current);
            }
            if ($element instanceof Fluent) {
                $element = $element->toArray();
            }
            if (!empty($element['childs'])) {
                $children = $this->lookInDeep($element['childs'], $after, $item, $buffer, $return, $key);
                if ($children) {
                    $element[$key]['childs'] = $children;
                }
            } else {
                $return = '';
            }

            $branch[$key] = $element;
        }

        return $branch;
    }
1081344
function transformItem(stream, item) {
    var ret;
    if (isArray(item)) {
        if (isHashArray(item)) {
            ret = transformHashArrayData(stream, item);
        } else {
            ret = transformArrayData(stream, item);
        }
    } else {
        ret = transformHashData(stream, item);
    }
    return ret;
}
954865
public function with($transformer)
    {
        $concrete = self::getTransformerFactory()->make($transformer);

        $this->resource->setTransformer($concrete);

        return Presentation::of($this->resource);
    }
762717
public function items($params = [], \DateTime $updatedAfter = null)
    {
        $params = array_merge($this->auth->getCredentials(), $params);

        if ($updatedAfter !== null) {
            $this->client->addRequestHeaders([
                'If-Modified-Since' => $updatedAfter->format('D, d M Y H:i:s')
            ]);
        }

        return $this->client->get(self::ACTION_NAME, $params);
    }
366406
public function item($data, $transformer = null, $resourceKey = null): Item
    {
        return new Item($data, $transformer, $resourceKey);
    }
947566
public function validateAfter($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'after');

        return $this->compareDates($attribute, $value, $parameters, '>');
    }
52419
public function formatItem($item, $format = 'json')
    {
        $formatted = null;

        switch ($format) {
            case 'json':
                // serialize properties with null values
                $context = new SerializationContext();
                $context->setSerializeNull(true);
                $context->enableMaxDepthChecks(true);
                $formatted = $this->getSerializer()->serialize($item, 'json', $context);
                break;
            case 'jsonp':
                $callback = $this->getRequest()->query->get('jsonp.callback', 'JSONP.callback');

                // validate against XSS
                $validator = new \JsonpCallbackValidator();
                if (!$validator->validate($callback)) {
                    throw new BadRequestHttpException('Invalid JSONP callback value');
                }

                $context = new SerializationContext();
                $context->setSerializeNull(true);
                $json = $this->getSerializer()->serialize($item, 'json');

                $formatted = sprintf('/**/%s(%s)', $callback, $json);
                break;
            default:
                // any other format is not supported
                throw new \InvalidArgumentException(sprintf('Format not supported: %s', $format));
        }

        return $formatted;
    }
630614
public static function callable(callable $transformer, array $params, string $method = '__invoke'): array
    {
        if (TransformerHelper::isClosure($transformer)) {
            return static::closure($transformer, $params);
        }

        if (empty($params)) {
            return $params;
        }

        try {
            if (is_array($transformer)) {
                $method = $transformer[1] ?? $method;
                $transformer = $transformer[0] ?? $transformer;
            }

            list($one) = self::interpretFunction(
                new \ReflectionMethod($transformer, $method),
                $params
            );

            return $one;
        } catch (\ReflectionException $e) {
            // Sorry
        }

        return [];
    }
1353323
protected function createBinding($resolver, array $parameters = [], Closure $callback = null)
    {
        return new Binding($this->container, $resolver, $parameters, $callback);
    }
1119646
private function parseItem(Item $item)
    {
        // Get and format an item
        $tmp = $this->getFormattedItem($item);

        // Get related data
        $relationships = $this->getRelationships($item);

        // Closure function to internally parse related includes
        $parseRelationships = function($key, Item $item, array $relationships = []) {
            $related = $this->getFormattedItem($item);

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

            unset($related['attributes']);
            unset($related['links']);
            $relationships[$key]['data'][] = $related;

            return $relationships;
        };

        // Loop data to create includes response data
        foreach ($relationships as $key => $value) {
            if ($value instanceof Collection) {
                foreach ($value->getData() as $include_value) {
                    $relationships = $parseRelationships($key, new Item($include_value, $value->getTransformer()), $relationships);
                }
            } else if ($value instanceof Item) {
                $relationships = $parseRelationships($key, $value, $relationships);
            }
        }

        // Pass the relationships data into the item
        $tmp['relationships'] = $relationships;

        // Set the response data
        if (is_array($this->data)) {
            $this->data[] = $tmp;
        } else {
            $this->data = $tmp;
        }

        return $this;
    }