File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change
1
+ # Presento
2
+
3
+ A data preparing and presenting package for PHP.
4
+
5
+ ## Why Presento?
6
+
7
+ Presento is a simple but powerful tools for preparing and presenting data.
8
+ When we build an API based application, we need transform before it present or response.
Original file line number Diff line number Diff line change 5
5
6
6
abstract class Presenter
7
7
{
8
+ protected $ transformer = null ;
8
9
protected $ data = [];
9
10
protected $ generatedData = [];
10
11
11
- public function __construct (array $ data )
12
+ public function __construct (array $ data, string $ transformer = null )
12
13
{
13
14
$ this ->data = $ data ;
15
+ $ this ->transformer = $ this ->transformer ();
16
+ if (!is_null ($ transformer )) {
17
+ $ this ->transformer = $ transformer ;
18
+ }
19
+
14
20
$ this ->generatedData = $ this ->handle ();
15
21
}
16
22
@@ -95,7 +101,7 @@ public function process(array $data) : array
95
101
*/
96
102
protected function transform (array $ data ) : array
97
103
{
98
- $ transformerClass = $ this ->transformer () ;
104
+ $ transformerClass = $ this ->transformer ;
99
105
100
106
if (!is_null ($ transformerClass )) {
101
107
$ transformer = new $ transformerClass ($ data );
You can’t perform that action at this time.
0 commit comments