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