2019-03-28 03:36:36 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-03-28 03:36:36 +01:00
|
|
|
|
2019-03-28 22:34:58 +01:00
|
|
|
namespace App\Transformers;
|
2019-03-28 03:36:36 +01:00
|
|
|
|
|
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
|
|
|
|
class EntityTransformer extends TransformerAbstract
|
|
|
|
{
|
|
|
|
protected $serializer;
|
|
|
|
|
2019-03-28 22:34:58 +01:00
|
|
|
const API_SERIALIZER_ARRAY = 'array';
|
|
|
|
const API_SERIALIZER_JSON = 'json';
|
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
public function __construct($serializer = null)
|
|
|
|
{
|
|
|
|
$this->serializer = $serializer;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function includeCollection($data, $transformer, $entityType)
|
|
|
|
{
|
2019-03-28 22:34:58 +01:00
|
|
|
if ($this->serializer && $this->serializer != self::API_SERIALIZER_JSON) {
|
2019-03-28 03:36:36 +01:00
|
|
|
$entityType = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->collection($data, $transformer, $entityType);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function includeItem($data, $transformer, $entityType)
|
|
|
|
{
|
2019-03-28 22:34:58 +01:00
|
|
|
if ($this->serializer && $this->serializer != self::API_SERIALIZER_JSON) {
|
2019-03-28 03:36:36 +01:00
|
|
|
$entityType = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->item($data, $transformer, $entityType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDefaultIncludes()
|
|
|
|
{
|
|
|
|
return $this->defaultIncludes;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDefaults($entity)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|