Fractal transform a collection

@param object $items $items
@param array                $includes           Any transformer includes to use
@param string $transformer Namespaced Transformer
@param string $model_name Model Name
@return array
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();
    }
603515
public function serializeItem($item, TransformerAbstract $transformer = null, $resourceKey = null)
    {
        return $this->getFractalService()
            ->item($item, $transformer, $resourceKey);
    }
83252
public static function mergeNodes($items1, $items2)
    {
        $ret = array();
        $items = array_merge($items1, $items2);
        $len = count($items);

        // collects non-repeated elements
        for ($i = 0; $i < $len; $i++) {
            $item = $items[$i];
            $position = Dom::searchNode($item, $items, $i + 1);
            if ($position === false) {
                array_push($ret, $item);
            }
        }
        
        return $ret;
    }
884959
public function getItem(EloquentModel $model, $transformer = null, $resourceKey = null)
    {
        $resource = new FractalItem(
            $model,
            $this->getTransformer($transformer),
            $this->getResourceKey($resourceKey)
        );

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

        return $this->fractal->createData($resource)->toArray();
    }
495337
public function includeOptions(PollModelContract $item): FractalCollection
    {
        $transformer = app()->make(
            'InetStudio\PollsPackage\Analytics\Contracts\Transformers\Back\Result\PollOptionTransformerContract',
            [
                'totalVotes' => $item['options']->sum('votes_count'),
            ]
        );

        return new FractalCollection($item['options'], $transformer);
    }
124540
public function transform(CommentModelContract $item): array
    {
        return [
            'checkbox' => view('admin.module.comments::back.partials.datatables.checkbox', [
                'id' => $item->id,
            ])->render(),
            'id' => (int) $item->id,
            'read' => view('admin.module.comments::back.partials.datatables.read', [
                'is_read' => $item->is_read,
            ])->render(),
            'active' => view('admin.module.comments::back.partials.datatables.active', [
                'id' => $item->id,
                'is_active' => $item->is_active,
            ])->render(),
            'name' => $item->name,
            'email' => $item->email,
            'message' => $item->message,
            'created_at' => (string) $item->created_at,
            'material' => view('admin.module.comments::back.partials.datatables.material', [
                'item' => $item->commentable,
            ])->render(),
            'actions' => view('admin.module.comments::back.partials.datatables.actions', [
                'id' => $item->id,
            ])->render(),
        ];
    }
329313
public ModelAdapter<?, Item> add(List<Item> items) {
        if (mOriginalItems != null && items.size() > 0) {
            if (mItemAdapter.isUseIdDistributor()) {
                mItemAdapter.getIdDistributor().checkIds(items);
            }
            mOriginalItems.addAll(items);
            publishResults(mConstraint, performFiltering(mConstraint));
            return mItemAdapter;
        } else {
            return mItemAdapter.addInternal(items);
        }
    }
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);
    }
440475
public static function menuToRules($items)
    {
        $rules = [];
        foreach ($items as $item) {
            $url = ArrayHelper::getValue($item, 'url');
            $urlRule = ArrayHelper::getValue($item, 'urlRule');

            if ($url && $urlRule && is_array($url)) {
                $defaults = $url;
                $route = array_shift($defaults);

                if (is_string($urlRule)) {
                    $rules[] = [
                        'pattern' => Yii::getAlias($urlRule),
                        'route' => $route,
                    ];
                } elseif (is_array($urlRule)) {
                    if (!isset($urlRule['route'])) {
                        $urlRule['route'] = $route;
                    }
                    $rules[] = $urlRule;
                }
            }

            $subItems = ArrayHelper::getValue($item, 'items');
            if (is_array($subItems)) {
                $rules = array_merge(static::menuToRules($subItems), $rules);
            }
        }
        return $rules;
    }
573284
static function transform($modelOrCollection, $options = [])
    {
        $static = new static($options);

        if ($modelOrCollection instanceof Collection) {
            return $modelOrCollection->map([$static, 'transformModel'])->toArray();
        }

        return $static->transformModel($modelOrCollection);
    }
744077
public ModelAdapter<Model, Item> set(List<Model> items) {
        return set(items, true);
    }
865453
protected function getArrayableItems($items)
    {
        if (is_array($items)) {
            return $items;
        }

        if ($items instanceof Traversable) {
            return iterator_to_array($items);
        }

        return (array) $items;
    }
478005
private function createList(Mapper $mapper, array $items)
    {
        $result = [];
        foreach ($items as $item) {
            $result[] = $mapper->createObject($item);
        }

        return $result;
    }
330301
protected function extractItems($items) : iterable
    {
        // Catch arrays and Traversable objects.
        // By extension, this also includes other Collections (via their Iterator) *and* generators.
        // Keep especially the latter in mind when overriding concrete Collections.
        if (is_iterable($items)) {
            return $items;
        }

        // Arbitrary interfaces in order of preference.
        if ($items instanceof core\interfaces\Arrayable) {
            return $items->toArray();
        }

        if ($items instanceof \JsonSerializable) {
            return $items->jsonSerialize();
        }

        if ($items instanceof core\interfaces\Jsonable) {
            return json_decode($items->toJson(), true);
        }

        // Worst case scenario - use PHP's internals to attempt to cast it to an array.
        return (array) $items;
    }
1238736
public static function itemsList($items, $validator)
    {
        foreach ($items as $item)
        {
            if (!self::$validator($item))
            {
                return false;
            }
        }

        return true;
    }
72303
public function nestedList(array $list, array $options = [], array $itemOptions = [])
    {
        $options = optionsParser($options);
        $itemOptions = optionsParser($itemOptions);

        if ($options->exists('icon')) {
            $itemOptions->add('icon', $options->get('icon'));
        }

        if ($itemOptions->exists('icon')) {
            $options->append('class', 'fa-ul');
            $itemOptions->append('icon', 'li');

            $list = array_map(function ($element) use ($itemOptions) {
                return collection($this->addIconToText($element, clone $itemOptions))->first();
            }, $list);
        }

        $options->delete('icon', 'icon-align');
        $itemOptions->delete('icon', 'icon-align');

        return parent::nestedList($list, $options->toArray(), $itemOptions->toArray());
    }
553418
protected function transformerHasIncludes($transformer)
    {
        if (! $transformer instanceof NodesTransformerAbstract &&
            ! $transformer instanceof FractalTransformerAbstract) {
            return false;
        }

        $defaultIncludes = $transformer->getDefaultIncludes();
        $availableIncludes = $transformer->getAvailableIncludes();

        return ! empty($defaultIncludes) || ! empty($availableIncludes);
    }