Path: blob/1.0-develop/app/Extensions/Spatie/Fractalistic/Fractal.php
10311 views
<?php12namespace Pterodactyl\Extensions\Spatie\Fractalistic;34use League\Fractal\Scope;5use League\Fractal\TransformerAbstract;6use Spatie\Fractal\Fractal as SpatieFractal;7use Illuminate\Contracts\Pagination\LengthAwarePaginator;8use League\Fractal\Pagination\IlluminatePaginatorAdapter;9use Pterodactyl\Extensions\League\Fractal\Serializers\PterodactylSerializer;1011class Fractal extends SpatieFractal12{13/**14* Create fractal data.15*16* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation17* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified18*/19public function createData(): Scope20{21// Set the serializer by default.22if (is_null($this->serializer)) {23$this->serializer = new PterodactylSerializer();24}2526// Automatically set the paginator on the response object if the27// data being provided implements a paginator.28if (is_null($this->paginator) && $this->data instanceof LengthAwarePaginator) {29$this->paginator = new IlluminatePaginatorAdapter($this->data);30}3132// If the resource name is not set attempt to pull it off the transformer33// itself and set it automatically.34if (35is_null($this->resourceName)36&& $this->transformer instanceof TransformerAbstract37&& method_exists($this->transformer, 'getResourceName')38) {39$this->resourceName = $this->transformer->getResourceName();40}4142return parent::createData();43}44}454647