-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
47 lines (38 loc) · 1.29 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require_once dirname(__FILE__, 3) . '/vendor/autoload.php';
use League\Fractal\Manager;
use League\Fractal\Resource\Collection;
$fractal = new Manager();
$users = [
[
'id' => '1',
'name' => 'Admin Account',
'email' => '[email protected]',
'email_verified' => true,
'password' => '123456',
],
[
'id' => '2',
'name' => 'Mahmoud Mohamed Ramadan',
'email' => '[email protected]',
'email_verified' => true,
'password' => '123456',
]
];
// Passing this array (collection) into a resource, which will also have a "Transformer"
// This "Transformer" can be a callback or a new instance of a Transformer object
// We type hinting for an array, because each item in the `$users` var is an array
// for more info read...https://fractal.thephpleague.com/glossary/
$resource = new Collection($users, function (array $user) {
return [
'id' => (int) $user['id'],
'name' => $user['name'],
'private' => [
'email' => $user['email'],
'email_verified' => $user['email_verified'],
'password' => $user['password'],
],
];
});
$array = $fractal->createData($resource)->toArray();
echo $fractal->createData($resource)->toJson();