Create FractalCollection payload.

@param IlluminateCollection|array $collection
@param null $transformer
@param string|null $resourceKey
@return mixed
546923
public function getCollection($collection, $transformer = null, $resourceKey = null)
    {
        $resource = new FractalCollection(
            $collection,
            $this->getTransformer($transformer),
            $this->getResourceKey($resourceKey)
        );

        if ($meta = $this->getMeta()) {
            $resource->setMeta($meta);
            $this->meta = [];
        }

        return $this->fractal->createData($resource)->toArray();
    }
841442
@CheckResult
    @NonNull
    public final PowerAdapter compose(@NonNull Transformer transformer) {
        return checkNotNull(transformer, "transformer").transform(this);
    }
424699
public function collection(
        ResourceManager $resourceManager,
        ApiRequest $request,
        int $version,
        string $resource
    )
    {
        $resourceManager->version($version);

        /** @var HandlesCollectionRequest $handler */
        $handler = $this->initializeHandler($resourceManager, $resource, $request, HandlesCollectionRequest::class);

        $parameters = $request->asParameters();

        $repository = $this->initializeRepository($resourceManager, $resource, $parameters);

        $result = $handler->index($repository, $parameters);

        $document = $this->makeDocumentFromCollection($resourceManager, $resource, $result, $parameters, $handler);

        return $this->respond($document);
    }
357297
public function transformItem($resource, TransformerInterface $transformer)
    {
        $data = $transformer->execute($resource);

        $rootKey = $this->options['root_key'];
        if ($rootKey) {
            return [$rootKey => $data];
        }

        return $data;
    }
482767
public function transformCollection($items, $includes = [], TransformerContract $transformer = null, $meta = [])
    {
        $this->fractal_manager->parseIncludes($includes);
        $transformer = is_null($transformer) ? $this->getTransformer() : $transformer;
        $resource = new Collection($items, $transformer, $this->getModelName());

        $resource->setMeta($meta);
        if ($items instanceof LengthAwarePaginator) {
            $resource->setPaginator(new IlluminatePaginatorAdapter($items));
        }

        return $this->fractal_manager->createData($resource)->toArray();
    }
196129
public static function make($key, $resource, $version = 'v2')
    {
        $client = new Client($key, $version);

        $namespace = 'Rule\\ApiWrapper\\Api\\' . strtoupper($version) . '\\' . ucfirst($resource) . '\\';
        $classname = $namespace . ucfirst($resource);

        if (!class_exists($classname)) {
            throw new InvalidResourceException("Invalid resource name providen or api version not supported");
        }

        return new $classname($client);
    }
1245095
public function collection($data, $transformer = null, $resourceKey = null): Collection
    {
        return new Collection($data, $transformer, $resourceKey);
    }
870071
private function makeDocumentFromCollection(
        ResourceManager $resourceManager,
        string $resource,
        $result,
        Parameters $parameters,
        ApiRequestHandler $handler
    )
    {
        $document = new Document();
        $serializer = $resourceManager->resolveSerializer($resource);
        if ($handler instanceof ModifiesSerializer) {
            $serializer = $handler->modify($serializer);
        }
        $collection = new Collection($result, $serializer);
        if ($handler instanceof HasElementIncludes) {
            $handler->includes($collection);
        }

        $this->assignAndResolveIncludes($resourceManager, $resource, $collection, $parameters);
        $document->setData($collection);

        if ($handler instanceof HasDocumentMeta) {
            $handler->meta($document);
        }

        if (config('json-api.response.resources.links.self', false)) {
            $document->addLink('self', apiRoute($resource, null, request()->route('version')));
        }

        return $document;
    }
1205843
public function collection($data, $transformer = null, $resourceName = null)
    {
        if (! is_null($resourceName)) {
            $this->resourceName = $resourceName;
        }

        return $this->data('collection', $data, $transformer);
    }
1078026
public function transformCollection($collection, $meta = [])
    {
        return $this->getFractalFactory()->makeCollection($collection, $meta, $this->getTransformer());
    }
157052
public function primitive($data, $transformer = null, $resourceName = null)
    {
        if (! is_null($resourceName)) {
            $this->resourceName = $resourceName;
        }

        return $this->data('primitive', $data, $transformer);
    }
317564
protected function executeResourceTransformers()
    {
        $transformer = $this->resource->getTransformer();
        $data = $this->resource->getData();

        $transformedData = $includedData = [];

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

        return [$transformedData, $includedData];
    }
780556
public function collection($data, $transformer, $resourceKey = null, Cursor $cursor = null, $meta = [])
    {
        if (!is_object($transformer) && !is_callable($transformer)) {
            $transformer = $this->di->getShared($transformer);
        }

        $resource = new Collection($data, $transformer, $resourceKey);

        foreach ($meta as $metaKey => $metaValue) {
            $resource->setMetaValue($metaKey, $metaValue);
        }

        if (!is_null($cursor)) {
            $resource->setCursor($cursor);
        }

        $rootScope = $this->getManager()->createData($resource);

        return $rootScope->toArray();
    }
898126
private function getOrCreateCollection($key, $localizedTitles, $userId, $parent)
    {
        $locales = array_keys($localizedTitles);
        $firstLocale = array_shift($locales);

        $collection = $this->collectionManager->getByKey($key, $firstLocale);
        if (null === $collection) {
            $collection = $this->createCollection($localizedTitles[$firstLocale], $key, $firstLocale, $userId, $parent);
        } else {
            $collection->setTitle($localizedTitles[$firstLocale]);
        }

        foreach ($locales as $locale) {
            $this->createCollection($localizedTitles[$locale], $key, $locale, $userId, $parent, $collection->getId());
        }

        return $collection;
    }
757820
public function getResources(
        ResourceTransformer $resourceTransformer,
        ResourceDefinition $resourceDefinition,
        Context $context,
        $request = null
    ) {
        if (!$this->hasApplicableContentType()) {
            return null;
        }

        $rawContent = $this->getRawContent();
        $content = json_decode($rawContent, true);

        if (!$content) {
            throw new \InvalidArgumentException("Could not decode body: " . $rawContent);
        }

        $resourceCollection = $resourceTransformer->getResourceFactory()->createResourceCollection();

        if (isset($content[ResourceTransformer::RELATIONSHIP_ITEMS])) {
            // This is a list of items
            foreach ($content[ResourceTransformer::RELATIONSHIP_ITEMS] as $item) {
                $resource = $resourceTransformer->fromArray(
                    $resourceDefinition,
                    $item,
                    $context
                );
                $resourceCollection->add($resource);
            }
        } else {
            $resource = $resourceTransformer->fromArray(
                $resourceDefinition,
                $content,
                $context
            );
            $resourceCollection->add($resource);
        }

        return $resourceCollection;
    }
344682
public function buildLayer(Layer $nextLayer, array $arguments)
    {
        $transformerClass = isset($arguments['class']) ? $arguments['class'] : '';
        $isList = isset($arguments['list']) && $arguments['list'] == true;

        if (trim($transformerClass) == '') {
            return $nextLayer;
        }

        return new FractalRenderingLayer($this->container, $this->manager, $nextLayer, $transformerClass, $isList);
    }
428426
public function applyTransformation(ITokenTransformation $transformer, $removeNulls = true) 
    {        
        foreach($this->tokens as &$token) 
        { 
            $token = $transformer->transform($token);
        }
        //filter null tokens and re-index
        if($removeNulls) {
            $this->tokens = array_values(array_filter($this->tokens));
        }
        return $this;
    }