-
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.
Create general info serializer and transformer [MA-144]
- Loading branch information
1 parent
7c87284
commit 6bc024b
Showing
3 changed files
with
48 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,16 @@ | ||
<?php | ||
|
||
namespace App\Models\Transformers; | ||
|
||
use A17\Twill\Models\Contracts\TwillModelContract; | ||
use League\Fractal\TransformerAbstract; | ||
|
||
class GeneralInfoTransformer extends TransformerAbstract | ||
{ | ||
public function transform(TwillModelContract $label) | ||
{ | ||
return [ | ||
$label->key => $label->text, | ||
]; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace App\Repositories\Serializers; | ||
|
||
use App\Models\Transformers\GeneralInfoTransformer; | ||
use League\Fractal\Manager; | ||
use League\Fractal\Resource; | ||
use League\Fractal\Serializer\ArraySerializer; | ||
|
||
class GeneralInfoSerializer | ||
{ | ||
protected ?Manager $manager = null; | ||
|
||
public function __construct() | ||
{ | ||
$this->manager = new Manager(); | ||
$this->manager->setSerializer(new AssociativeArraySerializer()); | ||
} | ||
|
||
public function serialize($labels) | ||
{ | ||
$resource = new Resource\Collection($labels, new GeneralInfoTransformer(), 'general_info'); | ||
return $this->manager->createData($resource)->toArray(); | ||
} | ||
} |
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