1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FreedomCore\VK\API; |
4
|
|
|
|
5
|
|
|
use FreedomCore\VK\VKBase; |
6
|
|
|
use FreedomCore\VK\VKException; |
7
|
|
|
|
8
|
|
|
class VKAPI { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* VK Object |
12
|
|
|
* @var VKBase |
13
|
|
|
*/ |
14
|
|
|
protected $VKObject; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* API Method for this class |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $apiMethod = ''; |
21
|
|
|
|
22
|
|
|
const PERMISSION_NOTIFY = 1; |
23
|
|
|
const PERMISSION_FRIENDS = 2; |
24
|
|
|
const PERMISSION_PHOTOS = 4; |
25
|
|
|
const PERMISSION_AUDIO = 8; |
26
|
|
|
const PERMISSION_VIDEO = 16; |
27
|
|
|
const PERMISSION_DOCS = 131072; |
28
|
|
|
const PERMISSION_NOTES = 2048; |
29
|
|
|
const PERMISSION_PAGES = 128; |
30
|
|
|
const PERMISSION_LMLINK = 256; |
31
|
|
|
const PERMISSION_STATUS = 1024; |
32
|
|
|
const PERMISSION_OFFERS = 32; |
33
|
|
|
const PERMISSION_QUESTIONS = 64; |
34
|
|
|
const PERMISSION_WALL = 8192; |
35
|
|
|
const PERMISSION_GROUPS = 262144; |
36
|
|
|
const PERMISSION_MESSAGES = 4096; |
37
|
|
|
const PERMISSION_EMAIL = 4194304; |
38
|
|
|
const PERMISSION_NOTIFICATIONS = 524288; |
39
|
|
|
const PERMISSION_STATS = 1048576; |
40
|
|
|
const PERMISSION_ADDS = 32768; |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* VKUsers constructor. |
45
|
|
|
* @param VKBase $vkObject |
46
|
|
|
*/ |
47
|
|
|
public function __construct(VKBase $vkObject) { |
48
|
|
|
$this->VKObject = $vkObject; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Is User Authorized To Make an API Request |
53
|
|
|
* @param int $requiredPermission |
54
|
|
|
* @return boolean|null |
55
|
|
|
* @throws VKException |
56
|
|
|
*/ |
57
|
|
|
protected function isAllowed($requiredPermission = null) { |
58
|
|
|
if ($requiredPermission != null) { |
59
|
|
|
try { |
60
|
|
|
$isValidPermission = $this->VKObject->getPermissionsMask() & $requiredPermission; |
61
|
|
|
if (!$isValidPermission) { |
62
|
|
|
throw new VKException('Insufficient Permissions Received!', 1); |
63
|
|
|
} |
64
|
|
|
} catch (VKException $ex) { |
65
|
|
|
echo $ex->getMessage(); |
66
|
|
|
die(); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
try { |
71
|
|
|
if (!$this->VKObject->isAuthorized()) { |
72
|
|
|
throw new VKException('User not Authorized to make this API Request!', 1); |
73
|
|
|
} |
74
|
|
|
} catch (VKException $ex) { |
75
|
|
|
echo $ex->getMessage(); |
76
|
|
|
die(); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Execute API Call |
82
|
|
|
* @param string $apiMethod |
83
|
|
|
* @param $requestParameters |
84
|
|
|
* @return mixed |
85
|
|
|
*/ |
86
|
|
|
protected function executeQuery($apiMethod, $requestParameters) { |
87
|
|
|
return $this->VKObject->apiQuery($this->apiMethod.$apiMethod, $requestParameters); |
88
|
|
|
} |
89
|
|
|
} |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.