diff --git a/.gitignore b/.gitignore index bde5737..608b6dc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ # Local History for Visual Studio Code .history/ + +tests/main.php diff --git a/src/Account.php b/src/Account.php new file mode 100644 index 0000000..0507639 --- /dev/null +++ b/src/Account.php @@ -0,0 +1,15 @@ +user = $user; + } + + public function getId() { + return $this->user->VkApiRequest()->api('account.getProfileInfo', [])['id']; + } + +} \ No newline at end of file diff --git a/src/User.php b/src/User.php index 666f300..f76476b 100644 --- a/src/User.php +++ b/src/User.php @@ -1,11 +1,29 @@ token = $token; + $this->v = $v; + + $this->VkApiRequest = new VkApiRequest($this); + $this->Account = new Account($this); + } + + public function VkApiRequest(): VkApiRequest { + return $this->VkApiRequest; + } + + public function getAccount(): Account { + return $this->Account; + } + + // public function getMessages(): Messages { } + +} \ No newline at end of file diff --git a/src/VkApiRequest.php b/src/VkApiRequest.php index 70a41b1..5ff2d5a 100644 --- a/src/VkApiRequest.php +++ b/src/VkApiRequest.php @@ -2,14 +2,10 @@ class VkApiRequest { - public static $token; - public static $v; + private $user; - public function __construct(string $token, $v = 5.126) { - if (strlen($token) < 1) exit('Where is my token?'); - - self::$token = $token; - self::$v = $v; + public function __construct(User $user) { + $this->user = $user; } public function call(string $url) { @@ -19,19 +15,19 @@ public function call(string $url) { ); if (isset($sendRequest['error'])) { - echo ('\n*******\n' . var_dump($sendRequest['error']) . '\n*******'); + echo ("*******\n#{$sendRequest['error']['error_code']}, {$sendRequest['error']['error_msg']}\n*******\n"); } else return (isset($sendRequest['response'])) ? $sendRequest['response'] : $sendRequest; } public function api(string $method, array $params = []) { - return $this->call(self::http_build_query($method, [ - 'v' => self::$v, - 'access_token' => self::$token - ] + $params)); + return $this->call(self::http_build_query($method, http_build_query([ + 'v' => $this->user->v, + 'access_token' => $this->user->token + ] + $params))); } - private static function http_build_query($method, $params = '') { - return 'https://api.vk.com/method/{$method}?{$params}'; + private static function http_build_query(string $method, string $params) { + return "https://api.vk.com/method/{$method}?{$params}"; } private static function curl_post(string $url) { @@ -51,4 +47,4 @@ private static function curl_post(string $url) { return false; } -} +} \ No newline at end of file