Add all of the potential transformers that might be needed for now.

This commit is contained in:
Dane Everitt 2017-04-07 20:28:58 -04:00
parent 65630bdcce
commit 51204b8d9d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
12 changed files with 642 additions and 9 deletions

View file

@ -30,12 +30,55 @@ use League\Fractal\TransformerAbstract;
class AllocationTransformer extends TransformerAbstract
{
/**
* Return a generic transformed server array.
* The filter to be applied to this transformer.
*
* @var bool|string
*/
protected $filter;
/**
* Transformer constructor.
*
* @param bool|string $filter
* @return void
*/
public function __construct($filter = false)
{
$this->filter = $filter;
}
/**
* Return a generic transformed allocation array.
*
* @return array
*/
public function transform(Allocation $allocation)
{
return $this->transformWithFilter($allocation);
}
/**
* Determine which transformer filter to apply.
*
* @return array
*/
protected function transformWithFilter(Allocation $allocation)
{
if ($this->filter === 'server') {
return $this->transformForServer($allocation);
}
return $allocation->toArray();
}
/**
* Transform the allocation to only return information not duplicated
* in the server response (discard node_id and server_id).
*
* @return array
*/
protected function transformForServer(Allocation $allocation)
{
return collect($allocation)->only('id', 'ip', 'ip_alias', 'port')->toArray();
}
}