Skip to content

Commit

Permalink
опа
Browse files Browse the repository at this point in the history
  • Loading branch information
FunnyRain committed Feb 6, 2021
1 parent f04f6a5 commit bf4840f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

# Local History for Visual Studio Code
.history/

tests/main.php
15 changes: 15 additions & 0 deletions src/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class Account {

private $user;

public function __construct(User $user) {
$this->user = $user;
}

public function getId() {
return $this->user->VkApiRequest()->api('account.getProfileInfo', [])['id'];
}

}
34 changes: 26 additions & 8 deletions src/User.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
<?php

class User {

public function __construct() { }

// public function getAccount(): Account { }

// public function getMessages(): Messages { }

}

private $VkApiRequest;
private $Account;

public $token;
public $v;

public function __construct(string $token, $v = 5.126) {
$this->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 { }

}
26 changes: 11 additions & 15 deletions src/VkApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -51,4 +47,4 @@ private static function curl_post(string $url) {

return false;
}
}
}

0 comments on commit bf4840f

Please sign in to comment.