Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit eca7603

Browse files
committed
Added GraphUserPages (user-id/accounts) as an Iterator, GraphPage with basic attributes and a GraphUserPage extending GraphPage to add the AccessToken and Permissions attributes.
1 parent d8b2bcb commit eca7603

File tree

3 files changed

+264
-0
lines changed

3 files changed

+264
-0
lines changed

src/Facebook/GraphPage.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright 2014 Facebook, Inc.
4+
*
5+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
6+
* use, copy, modify, and distribute this software in source code or binary
7+
* form for use in connection with the web services and APIs provided by
8+
* Facebook.
9+
*
10+
* As with any software that integrates with the Facebook platform, your use
11+
* of this software is subject to the Facebook Developer Principles and
12+
* Policies [http://developers.facebook.com/policy/]. This copyright notice
13+
* shall be included in all copies or substantial portions of the software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
namespace Facebook;
25+
26+
/**
27+
* Class GraphPage
28+
* @package Facebook
29+
* @author Artur Luiz <[email protected]>
30+
*/
31+
class GraphPage extends GraphObject
32+
{
33+
34+
/**
35+
* Returns the ID for the user's page as a string if present.
36+
*
37+
* @return string|null
38+
*/
39+
public function getId()
40+
{
41+
return $this->getProperty('id');
42+
}
43+
44+
/**
45+
* Returns the Category for the user's page as a string if present.
46+
*
47+
* @return string|null
48+
*/
49+
public function getCategory()
50+
{
51+
return $this->getProperty('category');
52+
}
53+
54+
/**
55+
* Returns the Name of the user's page as a string if present.
56+
*
57+
* @return string|null
58+
*/
59+
public function getName()
60+
{
61+
return $this->getProperty('name');
62+
}
63+
64+
}

src/Facebook/GraphUserPage.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright 2014 Facebook, Inc.
4+
*
5+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
6+
* use, copy, modify, and distribute this software in source code or binary
7+
* form for use in connection with the web services and APIs provided by
8+
* Facebook.
9+
*
10+
* As with any software that integrates with the Facebook platform, your use
11+
* of this software is subject to the Facebook Developer Principles and
12+
* Policies [http://developers.facebook.com/policy/]. This copyright notice
13+
* shall be included in all copies or substantial portions of the software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
namespace Facebook;
25+
26+
/**
27+
* Class GraphUserPage
28+
* @package Facebook
29+
* @author Artur Luiz <[email protected]>
30+
*/
31+
class GraphUserPage extends GraphObject
32+
{
33+
34+
/**
35+
* Returns the ID for the user's page as a string if present.
36+
*
37+
* @return string|null
38+
*/
39+
public function getId()
40+
{
41+
return $this->getProperty('id');
42+
}
43+
44+
/**
45+
* Returns the Category for the user's page as a string if present.
46+
*
47+
* @return string|null
48+
*/
49+
public function getCategory()
50+
{
51+
return $this->getProperty('category');
52+
}
53+
54+
/**
55+
* Returns the Name of the user's page as a string if present.
56+
*
57+
* @return string|null
58+
*/
59+
public function getName()
60+
{
61+
return $this->getProperty('name');
62+
}
63+
64+
/**
65+
* Returns the Access Token used to access the user's page as a string if present.
66+
*
67+
* @return string|null
68+
*/
69+
public function getAccessToken()
70+
{
71+
return $this->getProperty('access_token');
72+
}
73+
74+
/**
75+
* Returns the Permissions for the user's page as an array if present.
76+
*
77+
* @return array|null
78+
*/
79+
public function getPermissions()
80+
{
81+
return $this->getProperty('perms');
82+
}
83+
84+
}

src/Facebook/GraphUserPages.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Copyright 2014 Facebook, Inc.
4+
*
5+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
6+
* use, copy, modify, and distribute this software in source code or binary
7+
* form for use in connection with the web services and APIs provided by
8+
* Facebook.
9+
*
10+
* As with any software that integrates with the Facebook platform, your use
11+
* of this software is subject to the Facebook Developer Principles and
12+
* Policies [http://developers.facebook.com/policy/]. This copyright notice
13+
* shall be included in all copies or substantial portions of the software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
namespace Facebook;
25+
26+
/**
27+
* Class GraphUserPages
28+
* @package Facebook
29+
* @author Artur Luiz <[email protected]>
30+
*/
31+
class GraphUserPages extends GraphPage implements \Iterator
32+
{
33+
34+
/**
35+
* @var int The current position of GraphUserPage list
36+
*/
37+
private $position;
38+
39+
/**
40+
* @var GraphUserPage|null The current GraphUserPage
41+
*/
42+
private $currentPage;
43+
44+
/**
45+
* Creates a GraphUserPages using the data provided.
46+
*
47+
* @param array $raw
48+
*/
49+
public function __construct($raw)
50+
{
51+
parent::__construct($raw);
52+
$this->position = 0;
53+
}
54+
55+
/**
56+
* Returns the ID for the user as a string if present.
57+
*
58+
* @return string|null
59+
*/
60+
public function getPages()
61+
{
62+
return $this->getProperty('data');
63+
}
64+
65+
/**
66+
* Returns the page.
67+
*
68+
* @return GraphUserPage|null
69+
*/
70+
public function current()
71+
{
72+
return $this->currentPage;
73+
}
74+
75+
/**
76+
* Returns current key.
77+
*
78+
* @return int
79+
*/
80+
public function key()
81+
{
82+
return $this->position;
83+
}
84+
85+
/**
86+
* Goes to next page.
87+
*
88+
* @return void
89+
*/
90+
public function next()
91+
{
92+
$this->position++;
93+
}
94+
95+
/**
96+
* Goes to first page.
97+
*
98+
* @return void
99+
*/
100+
public function rewind()
101+
{
102+
$this->position = 0;
103+
}
104+
105+
/**
106+
* Returns true if there is any page to show.
107+
*
108+
* @return boolean
109+
*/
110+
public function valid()
111+
{
112+
$this->currentPage = $this->getPages()->getProperty($this->position, GraphUserPage::className());
113+
return !is_null($this->currentPage);
114+
}
115+
116+
}

0 commit comments

Comments
 (0)