2018-01-20 03:47:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Extensions\Spatie\Fractalistic;
|
|
|
|
|
2018-01-26 03:26:06 +00:00
|
|
|
use League\Fractal\TransformerAbstract;
|
2018-01-26 04:34:53 +00:00
|
|
|
use Spatie\Fractal\Fractal as SpatieFractal;
|
2018-01-20 03:47:06 +00:00
|
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
2018-01-27 18:38:56 +00:00
|
|
|
use Pterodactyl\Extensions\League\Fractal\Serializers\PterodactylSerializer;
|
2018-01-20 03:47:06 +00:00
|
|
|
|
|
|
|
class Fractal extends SpatieFractal
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create fractal data.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Scope
|
|
|
|
*
|
|
|
|
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
|
|
|
|
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
|
|
|
|
*/
|
|
|
|
public function createData()
|
|
|
|
{
|
|
|
|
// Set the serializer by default.
|
|
|
|
if (is_null($this->serializer)) {
|
2018-01-27 18:38:56 +00:00
|
|
|
$this->serializer = new PterodactylSerializer;
|
2018-01-20 03:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Automatically set the paginator on the response object if the
|
|
|
|
// data being provided implements a paginator.
|
|
|
|
if (is_null($this->paginator) && $this->data instanceof LengthAwarePaginator) {
|
|
|
|
$this->paginator = new IlluminatePaginatorAdapter($this->data);
|
|
|
|
}
|
|
|
|
|
2018-01-26 03:26:06 +00:00
|
|
|
// If the resource name is not set attempt to pull it off the transformer
|
|
|
|
// itself and set it automatically.
|
|
|
|
if (
|
|
|
|
is_null($this->resourceName)
|
|
|
|
&& $this->transformer instanceof TransformerAbstract
|
|
|
|
&& method_exists($this->transformer, 'getResourceName')
|
|
|
|
) {
|
|
|
|
$this->resourceName = $this->transformer->getResourceName();
|
2018-01-21 20:37:57 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
return parent::createData();
|
|
|
|
}
|
|
|
|
}
|