@param null|mixed $data
@param null|callable|\League\Fractal\TransformerAbstract $transformer
@param null|\League\Fractal\Serializer\SerializerAbstract $serializer

@return \Spatie\Fractalistic\Fractal
550392
public static function create($data = null, $transformer = null, $serializer = null)
    {
        $fractal = parent::create($data, $transformer, $serializer);

        if (config('fractal.auto_includes.enabled')) {
            $requestKey = config('fractal.auto_includes.request_key');

            if ($include = app('request')->query($requestKey)) {
                $fractal->parseIncludes($include);
            }
        }

        if (empty($serializer)) {
            $serializer = config('fractal.default_serializer');
        }

        if ($data instanceof LengthAwarePaginator) {
            $paginator = config('fractal.default_paginator');

            if (empty($paginator)) {
                $paginator = IlluminatePaginatorAdapter::class;
            }

            $fractal->paginateWith(new $paginator($data));
        }

        if (empty($serializer)) {
            return $fractal;
        }

        if ($serializer instanceof SerializerAbstract) {
            return $fractal->serializeWith($serializer);
        }

        if ($serializer instanceof Closure) {
            return $fractal->serializeWith($serializer());
        }

        if ($serializer == JsonApiSerializer::class) {
            $baseUrl = config('fractal.base_url');

            return $fractal->serializeWith(new $serializer($baseUrl));
        }

        return $fractal->serializeWith(new $serializer);
    }
784214
protected function primitive($data, $transformer = null, $resourceKey = null)
    {
        return new Primitive($data, $transformer, $resourceKey);
    }
145238
public function present($data)
    {
        if (!class_exists('League\Fractal\Manager')) {
            throw new Exception(trans('repository::packages.league_fractal_required'));
        }

        if ($data instanceof Collection) {
            $this->resource = $this->transformCollection($data);
        } elseif ($data instanceof AbstractPaginator) {
            $this->resource = $this->transformPaginator($data);
        } else {
            $this->resource = $this->transformItem($data);
        }

        // set meta
        $this->resource->setMeta($this->meta);

        return $this->fractal->createData($this->resource)->toArray();
    }
7314
protected function parseTransformer($transformer, Model $model)
    {
        if ($transformer instanceof Transformer) {
            $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations($model) : $transformer->getRelations();
            $transformer = $transformer->setRelations($relations);

        } elseif (! is_callable($transformer)) {
            throw new InvalidTransformerException($model);
        }

        return $transformer;
    }
1083220
public function createData()
    {
        if (is_null($this->transformer)) {
            throw new NoTransformerSpecified();
        }

        if (is_string($this->serializer)) {
            $this->serializer = new $this->serializer;
        }

        if (! is_null($this->serializer)) {
            $this->manager->setSerializer($this->serializer);
        }

        $this->manager->setRecursionLimit($this->recursionLimit);

        if (! empty($this->includes)) {
            $this->manager->parseIncludes($this->includes);
        }

        if (! empty($this->excludes)) {
            $this->manager->parseExcludes($this->excludes);
        }

        if (! empty($this->fieldsets)) {
            $this->manager->parseFieldsets($this->fieldsets);
        }

        return $this->manager->createData($this->getResource(), $this->resourceName);
    }
241045
final public static function getInstance($data=null)
    {
        $class = get_called_class();
        if (empty($class)) return null;

        if (!isset(self::$_instance)){
            self::$_instance = new $class($data);
        }

        return self::$_instance;
    }
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
        );
    }
1032074
public function item($model, $transformer = null)
    {

        // Prevent error if include dont work
        // This only returns null
        if ( ! $model ) {
            return $this->formatOutput(null);
        }

        // Check if we should call this function on another transformer
        if ( $transformer ) {
            return $transformer->item( $model );
        }

        // Format output to api
        return $this->formatOutput( $this->callTransform( $model ) );
    }
880266
public function denormalize($data, $class, $format = null, array $context = [])
    {
        if (null === $this->serializer) {
            throw new BadMethodCallException('Please set a serializer before calling denormalize()!');
        }
        if (!\is_array($data)) {
            throw new InvalidArgumentException('Data expected to be an array, '.\gettype($data).' given.');
        }
        if ('[]' !== substr($class, -2)) {
            throw new InvalidArgumentException('Unsupported class: '.$class);
        }

        $serializer = $this->serializer;
        $class = substr($class, 0, -2);

        $builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null;
        foreach ($data as $key => $value) {
            if (null !== $builtinType && !('is_'.$builtinType)($key)) {
                throw new NotNormalizableValueException(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, $builtinType, \gettype($key)));
            }

            $data[$key] = $serializer->denormalize($value, $class, $format, $context);
        }

        return $data;
    }
595720
public function deserialize($subject, &$data = array(), SerializerInterface $serializer = null)
    {
        $context = $this->deserializer();
        $context($subject, $data, $serializer);
        return $subject;
    }
40103
public function data($dataType, $data, $transformer = null)
    {
        $this->dataType = $dataType;

        $this->data = $data;

        if (! is_null($transformer)) {
            $this->transformer = $transformer;
        }

        return $this;
    }
264229
public static function requestBuilder(callable $serializer)
    {
        return function (callable $handler) use ($serializer) {
            return function (CommandInterface $command) use ($serializer, $handler) {
                return $handler($command, $serializer($command));
            };
        };
    }
1166960
protected function transformContent(TransformContainerInterface $container)
    {
        if (null === $container->getTransformer()) {
            return $container->getContent();
        }

        $transformer = $this->makeTransformerInstance($container->getTransformer());
        $content     = $container->getContent();

        if ($container->isCollection()) {

            // Detect pagination and convert apply it for Fractal
            $paginator   = null;

            if ($content instanceof Paginator) {
                $paginator = $content;
                $content   = $content->items();
            }

            /** @var FractalCollection $resource */
            $resource = new FractalCollection($content, $transformer);

            if ($paginator) {
                $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
            }

        } else {
            /** @var FractalItem $resource */
            $resource = new FractalItem($content, $transformer);
        }

        return $this->fractalManager->createData($resource)->toArray();
    }
930410
public function unserialize($data)
    {
        $object = @unserialize($data);
        if($object === false) {
            throw new SerializerException("Unable to unserialize data: " . $data);
        }

        return $object;
    }
824719
protected function executeResourceTransformers()
    {
        $transformer = $this->resource->getTransformer();
        $data = $this->resource->getData();

        $transformedData = $includedData = [];

        if ($this->resource instanceof FractalItem) {
            list($transformedData, $includedData[]) = $this->fireTransformer($transformer, $data);
        } elseif ($this->resource instanceof FractalCollection) {
            foreach ($data as $value) {
                list($transformedData[], $includedData[]) = $this->fireTransformer($transformer, $value);
            }
        } elseif ($this->resource instanceof FractalNullResource) {
            $transformedData = null;
            $includedData = [];
        } elseif ($this->resource instanceof NodesResourceContent) {
            $transformedData = (array) $data;
            $includedData = [];
        } else {
            throw new InvalidArgumentException(
                'Argument $resource should be an instance of League\Fractal\Resource\Item'
                .' or League\Fractal\Resource\Collection'
            );
        }

        return [$transformedData, $includedData];
    }
1056359
public function transform($output, $transformer, $serializer = null)
    {
        if ($serializer !== null) {
            $this->fractal->setSerializer($this->createSerializer($serializer));
        }

        $collector = [];
        foreach ($transformer as $transform) {
            if ($transform != null) {
                $resource       = new Collection($output, $this->createTransformer($transform));
                $collection     = $this->fractal->createData($resource)->toArray();
                $transformed    = $collection['data'] ?? $collection;
                $collector      = array_map(
                    function ($item_collector, $item_transformed) {
                        if ($item_collector === null) {
                            $item_collector = [];
                        }

                        return array_merge($item_collector, $item_transformed);
                    }, $collector, $transformed
                );
            }
        }

        return $collector;
    }
824313
protected function fireIncludedTransformers($transformer, $data)
    {
        $this->availableIncludes = $transformer->getAvailableIncludes();

        return $transformer->processIncludedResources($this, $data) ?: [];
    }