-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from morloderex/master
Add None transformer
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Napp\Core\Api\Transformers; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Support\Arr; | ||
|
||
class NoneTransformer implements TransformerInterface | ||
{ | ||
/** | ||
* @param array|Arrayable $data | ||
* @return array | ||
*/ | ||
public function transformInput($data): array | ||
{ | ||
if ($data instanceof Arrayable) { | ||
return $data->toArray(); | ||
} | ||
|
||
return Arr::wrap($data); | ||
} | ||
|
||
/** | ||
* @param array|Arrayable $data | ||
* @return array | ||
*/ | ||
public function transformOutput($data): array | ||
{ | ||
if ($data instanceof Arrayable) { | ||
return $data->toArray(); | ||
} | ||
|
||
return Arr::wrap($data); | ||
} | ||
} |