@@ 5-48 (lines=44) @@ | ||
2 | ||
3 | namespace Borfast\Socializr; |
|
4 | ||
5 | class Group |
|
6 | { |
|
7 | public $id; |
|
8 | public $name; |
|
9 | public $picture; |
|
10 | public $link; |
|
11 | public $access_token; |
|
12 | public $can_post = false; |
|
13 | ||
14 | public $provider; |
|
15 | public $raw_response; |
|
16 | ||
17 | ||
18 | /** |
|
19 | * Create a new Group object based on an array of attributes and a mapping |
|
20 | * from those attributes to the Profile object's attributes. |
|
21 | * The $mapping array should have this format (example for Facebook page): |
|
22 | * $mapping = [ |
|
23 | * 'id' => 'id', |
|
24 | * 'email' => 'email', |
|
25 | * 'name' => 'name', |
|
26 | * 'first_name' => 'first_name', |
|
27 | * 'middle_name' => 'middle_name', |
|
28 | * 'last_name' => 'last_name', |
|
29 | * 'username' => 'username', |
|
30 | * 'link' => 'link' |
|
31 | * ]; |
|
32 | * The keys are the name of the Group object attributes, while the values |
|
33 | * are the key of that attribute in the $attributes array. Like so: |
|
34 | * ['group_object_attribute' => 'key_in_attributes_array'] |
|
35 | * |
|
36 | * @author Raúl Santos |
|
37 | */ |
|
38 | public static function create(array $mapping, array $attributes) |
|
39 | { |
|
40 | $group = new Group; |
|
41 | ||
42 | foreach ($mapping as $key => $name) { |
|
43 | $group->$key = (isset($attributes[$name])) ? $attributes[$name] : null; |
|
44 | } |
|
45 | ||
46 | return $group; |
|
47 | } |
|
48 | } |
|
49 |
@@ 5-50 (lines=46) @@ | ||
2 | ||
3 | namespace Borfast\Socializr; |
|
4 | ||
5 | class Page |
|
6 | { |
|
7 | public $id; |
|
8 | public $name; |
|
9 | public $picture; |
|
10 | public $link; |
|
11 | public $access_token; |
|
12 | public $can_post = false; |
|
13 | public $likes; |
|
14 | public $fan_count; |
|
15 | ||
16 | public $provider; |
|
17 | public $raw_response; |
|
18 | ||
19 | ||
20 | /** |
|
21 | * Create a new Page object based on an array of attributes and a mapping |
|
22 | * from those attributes to the Profile object's attributes. |
|
23 | * The $mapping array should have this format (example for Facebook Page): |
|
24 | * $mapping = [ |
|
25 | * 'id' => 'id', |
|
26 | * 'email' => 'email', |
|
27 | * 'name' => 'name', |
|
28 | * 'first_name' => 'first_name', |
|
29 | * 'middle_name' => 'middle_name', |
|
30 | * 'last_name' => 'last_name', |
|
31 | * 'username' => 'username', |
|
32 | * 'link' => 'link' |
|
33 | * ]; |
|
34 | * The keys are the name of the Page object attributes, while the values |
|
35 | * are the key of that attribute in the $attributes array. Like so: |
|
36 | * ['page_object_attribute' => 'key_in_attributes_array'] |
|
37 | * |
|
38 | * @author Raúl Santos |
|
39 | */ |
|
40 | public static function create(array $mapping, array $attributes) |
|
41 | { |
|
42 | $page = new Page; |
|
43 | ||
44 | foreach ($mapping as $key => $name) { |
|
45 | $page->$key = (isset($attributes[$name])) ? $attributes[$name] : null; |
|
46 | } |
|
47 | ||
48 | return $page; |
|
49 | } |
|
50 | } |
|
51 |