-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialise_collection.php
49 lines (42 loc) · 1.1 KB
/
serialise_collection.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
48
49
<?php
require_once('./vendor/autoload.php');
use Micronative\EntityPatcher\Patcher;
use Samples\Entity\Company;
use Samples\Entity\Role;
use Samples\Entity\User;
$patcher = new Patcher();
$company = new Company();
$company
->setId(1)
->setName('Micronative');
$role1 = new Role();
$role1
->setId(1)
->setType('Admin');
$role2 = new Role();
$role2
->setId(21)
->setType('Manager');
$user1 = new User();
$user1
->setId(2)
->setEmail('ken.ngo@micronative.com')
->setFirstName('Ken')
->setLastName('Ngo')
->setCompany($company);
$role1->setUsers([$user1]);
$user1->setRoles([$role1, $role2]);
$user2 = new User();
$user2
->setId(3)
->setEmail('May.ngo@micronative.com')
->setFirstName('May')
->setLastName('Ngo')
->setCompany($company);
$role2->setUsers([$user2]);
# serialise to array KEYED_BY_PROPERTY
$rolesArray = $patcher->serialiseCollection([$role1, $role2], Patcher::KEYED_BY_PROPERTY);
print_r($rolesArray);
# serialise to array KEYED_BY_COLUMN
$rolesArray = $patcher->serialiseCollection([$role1, $role2], Patcher::KEYED_BY_COLUMN);
print_r($rolesArray);