1
0
Fork 0
mirror of synced 2024-06-03 11:24:48 +12:00

Improve PHP exeution time by using

fully-qualified function calls
This commit is contained in:
Eldad Fux 2020-06-20 14:05:43 +03:00
parent c2f55786ea
commit a86ad1be90
47 changed files with 371 additions and 361 deletions

View file

@ -161,6 +161,16 @@ To run tests manually, run phpunit from your command line:
docker exec appwrite test docker exec appwrite test
``` ```
## Code Maintenance
We use some automation tools to help us keep a healthy code base.
Improve PHP exeution time by using [fully-qualified function calls](https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/):
```bash
php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes
```
## Tutorials ## Tutorials
From time to time, our team will add tutorials that will help contributors find their way in the Appwrite source code. Below is a list of currently available tutorials: From time to time, our team will add tutorials that will help contributors find their way in the Appwrite source code. Below is a list of currently available tutorials:

View file

@ -82,7 +82,7 @@ class Auth
*/ */
public static function encodeSession($id, $secret) public static function encodeSession($id, $secret)
{ {
return base64_encode(json_encode([ return \base64_encode(\json_encode([
'id' => $id, 'id' => $id,
'secret' => $secret, 'secret' => $secret,
])); ]));
@ -99,14 +99,14 @@ class Auth
*/ */
public static function decodeSession($session) public static function decodeSession($session)
{ {
$session = json_decode(base64_decode($session), true); $session = \json_decode(\base64_decode($session), true);
$default = ['id' => null, 'secret' => '']; $default = ['id' => null, 'secret' => ''];
if (!is_array($session)) { if (!\is_array($session)) {
return $default; return $default;
} }
return array_merge($default, $session); return \array_merge($default, $session);
} }
/** /**
@ -120,7 +120,7 @@ class Auth
*/ */
public static function hash($string) public static function hash($string)
{ {
return hash('sha256', $string); return \hash('sha256', $string);
} }
/** /**
@ -134,7 +134,7 @@ class Auth
*/ */
public static function passwordHash($string) public static function passwordHash($string)
{ {
return password_hash($string, PASSWORD_BCRYPT, array('cost' => 8)); return \password_hash($string, PASSWORD_BCRYPT, array('cost' => 8));
} }
/** /**
@ -147,7 +147,7 @@ class Auth
*/ */
public static function passwordVerify($plain, $hash) public static function passwordVerify($plain, $hash)
{ {
return password_verify($plain, $hash); return \password_verify($plain, $hash);
} }
/** /**
@ -163,7 +163,7 @@ class Auth
*/ */
public static function passwordGenerator(int $length = 20):string public static function passwordGenerator(int $length = 20):string
{ {
return bin2hex(random_bytes($length)); return \bin2hex(\random_bytes($length));
} }
/** /**
@ -179,7 +179,7 @@ class Auth
*/ */
public static function tokenGenerator(int $length = 128):string public static function tokenGenerator(int $length = 128):string
{ {
return bin2hex(random_bytes($length)); return \bin2hex(\random_bytes($length));
} }
/** /**
@ -199,7 +199,7 @@ class Auth
isset($token['expire']) && isset($token['expire']) &&
$token['type'] == $type && $token['type'] == $type &&
$token['secret'] === self::hash($secret) && $token['secret'] === self::hash($secret) &&
$token['expire'] >= time()) { $token['expire'] >= \time()) {
return $token->getId(); return $token->getId();
} }
} }

View file

@ -95,7 +95,7 @@ abstract class OAuth2
protected function addScope(string $scope):OAuth2 protected function addScope(string $scope):OAuth2
{ {
// Add a scope to the scopes array if it isn't already present // Add a scope to the scopes array if it isn't already present
if (!in_array($scope, $this->scopes)){ if (!\in_array($scope, $this->scopes)){
$this->scopes[] = $scope; $this->scopes[] = $scope;
} }
return $this; return $this;
@ -120,7 +120,7 @@ abstract class OAuth2
*/ */
public function parseState(string $state) public function parseState(string $state)
{ {
return json_decode($state, true); return \json_decode($state, true);
} }
/** /**
@ -133,24 +133,24 @@ abstract class OAuth2
*/ */
protected function request(string $method, string $url = '', array $headers = [], string $payload = ''):string protected function request(string $method, string $url = '', array $headers = [], string $payload = ''):string
{ {
$ch = curl_init($url); $ch = \curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HEADER, 0); \curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, ''); \curl_setopt($ch, CURLOPT_USERAGENT, '');
if (!empty($payload)) { if (!empty($payload)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); \curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
} }
$headers[] = 'Content-length: '.strlen($payload); $headers[] = 'Content-length: '.\strlen($payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); \curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Send the request & save response to $response // Send the request & save response to $response
$response = curl_exec($ch); $response = \curl_exec($ch);
curl_close($ch); \curl_close($ch);
return $response; return $response;
} }

View file

@ -38,7 +38,7 @@ class Amazon extends OAuth2
*/ */
public function parseState(string $state) public function parseState(string $state)
{ {
return json_decode(html_entity_decode($state), true); return \json_decode(\html_entity_decode($state), true);
} }
@ -47,11 +47,11 @@ class Amazon extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://www.amazon.com/ap/oa?'.http_build_query([ return 'https://www.amazon.com/ap/oa?'.\http_build_query([
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
'redirect_uri' => $this->callback 'redirect_uri' => $this->callback
]); ]);
} }
@ -68,7 +68,7 @@ class Amazon extends OAuth2
'POST', 'POST',
'https://api.amazon.com/auth/o2/token', 'https://api.amazon.com/auth/o2/token',
$headers, $headers,
http_build_query([ \http_build_query([
'code' => $code, 'code' => $code,
'client_id' => $this->appID , 'client_id' => $this->appID ,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
@ -76,7 +76,7 @@ class Amazon extends OAuth2
'grant_type' => 'authorization_code' 'grant_type' => 'authorization_code'
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -141,8 +141,8 @@ class Amazon extends OAuth2
protected function getUser(string $accessToken): array protected function getUser(string $accessToken): array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request('GET', 'https://api.amazon.com/user/profile?access_token='.urlencode($accessToken)); $user = $this->request('GET', 'https://api.amazon.com/user/profile?access_token='.\urlencode($accessToken));
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;
} }

View file

@ -41,13 +41,13 @@ class Apple extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://appleid.apple.com/auth/authorize?'.http_build_query([ return 'https://appleid.apple.com/auth/authorize?'.\http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
'response_type' => 'code', 'response_type' => 'code',
'response_mode' => 'form_post', 'response_mode' => 'form_post',
'scope' => implode(' ', $this->getScopes()) 'scope' => \implode(' ', $this->getScopes())
]); ]);
} }
@ -63,7 +63,7 @@ class Apple extends OAuth2
'POST', 'POST',
'https://appleid.apple.com/auth/token', 'https://appleid.apple.com/auth/token',
$headers, $headers,
http_build_query([ \http_build_query([
'grant_type' => 'authorization_code', 'grant_type' => 'authorization_code',
'code' => $code, 'code' => $code,
'client_id' => $this->appID, 'client_id' => $this->appID,
@ -72,10 +72,10 @@ class Apple extends OAuth2
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
$this->claims = (isset($accessToken['id_token'])) ? explode('.', $accessToken['id_token']) : [0 => '', 1 => '']; $this->claims = (isset($accessToken['id_token'])) ? \explode('.', $accessToken['id_token']) : [0 => '', 1 => ''];
$this->claims = (isset($this->claims[1])) ? json_decode(base64_decode($this->claims[1]), true) : []; $this->claims = (isset($this->claims[1])) ? \json_decode(\base64_decode($this->claims[1]), true) : [];
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -135,7 +135,7 @@ class Apple extends OAuth2
protected function getAppSecret():string protected function getAppSecret():string
{ {
try { try {
$secret = json_decode($this->appSecret, true); $secret = \json_decode($this->appSecret, true);
} catch (\Throwable $th) { } catch (\Throwable $th) {
throw new Exception('Invalid secret'); throw new Exception('Invalid secret');
} }
@ -152,19 +152,19 @@ class Apple extends OAuth2
$claims = [ $claims = [
'iss' => $teamID, 'iss' => $teamID,
'iat' => time(), 'iat' => \time(),
'exp' => time() + 86400*180, 'exp' => \time() + 86400*180,
'aud' => 'https://appleid.apple.com', 'aud' => 'https://appleid.apple.com',
'sub' => $bundleID, 'sub' => $bundleID,
]; ];
$pkey = openssl_pkey_get_private($keyfile); $pkey = \openssl_pkey_get_private($keyfile);
$payload = $this->encode(json_encode($headers)).'.'.$this->encode(json_encode($claims)); $payload = $this->encode(\json_encode($headers)).'.'.$this->encode(\json_encode($claims));
$signature = ''; $signature = '';
$success = openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256); $success = \openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256);
if (!$success) return ''; if (!$success) return '';
@ -176,7 +176,7 @@ class Apple extends OAuth2
*/ */
protected function encode($data) protected function encode($data)
{ {
return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($data)); return \str_replace(['+', '/', '='], ['-', '_', ''], \base64_encode($data));
} }
/** /**
@ -184,8 +184,8 @@ class Apple extends OAuth2
*/ */
protected function retrievePositiveInteger(string $data): string protected function retrievePositiveInteger(string $data): string
{ {
while ('00' === mb_substr($data, 0, 2, '8bit') && mb_substr($data, 2, 2, '8bit') > '7f') { while ('00' === \mb_substr($data, 0, 2, '8bit') && \mb_substr($data, 2, 2, '8bit') > '7f') {
$data = mb_substr($data, 2, null, '8bit'); $data = \mb_substr($data, 2, null, '8bit');
} }
return $data; return $data;

View file

@ -32,11 +32,11 @@ class Bitbucket extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://bitbucket.org/site/oauth2/authorize?'.http_build_query([ return 'https://bitbucket.org/site/oauth2/authorize?'.\http_build_query([
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
]); ]);
} }
@ -54,7 +54,7 @@ class Bitbucket extends OAuth2
'POST', 'POST',
'https://bitbucket.org/site/oauth2/access_token', 'https://bitbucket.org/site/oauth2/access_token',
$headers, $headers,
http_build_query([ \http_build_query([
'code' => $code, 'code' => $code,
'client_id' => $this->appID, 'client_id' => $this->appID,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
@ -62,7 +62,7 @@ class Bitbucket extends OAuth2
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -127,11 +127,11 @@ class Bitbucket extends OAuth2
protected function getUser(string $accessToken): array protected function getUser(string $accessToken): array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request('GET', 'https://api.bitbucket.org/2.0/user?access_token='.urlencode($accessToken)); $user = $this->request('GET', 'https://api.bitbucket.org/2.0/user?access_token='.\urlencode($accessToken));
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
$email = $this->request('GET', 'https://api.bitbucket.org/2.0/user/emails?access_token='.urlencode($accessToken)); $email = $this->request('GET', 'https://api.bitbucket.org/2.0/user/emails?access_token='.\urlencode($accessToken));
$this->user['email'] = json_decode($email, true)['values'][0]['email']; $this->user['email'] = \json_decode($email, true)['values'][0]['email'];
} }
return $this->user; return $this->user;
} }

View file

@ -44,10 +44,10 @@ class Bitly extends OAuth2
public function getLoginURL():string public function getLoginURL():string
{ {
return $this->endpoint . 'authorize?'. return $this->endpoint . 'authorize?'.
http_build_query([ \http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -62,19 +62,19 @@ class Bitly extends OAuth2
'POST', 'POST',
$this->resourceEndpoint . 'oauth/access_token', $this->resourceEndpoint . 'oauth/access_token',
["Content-Type: application/x-www-form-urlencoded"], ["Content-Type: application/x-www-form-urlencoded"],
http_build_query([ \http_build_query([
"client_id" => $this->appID, "client_id" => $this->appID,
"client_secret" => $this->appSecret, "client_secret" => $this->appSecret,
"code" => $code, "code" => $code,
"redirect_uri" => $this->callback, "redirect_uri" => $this->callback,
"state" => json_encode($this->state) "state" => \json_encode($this->state)
]) ])
); );
$result = null; $result = null;
if ($response) { if ($response) {
parse_str($response, $result); \parse_str($response, $result);
return $result['access_token']; return $result['access_token'];
} }
@ -137,12 +137,12 @@ class Bitly extends OAuth2
protected function getUser(string $accessToken) protected function getUser(string $accessToken)
{ {
$headers = [ $headers = [
'Authorization: Bearer '. urlencode($accessToken), 'Authorization: Bearer '. \urlencode($accessToken),
"Accept: application/json" "Accept: application/json"
]; ];
if (empty($this->user)) { if (empty($this->user)) {
$this->user = json_decode($this->request('GET', $this->resourceEndpoint . "v4/user", $headers), true); $this->user = \json_decode($this->request('GET', $this->resourceEndpoint . "v4/user", $headers), true);
} }

View file

@ -41,11 +41,11 @@ class Discord extends OAuth2
public function getLoginURL(): string public function getLoginURL(): string
{ {
$url = $this->endpoint . '/oauth2/authorize?'. $url = $this->endpoint . '/oauth2/authorize?'.
http_build_query([ \http_build_query([
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback 'redirect_uri' => $this->callback
]); ]);
@ -63,17 +63,17 @@ class Discord extends OAuth2
'POST', 'POST',
$this->endpoint . '/oauth2/token', $this->endpoint . '/oauth2/token',
['Content-Type: application/x-www-form-urlencoded'], ['Content-Type: application/x-www-form-urlencoded'],
http_build_query([ \http_build_query([
'grant_type' => 'authorization_code', 'grant_type' => 'authorization_code',
'code' => $code, 'code' => $code,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'client_id' => $this->appID, 'client_id' => $this->appID,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
'scope' => implode(' ', $this->scope) 'scope' => \implode(' ', $this->scope)
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -141,9 +141,9 @@ class Discord extends OAuth2
$user = $this->request( $user = $this->request(
'GET', 'GET',
$this->endpoint . '/users/@me', $this->endpoint . '/users/@me',
['Authorization: Bearer '.urlencode($accessToken)] ['Authorization: Bearer '.\urlencode($accessToken)]
); );
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;

View file

@ -33,10 +33,10 @@ class Dropbox extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://www.dropbox.com/oauth2/authorize?'.http_build_query([ return 'https://www.dropbox.com/oauth2/authorize?'.\http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
'response_type' => 'code' 'response_type' => 'code'
]); ]);
} }
@ -53,7 +53,7 @@ class Dropbox extends OAuth2
'POST', 'POST',
'https://api.dropboxapi.com/oauth2/token', 'https://api.dropboxapi.com/oauth2/token',
$headers, $headers,
http_build_query([ \http_build_query([
'code' => $code, 'code' => $code,
'client_id' => $this->appID, 'client_id' => $this->appID,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
@ -62,7 +62,7 @@ class Dropbox extends OAuth2
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -127,9 +127,9 @@ class Dropbox extends OAuth2
protected function getUser(string $accessToken): array protected function getUser(string $accessToken): array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$headers[] = 'Authorization: Bearer '. urlencode($accessToken); $headers[] = 'Authorization: Bearer '. \urlencode($accessToken);
$user = $this->request('POST', 'https://api.dropboxapi.com/2/users/get_current_account', $headers); $user = $this->request('POST', 'https://api.dropboxapi.com/2/users/get_current_account', $headers);
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;

View file

@ -36,11 +36,11 @@ class Facebook extends OAuth2
*/ */
public function getLoginURL():string public function getLoginURL():string
{ {
return 'https://www.facebook.com/'.$this->version.'/dialog/oauth?'.http_build_query([ return 'https://www.facebook.com/'.$this->version.'/dialog/oauth?'.\http_build_query([
'client_id'=> $this->appID, 'client_id'=> $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -53,7 +53,7 @@ class Facebook extends OAuth2
{ {
$accessToken = $this->request( $accessToken = $this->request(
'GET', 'GET',
'https://graph.facebook.com/'.$this->version.'/oauth/access_token?'.http_build_query([ 'https://graph.facebook.com/'.$this->version.'/oauth/access_token?'.\http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
@ -61,7 +61,7 @@ class Facebook extends OAuth2
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -126,9 +126,9 @@ class Facebook extends OAuth2
protected function getUser(string $accessToken):array protected function getUser(string $accessToken):array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request('GET', 'https://graph.facebook.com/'.$this->version.'/me?fields=email,name&access_token='.urlencode($accessToken)); $user = $this->request('GET', 'https://graph.facebook.com/'.$this->version.'/me?fields=email,name&access_token='.\urlencode($accessToken));
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;

View file

@ -31,11 +31,11 @@ class Github extends OAuth2
*/ */
public function getLoginURL():string public function getLoginURL():string
{ {
return 'https://github.com/login/oauth/authorize?'. http_build_query([ return 'https://github.com/login/oauth/authorize?'. \http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -51,7 +51,7 @@ class Github extends OAuth2
'POST', 'POST',
'https://github.com/login/oauth/access_token', 'https://github.com/login/oauth/access_token',
[], [],
http_build_query([ \http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
@ -61,7 +61,7 @@ class Github extends OAuth2
$output = []; $output = [];
parse_str($accessToken, $output); \parse_str($accessToken, $output);
if (isset($output['access_token'])) { if (isset($output['access_token'])) {
return $output['access_token']; return $output['access_token'];
@ -93,7 +93,7 @@ class Github extends OAuth2
*/ */
public function getUserEmail(string $accessToken):string public function getUserEmail(string $accessToken):string
{ {
$emails = json_decode($this->request('GET', 'https://api.github.com/user/emails', ['Authorization: token '.urlencode($accessToken)]), true); $emails = \json_decode($this->request('GET', 'https://api.github.com/user/emails', ['Authorization: token '.\urlencode($accessToken)]), true);
foreach ($emails as $email) { foreach ($emails as $email) {
if ($email['primary'] && $email['verified']) { if ($email['primary'] && $email['verified']) {
@ -128,7 +128,7 @@ class Github extends OAuth2
protected function getUser(string $accessToken) protected function getUser(string $accessToken)
{ {
if (empty($this->user)) { if (empty($this->user)) {
$this->user = json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.urlencode($accessToken)]), true); $this->user = \json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.\urlencode($accessToken)]), true);
} }
return $this->user; return $this->user;

View file

@ -34,11 +34,11 @@ class Gitlab extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://gitlab.com/oauth/authorize?'.http_build_query([ return 'https://gitlab.com/oauth/authorize?'.\http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
'response_type' => 'code' 'response_type' => 'code'
]); ]);
} }
@ -52,7 +52,7 @@ class Gitlab extends OAuth2
{ {
$accessToken = $this->request( $accessToken = $this->request(
'POST', 'POST',
'https://gitlab.com/oauth/token?'.http_build_query([ 'https://gitlab.com/oauth/token?'.\http_build_query([
'code' => $code, 'code' => $code,
'client_id' => $this->appID, 'client_id' => $this->appID,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
@ -61,7 +61,7 @@ class Gitlab extends OAuth2
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -126,8 +126,8 @@ class Gitlab extends OAuth2
protected function getUser(string $accessToken): array protected function getUser(string $accessToken): array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request('GET', 'https://gitlab.com/api/v4/user?access_token='.urlencode($accessToken)); $user = $this->request('GET', 'https://gitlab.com/api/v4/user?access_token='.\urlencode($accessToken));
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;

View file

@ -43,11 +43,11 @@ class Google extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://accounts.google.com/o/oauth2/v2/auth?'. http_build_query([ return 'https://accounts.google.com/o/oauth2/v2/auth?'. \http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
'response_type' => 'code' 'response_type' => 'code'
]); ]);
} }
@ -61,7 +61,7 @@ class Google extends OAuth2
{ {
$accessToken = $this->request( $accessToken = $this->request(
'POST', 'POST',
'https://oauth2.googleapis.com/token?'.http_build_query([ 'https://oauth2.googleapis.com/token?'.\http_build_query([
'code' => $code, 'code' => $code,
'client_id' => $this->appID, 'client_id' => $this->appID,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
@ -71,7 +71,7 @@ class Google extends OAuth2
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -136,8 +136,8 @@ class Google extends OAuth2
protected function getUser(string $accessToken): array protected function getUser(string $accessToken): array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?access_token='.urlencode($accessToken)); $user = $this->request('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?access_token='.\urlencode($accessToken));
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;

View file

@ -45,12 +45,12 @@ class LinkedIn extends OAuth2
*/ */
public function getLoginURL():string public function getLoginURL():string
{ {
return 'https://www.linkedin.com/oauth/v2/authorization?'.http_build_query([ return 'https://www.linkedin.com/oauth/v2/authorization?'.\http_build_query([
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
]); ]);
} }
@ -65,7 +65,7 @@ class LinkedIn extends OAuth2
'POST', 'POST',
'https://www.linkedin.com/oauth/v2/accessToken', 'https://www.linkedin.com/oauth/v2/accessToken',
['Content-Type: application/x-www-form-urlencoded'], ['Content-Type: application/x-www-form-urlencoded'],
http_build_query([ \http_build_query([
'grant_type' => 'authorization_code', 'grant_type' => 'authorization_code',
'code' => $code, 'code' => $code,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
@ -74,7 +74,7 @@ class LinkedIn extends OAuth2
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -106,7 +106,7 @@ class LinkedIn extends OAuth2
*/ */
public function getUserEmail(string $accessToken):string public function getUserEmail(string $accessToken):string
{ {
$email = json_decode($this->request('GET', 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', ['Authorization: Bearer '.urlencode($accessToken)]), true); $email = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', ['Authorization: Bearer '.\urlencode($accessToken)]), true);
if ( if (
isset($email['elements']) && isset($email['elements']) &&
@ -149,7 +149,7 @@ class LinkedIn extends OAuth2
protected function getUser(string $accessToken) protected function getUser(string $accessToken)
{ {
if (empty($this->user)) { if (empty($this->user)) {
$this->user = json_decode($this->request('GET', 'https://api.linkedin.com/v2/me', ['Authorization: Bearer '.urlencode($accessToken)]), true); $this->user = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/me', ['Authorization: Bearer '.\urlencode($accessToken)]), true);
} }
return $this->user; return $this->user;

View file

@ -36,11 +36,11 @@ class Microsoft extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'.http_build_query([ return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'.\http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'state'=> json_encode($this->state), 'state'=> \json_encode($this->state),
'scope'=> implode(' ', $this->getScopes()), 'scope'=> \implode(' ', $this->getScopes()),
'response_type' => 'code', 'response_type' => 'code',
'response_mode' => 'query' 'response_mode' => 'query'
]); ]);
@ -59,17 +59,17 @@ class Microsoft extends OAuth2
'POST', 'POST',
'https://login.microsoftonline.com/common/oauth2/v2.0/token', 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
$headers, $headers,
http_build_query([ \http_build_query([
'code' => $code, 'code' => $code,
'client_id' => $this->appID, 'client_id' => $this->appID,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'grant_type' => 'authorization_code' 'grant_type' => 'authorization_code'
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -134,9 +134,9 @@ class Microsoft extends OAuth2
protected function getUser(string $accessToken): array protected function getUser(string $accessToken): array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$headers[] = 'Authorization: Bearer '. urlencode($accessToken); $headers[] = 'Authorization: Bearer '. \urlencode($accessToken);
$user = $this->request('GET', 'https://graph.microsoft.com/v1.0/me', $headers); $user = $this->request('GET', 'https://graph.microsoft.com/v1.0/me', $headers);
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;

View file

@ -36,11 +36,11 @@ class Mock extends OAuth2
*/ */
public function getLoginURL():string public function getLoginURL():string
{ {
return 'http://localhost/'.$this->version.'/mock/tests/general/oauth2?'. http_build_query([ return 'http://localhost/'.$this->version.'/mock/tests/general/oauth2?'. \http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -54,7 +54,7 @@ class Mock extends OAuth2
$accessToken = $this->request( $accessToken = $this->request(
'GET', 'GET',
'http://localhost/'.$this->version.'/mock/tests/general/oauth2/token?'. 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/token?'.
http_build_query([ \http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
@ -62,7 +62,7 @@ class Mock extends OAuth2
]) ])
); );
$accessToken = json_decode($accessToken, true); // $accessToken = \json_decode($accessToken, true); //
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -127,9 +127,9 @@ class Mock extends OAuth2
protected function getUser(string $accessToken):array protected function getUser(string $accessToken):array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request('GET', 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/user?token='.urlencode($accessToken)); $user = $this->request('GET', 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/user?token='.\urlencode($accessToken));
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;

View file

@ -50,14 +50,14 @@ class Paypal extends OAuth2
public function getLoginURL(): string public function getLoginURL(): string
{ {
$url = $this->endpoint[$this->environment] . 'connect/?'. $url = $this->endpoint[$this->environment] . 'connect/?'.
http_build_query([ \http_build_query([
'flowEntry' => 'static', 'flowEntry' => 'static',
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
// paypal is not accepting localhost string into return uri // paypal is not accepting localhost string into return uri
'redirect_uri' => str_replace("localhost", "127.0.0.1", $this->callback), 'redirect_uri' => \str_replace("localhost", "127.0.0.1", $this->callback),
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
]); ]);
return $url; return $url;
@ -73,15 +73,15 @@ class Paypal extends OAuth2
$accessToken = $this->request( $accessToken = $this->request(
'POST', 'POST',
$this->resourceEndpoint[$this->environment] . 'oauth2/token', $this->resourceEndpoint[$this->environment] . 'oauth2/token',
['Authorization: Basic ' . base64_encode($this->appID . ':' . $this->appSecret)], ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)],
http_build_query([ \http_build_query([
'code' => $code, 'code' => $code,
'grant_type' => 'authorization_code', 'grant_type' => 'authorization_code',
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
@ -148,7 +148,7 @@ class Paypal extends OAuth2
{ {
$header = [ $header = [
'Content-Type: application/json', 'Content-Type: application/json',
'Authorization: Bearer '.urlencode($accessToken), 'Authorization: Bearer '.\urlencode($accessToken),
]; ];
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request( $user = $this->request(
@ -156,7 +156,7 @@ class Paypal extends OAuth2
$this->resourceEndpoint[$this->environment] . 'identity/oauth2/userinfo?schema=paypalv1.1', $this->resourceEndpoint[$this->environment] . 'identity/oauth2/userinfo?schema=paypalv1.1',
$header $header
); );
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;

View file

@ -38,7 +38,7 @@ class Salesforce extends OAuth2
*/ */
public function parseState(string $state) public function parseState(string $state)
{ {
return json_decode(html_entity_decode($state), true); return \json_decode(\html_entity_decode($state), true);
} }
@ -47,12 +47,12 @@ class Salesforce extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://login.salesforce.com/services/oauth2/authorize?'.http_build_query([ return 'https://login.salesforce.com/services/oauth2/authorize?'.\http_build_query([
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri'=> $this->callback, 'redirect_uri'=> $this->callback,
'scope'=> implode(' ', $this->getScopes()), 'scope'=> \implode(' ', $this->getScopes()),
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -64,7 +64,7 @@ class Salesforce extends OAuth2
public function getAccessToken(string $code): string public function getAccessToken(string $code): string
{ {
$headers = [ $headers = [
"Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret), "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
"Content-Type: application/x-www-form-urlencoded", "Content-Type: application/x-www-form-urlencoded",
]; ];
@ -72,13 +72,13 @@ class Salesforce extends OAuth2
'POST', 'POST',
'https://login.salesforce.com/services/oauth2/token', 'https://login.salesforce.com/services/oauth2/token',
$headers, $headers,
http_build_query([ \http_build_query([
'code' => $code, 'code' => $code,
'redirect_uri' => $this->callback , 'redirect_uri' => $this->callback ,
'grant_type' => 'authorization_code' 'grant_type' => 'authorization_code'
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -143,8 +143,8 @@ class Salesforce extends OAuth2
protected function getUser(string $accessToken): array protected function getUser(string $accessToken): array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request('GET', 'https://login.salesforce.com/services/oauth2/userinfo?access_token='.urlencode($accessToken)); $user = $this->request('GET', 'https://login.salesforce.com/services/oauth2/userinfo?access_token='.\urlencode($accessToken));
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;
} }

View file

@ -35,11 +35,11 @@ class Slack extends OAuth2
public function getLoginURL():string public function getLoginURL():string
{ {
// https://api.slack.com/docs/oauth#step_1_-_sending_users_to_authorize_and_or_install // https://api.slack.com/docs/oauth#step_1_-_sending_users_to_authorize_and_or_install
return 'https://slack.com/oauth/authorize?'.http_build_query([ return 'https://slack.com/oauth/authorize?'.\http_build_query([
'client_id'=> $this->appID, 'client_id'=> $this->appID,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -53,7 +53,7 @@ class Slack extends OAuth2
// https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token // https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token
$accessToken = $this->request( $accessToken = $this->request(
'GET', 'GET',
'https://slack.com/api/oauth.access?'.http_build_query([ 'https://slack.com/api/oauth.access?'.\http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
'code' => $code, 'code' => $code,
@ -61,7 +61,7 @@ class Slack extends OAuth2
]) ])
); );
$accessToken = json_decode($accessToken, true); // $accessToken = \json_decode($accessToken, true); //
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -130,10 +130,10 @@ class Slack extends OAuth2
// https://api.slack.com/methods/users.identity // https://api.slack.com/methods/users.identity
$user = $this->request( $user = $this->request(
'GET', 'GET',
'https://slack.com/api/users.identity?token='.urlencode($accessToken) 'https://slack.com/api/users.identity?token='.\urlencode($accessToken)
); );
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;

View file

@ -46,12 +46,12 @@ class Spotify extends OAuth2
public function getLoginURL():string public function getLoginURL():string
{ {
return $this->endpoint . 'authorize?'. return $this->endpoint . 'authorize?'.
http_build_query([ \http_build_query([
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -62,12 +62,12 @@ class Spotify extends OAuth2
*/ */
public function getAccessToken(string $code):string public function getAccessToken(string $code):string
{ {
$header = "Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret); $header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret);
$result = json_decode($this->request( $result = \json_decode($this->request(
'POST', 'POST',
$this->endpoint . 'api/token', $this->endpoint . 'api/token',
[$header], [$header],
http_build_query([ \http_build_query([
"code" => $code, "code" => $code,
"grant_type" => "authorization_code", "grant_type" => "authorization_code",
"redirect_uri" => $this->callback "redirect_uri" => $this->callback
@ -137,8 +137,8 @@ class Spotify extends OAuth2
protected function getUser(string $accessToken) protected function getUser(string $accessToken)
{ {
if (empty($this->user)) { if (empty($this->user)) {
$this->user = json_decode($this->request('GET', $this->user = \json_decode($this->request('GET',
$this->resourceEndpoint . "me", ['Authorization: Bearer '.urlencode($accessToken)]), true); $this->resourceEndpoint . "me", ['Authorization: Bearer '.\urlencode($accessToken)]), true);
} }
return $this->user; return $this->user;

View file

@ -46,13 +46,13 @@ class Twitch extends OAuth2
public function getLoginURL():string public function getLoginURL():string
{ {
return $this->endpoint . 'authorize?'. return $this->endpoint . 'authorize?'.
http_build_query([ \http_build_query([
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'force_verify' => true, 'force_verify' => true,
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -63,11 +63,11 @@ class Twitch extends OAuth2
*/ */
public function getAccessToken(string $code):string public function getAccessToken(string $code):string
{ {
$result = json_decode($this->request( $result = \json_decode($this->request(
'POST', 'POST',
$this->endpoint . 'token', $this->endpoint . 'token',
[], [],
http_build_query([ \http_build_query([
"client_id" => $this->appID, "client_id" => $this->appID,
"client_secret" => $this->appSecret, "client_secret" => $this->appSecret,
"code" => $code, "code" => $code,
@ -139,8 +139,8 @@ class Twitch extends OAuth2
protected function getUser(string $accessToken) protected function getUser(string $accessToken)
{ {
if (empty($this->user)) { if (empty($this->user)) {
$this->user = json_decode($this->request('GET', $this->user = \json_decode($this->request('GET',
$this->resourceEndpoint, ['Authorization: Bearer '.urlencode($accessToken)]), true)['data']['0']; $this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true)['data']['0'];
} }
return $this->user; return $this->user;

View file

@ -44,13 +44,13 @@ class Vk extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://oauth.vk.com/authorize?' . http_build_query([ return 'https://oauth.vk.com/authorize?' . \http_build_query([
'client_id' => $this->appID, 'client_id' => $this->appID,
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'response_type' => 'code', 'response_type' => 'code',
'state' => json_encode($this->state), 'state' => \json_encode($this->state),
'v' => $this->version, 'v' => $this->version,
'scope' => implode(' ', $this->getScopes()) 'scope' => \implode(' ', $this->getScopes())
]); ]);
} }
@ -66,14 +66,14 @@ class Vk extends OAuth2
'POST', 'POST',
'https://oauth.vk.com/access_token?', 'https://oauth.vk.com/access_token?',
$headers, $headers,
http_build_query([ \http_build_query([
'code' => $code, 'code' => $code,
'client_id' => $this->appID, 'client_id' => $this->appID,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
'redirect_uri' => $this->callback 'redirect_uri' => $this->callback
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['email'])) { if (isset($accessToken['email'])) {
$this->user['email'] = $accessToken['email']; $this->user['email'] = $accessToken['email'];
@ -147,14 +147,14 @@ class Vk extends OAuth2
if (empty($this->user['name'])) { if (empty($this->user['name'])) {
$user = $this->request( $user = $this->request(
'GET', 'GET',
'https://api.vk.com/method/users.get?'. http_build_query([ 'https://api.vk.com/method/users.get?'. \http_build_query([
'v' => $this->version, 'v' => $this->version,
'fields' => 'id,name,email,first_name,last_name', 'fields' => 'id,name,email,first_name,last_name',
'access_token' => $accessToken 'access_token' => $accessToken
]) ])
); );
$user = json_decode($user, true); $user = \json_decode($user, true);
$this->user['name'] = $user['response'][0]['first_name'] ." ".$user['response'][0]['last_name']; $this->user['name'] = $user['response'][0]['first_name'] ." ".$user['response'][0]['last_name'];
} }
return $this->user; return $this->user;

View file

@ -49,7 +49,7 @@ class Yahoo extends OAuth2
*/ */
public function parseState(string $state) public function parseState(string $state)
{ {
return json_decode(html_entity_decode($state), true); return \json_decode(\html_entity_decode($state), true);
} }
/** /**
@ -58,12 +58,12 @@ class Yahoo extends OAuth2
public function getLoginURL():string public function getLoginURL():string
{ {
return $this->endpoint . 'request_auth?'. return $this->endpoint . 'request_auth?'.
http_build_query([ \http_build_query([
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'scope' => implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -75,15 +75,15 @@ class Yahoo extends OAuth2
public function getAccessToken(string $code):string public function getAccessToken(string $code):string
{ {
$header = [ $header = [
"Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret), "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
"Content-Type: application/x-www-form-urlencoded", "Content-Type: application/x-www-form-urlencoded",
]; ];
$result = json_decode($this->request( $result = \json_decode($this->request(
'POST', 'POST',
$this->endpoint . 'get_token', $this->endpoint . 'get_token',
$header, $header,
http_build_query([ \http_build_query([
"code" => $code, "code" => $code,
"grant_type" => "authorization_code", "grant_type" => "authorization_code",
"redirect_uri" => $this->callback "redirect_uri" => $this->callback
@ -153,8 +153,8 @@ class Yahoo extends OAuth2
protected function getUser(string $accessToken) protected function getUser(string $accessToken)
{ {
if (empty($this->user)) { if (empty($this->user)) {
$this->user = json_decode($this->request('GET', $this->user = \json_decode($this->request('GET',
$this->resourceEndpoint, ['Authorization: Bearer '.urlencode($accessToken)]), true); $this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true);
} }
return $this->user; return $this->user;

View file

@ -36,7 +36,7 @@ class Yandex extends OAuth2
*/ */
public function parseState(string $state) public function parseState(string $state)
{ {
return json_decode(html_entity_decode($state), true); return \json_decode(\html_entity_decode($state), true);
} }
@ -45,11 +45,11 @@ class Yandex extends OAuth2
*/ */
public function getLoginURL(): string public function getLoginURL(): string
{ {
return 'https://oauth.yandex.com/authorize?'.http_build_query([ return 'https://oauth.yandex.com/authorize?'.\http_build_query([
'response_type' => 'code', 'response_type' => 'code',
'client_id' => $this->appID, 'client_id' => $this->appID,
'scope'=> implode(' ', $this->getScopes()), 'scope'=> \implode(' ', $this->getScopes()),
'state' => json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
@ -61,7 +61,7 @@ class Yandex extends OAuth2
public function getAccessToken(string $code): string public function getAccessToken(string $code): string
{ {
$headers = [ $headers = [
"Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret), "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
"Content-Type: application/x-www-form-urlencoded", "Content-Type: application/x-www-form-urlencoded",
]; ];
@ -69,12 +69,12 @@ class Yandex extends OAuth2
'POST', 'POST',
'https://oauth.yandex.com/token', 'https://oauth.yandex.com/token',
$headers, $headers,
http_build_query([ \http_build_query([
'code' => $code, 'code' => $code,
'grant_type' => 'authorization_code' 'grant_type' => 'authorization_code'
]) ])
); );
$accessToken = json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) { if (isset($accessToken['access_token'])) {
return $accessToken['access_token']; return $accessToken['access_token'];
@ -139,11 +139,11 @@ class Yandex extends OAuth2
protected function getUser(string $accessToken): array protected function getUser(string $accessToken): array
{ {
if (empty($this->user)) { if (empty($this->user)) {
$user = $this->request('GET', 'https://login.yandex.ru/info?'.http_build_query([ $user = $this->request('GET', 'https://login.yandex.ru/info?'.\http_build_query([
'format' => 'json', 'format' => 'json',
'oauth_token' => $accessToken 'oauth_token' => $accessToken
])); ]));
$this->user = json_decode($user, true); $this->user = \json_decode($user, true);
} }
return $this->user; return $this->user;
} }

View file

@ -34,7 +34,7 @@ class Password extends Validator
*/ */
public function isValid($value) public function isValid($value)
{ {
if (strlen($value) < 6 || strlen($value) > 32) { if (\strlen($value) < 6 || \strlen($value) > 32) {
return false; return false;
} }

View file

@ -113,11 +113,11 @@ class MySQL extends Adapter
$output = [ $output = [
'$id' => null, '$id' => null,
'$collection' => null, '$collection' => null,
'$permissions' => (!empty($document['permissions'])) ? json_decode($document['permissions'], true) : [], '$permissions' => (!empty($document['permissions'])) ? \json_decode($document['permissions'], true) : [],
]; ];
foreach ($properties as &$property) { foreach ($properties as &$property) {
settype($property['value'], $property['primitive']); \settype($property['value'], $property['primitive']);
if ($property['array']) { if ($property['array']) {
$output[$property['key']][] = $property['value']; $output[$property['key']][] = $property['value'];
@ -154,9 +154,9 @@ class MySQL extends Adapter
public function createDocument(array $data = [], array $unique = []) public function createDocument(array $data = [], array $unique = [])
{ {
$order = 0; $order = 0;
$data = array_merge(['$id' => null, '$permissions' => []], $data); // Merge data with default params $data = \array_merge(['$id' => null, '$permissions' => []], $data); // Merge data with default params
$signature = md5(json_encode($data, true)); $signature = \md5(\json_encode($data, true));
$revision = uniqid('', true); $revision = \uniqid('', true);
$data['$id'] = (empty($data['$id'])) ? null : $data['$id']; $data['$id'] = (empty($data['$id'])) ? null : $data['$id'];
/* /*
@ -192,7 +192,7 @@ class MySQL extends Adapter
SET `key` = :key; SET `key` = :key;
'); ');
$st->bindValue(':key', md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR); $st->bindValue(':key', \md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR);
if(!$st->execute()) { if(!$st->execute()) {
throw new Duplicate('Duplicated Property: '.$key.'='.$value); throw new Duplicate('Duplicated Property: '.$key.'='.$value);
@ -213,9 +213,9 @@ class MySQL extends Adapter
$st1->bindValue(':uid', $data['$id'], PDO::PARAM_STR); $st1->bindValue(':uid', $data['$id'], PDO::PARAM_STR);
$st1->bindValue(':revision', $revision, PDO::PARAM_STR); $st1->bindValue(':revision', $revision, PDO::PARAM_STR);
$st1->bindValue(':signature', $signature, PDO::PARAM_STR); $st1->bindValue(':signature', $signature, PDO::PARAM_STR);
$st1->bindValue(':createdAt', date('Y-m-d H:i:s', time()), PDO::PARAM_STR); $st1->bindValue(':createdAt', \date('Y-m-d H:i:s', \time()), PDO::PARAM_STR);
$st1->bindValue(':updatedAt', date('Y-m-d H:i:s', time()), PDO::PARAM_STR); $st1->bindValue(':updatedAt', \date('Y-m-d H:i:s', \time()), PDO::PARAM_STR);
$st1->bindValue(':permissions', json_encode($data['$permissions']), PDO::PARAM_STR); $st1->bindValue(':permissions', \json_encode($data['$permissions']), PDO::PARAM_STR);
$st1->execute(); $st1->execute();
@ -240,7 +240,7 @@ class MySQL extends Adapter
foreach ($data as $key => $value) { // Prepare properties data foreach ($data as $key => $value) { // Prepare properties data
if (in_array($key, ['$permissions'])) { if (\in_array($key, ['$permissions'])) {
continue; continue;
} }
@ -292,8 +292,8 @@ class MySQL extends Adapter
} }
foreach ($props as $prop) { foreach ($props as $prop) {
if (is_array($prop['value'])) { if (\is_array($prop['value'])) {
throw new Exception('Value can\'t be an array: '.json_encode($prop['value'])); throw new Exception('Value can\'t be an array: '.\json_encode($prop['value']));
} }
$st2->bindValue(':documentUid', $data['$id'], PDO::PARAM_STR); $st2->bindValue(':documentUid', $data['$id'], PDO::PARAM_STR);
$st2->bindValue(':documentRevision', $revision, PDO::PARAM_STR); $st2->bindValue(':documentRevision', $revision, PDO::PARAM_STR);
@ -481,7 +481,7 @@ class MySQL extends Adapter
*/ */
public function getCollection(array $options) public function getCollection(array $options)
{ {
$start = microtime(true); $start = \microtime(true);
$orderCastMap = [ $orderCastMap = [
'int' => 'UNSIGNED', 'int' => 'UNSIGNED',
'string' => 'CHAR', 'string' => 'CHAR',
@ -494,11 +494,11 @@ class MySQL extends Adapter
$options['orderField'] = (empty($options['orderField'])) ? '$id' : $options['orderField']; // Set default order field $options['orderField'] = (empty($options['orderField'])) ? '$id' : $options['orderField']; // Set default order field
$options['orderCast'] = (empty($options['orderCast'])) ? 'string' : $options['orderCast']; // Set default order field $options['orderCast'] = (empty($options['orderCast'])) ? 'string' : $options['orderCast']; // Set default order field
if (!array_key_exists($options['orderCast'], $orderCastMap)) { if (!\array_key_exists($options['orderCast'], $orderCastMap)) {
throw new Exception('Invalid order cast'); throw new Exception('Invalid order cast');
} }
if (!in_array($options['orderType'], $orderTypeMap)) { if (!\in_array($options['orderType'], $orderTypeMap)) {
throw new Exception('Invalid order type'); throw new Exception('Invalid order type');
} }
@ -514,11 +514,11 @@ class MySQL extends Adapter
$value = $filter['value']; $value = $filter['value'];
$operator = $filter['operator']; $operator = $filter['operator'];
$path = explode('.', $key); $path = \explode('.', $key);
$original = $path; $original = $path;
if (1 < count($path)) { if (1 < \count($path)) {
$key = array_pop($path); $key = \array_pop($path);
} else { } else {
$path = []; $path = [];
} }
@ -535,7 +535,7 @@ class MySQL extends Adapter
//if($path == "''") { // Handle direct attributes queries //if($path == "''") { // Handle direct attributes queries
$where[] = 'JOIN `'.$this->getNamespace().".database.properties` b{$i} ON a.uid IS NOT NULL AND b{$i}.documentUid = a.uid AND (b{$i}.key = {$key} AND b{$i}.value {$operator} {$value})"; $where[] = 'JOIN `'.$this->getNamespace().".database.properties` b{$i} ON a.uid IS NOT NULL AND b{$i}.documentUid = a.uid AND (b{$i}.key = {$key} AND b{$i}.value {$operator} {$value})";
} else { // Handle direct child attributes queries } else { // Handle direct child attributes queries
$len = count($original); $len = \count($original);
$prev = 'c'.$i; $prev = 'c'.$i;
foreach ($original as $y => $part) { foreach ($original as $y => $part) {
@ -557,10 +557,10 @@ class MySQL extends Adapter
} }
// Sorting // Sorting
$orderPath = explode('.', $options['orderField']); $orderPath = \explode('.', $options['orderField']);
$len = count($orderPath); $len = \count($orderPath);
$orderKey = 'order_b'; $orderKey = 'order_b';
$part = $this->getPDO()->quote(implode('', $orderPath), PDO::PARAM_STR); $part = $this->getPDO()->quote(\implode('', $orderPath), PDO::PARAM_STR);
$orderSelect = "CASE WHEN {$orderKey}.key = {$part} THEN CAST({$orderKey}.value AS {$orderCastMap[$options['orderCast']]}) END AS sort_ff"; $orderSelect = "CASE WHEN {$orderKey}.key = {$part} THEN CAST({$orderKey}.value AS {$orderCastMap[$options['orderCast']]}) END AS sort_ff";
if (1 === $len) { if (1 === $len) {
@ -606,9 +606,9 @@ class MySQL extends Adapter
} }
$select = 'DISTINCT a.uid'; $select = 'DISTINCT a.uid';
$where = implode("\n", $where); $where = \implode("\n", $where);
$join = implode("\n", $join); $join = \implode("\n", $join);
$sorts = implode("\n", $sorts); $sorts = \implode("\n", $sorts);
$range = "LIMIT {$options['offset']}, {$options['limit']}"; $range = "LIMIT {$options['offset']}, {$options['limit']}";
$roles = []; $roles = [];
@ -624,10 +624,10 @@ class MySQL extends Adapter
FROM `".$this->getNamespace().".database.documents` a {$where}{$join}{$sorts} FROM `".$this->getNamespace().".database.documents` a {$where}{$join}{$sorts}
WHERE status = 0 WHERE status = 0
{$search} {$search}
AND (".implode('||', $roles).") AND (".\implode('||', $roles).")
ORDER BY sort_ff {$options['orderType']} %s"; ORDER BY sort_ff {$options['orderType']} %s";
$st = $this->getPDO()->prepare(sprintf($query, $select, $range)); $st = $this->getPDO()->prepare(\sprintf($query, $select, $range));
$st->execute(); $st->execute();
@ -638,7 +638,7 @@ class MySQL extends Adapter
$results['data'][] = $node['uid']; $results['data'][] = $node['uid'];
} }
$count = $this->getPDO()->prepare(sprintf($query, 'count(DISTINCT a.uid) as sum', '')); $count = $this->getPDO()->prepare(\sprintf($query, 'count(DISTINCT a.uid) as sum', ''));
$count->execute(); $count->execute();
@ -647,11 +647,11 @@ class MySQL extends Adapter
$this->resetDebug(); $this->resetDebug();
$this $this
->setDebug('query', preg_replace('/\s+/', ' ', sprintf($query, $select, $range))) ->setDebug('query', \preg_replace('/\s+/', ' ', \sprintf($query, $select, $range)))
->setDebug('time', microtime(true) - $start) ->setDebug('time', \microtime(true) - $start)
->setDebug('filters', count($options['filters'])) ->setDebug('filters', \count($options['filters']))
->setDebug('joins', substr_count($query, 'JOIN')) ->setDebug('joins', \substr_count($query, 'JOIN'))
->setDebug('count', count($results['data'])) ->setDebug('count', \count($results['data']))
->setDebug('sum', (int) $count['sum']) ->setDebug('sum', (int) $count['sum'])
->setDebug('documents', $this->count) ->setDebug('documents', $this->count)
; ;
@ -670,7 +670,7 @@ class MySQL extends Adapter
*/ */
public function getCount(array $options) public function getCount(array $options)
{ {
$start = microtime(true); $start = \microtime(true);
$where = []; $where = [];
$join = []; $join = [];
@ -680,11 +680,11 @@ class MySQL extends Adapter
$key = $filter['key']; $key = $filter['key'];
$value = $filter['value']; $value = $filter['value'];
$operator = $filter['operator']; $operator = $filter['operator'];
$path = explode('.', $key); $path = \explode('.', $key);
$original = $path; $original = $path;
if (1 < count($path)) { if (1 < \count($path)) {
$key = array_pop($path); $key = \array_pop($path);
} else { } else {
$path = []; $path = [];
} }
@ -696,7 +696,7 @@ class MySQL extends Adapter
//if($path == "''") { // Handle direct attributes queries //if($path == "''") { // Handle direct attributes queries
$where[] = 'JOIN `'.$this->getNamespace().".database.properties` b{$i} ON a.uid IS NOT NULL AND b{$i}.documentUid = a.uid AND (b{$i}.key = {$key} AND b{$i}.value {$operator} {$value})"; $where[] = 'JOIN `'.$this->getNamespace().".database.properties` b{$i} ON a.uid IS NOT NULL AND b{$i}.documentUid = a.uid AND (b{$i}.key = {$key} AND b{$i}.value {$operator} {$value})";
} else { // Handle direct child attributes queries } else { // Handle direct child attributes queries
$len = count($original); $len = \count($original);
$prev = 'c'.$i; $prev = 'c'.$i;
foreach ($original as $y => $part) { foreach ($original as $y => $part) {
@ -714,8 +714,8 @@ class MySQL extends Adapter
} }
} }
$where = implode("\n", $where); $where = \implode("\n", $where);
$join = implode("\n", $join); $join = \implode("\n", $join);
$func = 'JOIN `'.$this->getNamespace().".database.properties` b_func ON a.uid IS NOT NULL $func = 'JOIN `'.$this->getNamespace().".database.properties` b_func ON a.uid IS NOT NULL
AND a.uid = b_func.documentUid AND a.uid = b_func.documentUid
AND (b_func.key = 'sizeOriginal')"; AND (b_func.key = 'sizeOriginal')";
@ -732,9 +732,9 @@ class MySQL extends Adapter
$query = 'SELECT SUM(b_func.value) as result $query = 'SELECT SUM(b_func.value) as result
FROM `'.$this->getNamespace().".database.documents` a {$where}{$join}{$func} FROM `'.$this->getNamespace().".database.documents` a {$where}{$join}{$func}
WHERE status = 0 WHERE status = 0
AND (".implode('||', $roles).')'; AND (".\implode('||', $roles).')';
$st = $this->getPDO()->prepare(sprintf($query)); $st = $this->getPDO()->prepare(\sprintf($query));
$st->execute(); $st->execute();
@ -743,10 +743,10 @@ class MySQL extends Adapter
$this->resetDebug(); $this->resetDebug();
$this $this
->setDebug('query', preg_replace('/\s+/', ' ', sprintf($query))) ->setDebug('query', \preg_replace('/\s+/', ' ', \sprintf($query)))
->setDebug('time', microtime(true) - $start) ->setDebug('time', \microtime(true) - $start)
->setDebug('filters', count($options['filters'])) ->setDebug('filters', \count($options['filters']))
->setDebug('joins', substr_count($query, 'JOIN')) ->setDebug('joins', \substr_count($query, 'JOIN'))
; ;
return (int) (isset($result['result'])) ? $result['result'] : 0; return (int) (isset($result['result'])) ? $result['result'] : 0;
@ -757,7 +757,7 @@ class MySQL extends Adapter
*/ */
public function getId() public function getId()
{ {
$unique = uniqid(); $unique = \uniqid();
$attempts = 5; $attempts = 5;
for ($i = 1; $i <= $attempts; ++$i) { for ($i = 1; $i <= $attempts; ++$i) {
@ -801,7 +801,7 @@ class MySQL extends Adapter
$operator = null; $operator = null;
foreach ($operatorsMap as $node) { foreach ($operatorsMap as $node) {
if (strpos($filter, $node) !== false) { if (\strpos($filter, $node) !== false) {
$operator = $node; $operator = $node;
break; break;
} }
@ -811,9 +811,9 @@ class MySQL extends Adapter
throw new Exception('Invalid operator'); throw new Exception('Invalid operator');
} }
$filter = explode($operator, $filter); $filter = \explode($operator, $filter);
if (count($filter) != 2) { if (\count($filter) != 2) {
throw new Exception('Invalid filter expression'); throw new Exception('Invalid filter expression');
} }
@ -838,7 +838,7 @@ class MySQL extends Adapter
*/ */
protected function getDataType($value) protected function getDataType($value)
{ {
switch (gettype($value)) { switch (\gettype($value)) {
case 'string': case 'string':
return self::DATA_TYPE_STRING; return self::DATA_TYPE_STRING;
@ -857,7 +857,7 @@ class MySQL extends Adapter
break; break;
case 'array': case 'array':
if ((bool) count(array_filter(array_keys($value), 'is_string'))) { if ((bool) \count(\array_filter(\array_keys($value), 'is_string'))) {
return self::DATA_TYPE_DICTIONARY; return self::DATA_TYPE_DICTIONARY;
} }
@ -869,7 +869,7 @@ class MySQL extends Adapter
break; break;
} }
throw new Exception('Unknown data type: '.$value.' ('.gettype($value).')'); throw new Exception('Unknown data type: '.$value.' ('.\gettype($value).')');
} }
/** /**

View file

@ -42,11 +42,11 @@ class Redis extends Adapter
*/ */
public function getDocument($id) public function getDocument($id)
{ {
$output = json_decode($this->getRedis()->get($this->getNamespace().':document-'.$id), true); $output = \json_decode($this->getRedis()->get($this->getNamespace().':document-'.$id), true);
if (!$output) { if (!$output) {
$output = $this->adapter->getDocument($id); $output = $this->adapter->getDocument($id);
$this->getRedis()->set($this->getNamespace().':document-'.$id, json_encode($output, JSON_UNESCAPED_UNICODE)); $this->getRedis()->set($this->getNamespace().':document-'.$id, \json_encode($output, JSON_UNESCAPED_UNICODE));
} }
$output = $this->parseRelations($output); $output = $this->parseRelations($output);
@ -78,7 +78,7 @@ class Redis extends Adapter
foreach ($output['temp-relations'] as $i => $relationship) { foreach ($output['temp-relations'] as $i => $relationship) {
$node = $relationship['end']; $node = $relationship['end'];
$node = (!empty($nodes[$i])) ? $this->parseRelations(json_decode($nodes[$i], true)) : $this->getDocument($node); $node = (!empty($nodes[$i])) ? $this->parseRelations(\json_decode($nodes[$i], true)) : $this->getDocument($node);
if (empty($node)) { if (empty($node)) {
continue; continue;
@ -196,7 +196,7 @@ class Redis extends Adapter
$nodes = (!empty($keys)) ? $this->getRedis()->mget($keys) : []; $nodes = (!empty($keys)) ? $this->getRedis()->mget($keys) : [];
foreach ($data as $i => &$node) { foreach ($data as $i => &$node) {
$temp = (!empty($nodes[$i])) ? $this->parseRelations(json_decode($nodes[$i], true)) : $this->getDocument($node); $temp = (!empty($nodes[$i])) ? $this->parseRelations(\json_decode($nodes[$i], true)) : $this->getDocument($node);
if (!empty($temp)) { if (!empty($temp)) {
$node = $temp; $node = $temp;

View file

@ -122,7 +122,7 @@ class Database
*/ */
public function getCollection(array $options) public function getCollection(array $options)
{ {
$options = array_merge([ $options = \array_merge([
'offset' => 0, 'offset' => 0,
'limit' => 15, 'limit' => 15,
'search' => '', 'search' => '',
@ -142,11 +142,11 @@ class Database
} }
if ($options['first']) { if ($options['first']) {
$results = reset($results); $results = \reset($results);
} }
if ($options['last']) { if ($options['last']) {
$results = end($results); $results = \end($results);
} }
return $results; return $results;
@ -160,7 +160,7 @@ class Database
*/ */
public function getDocument($id, $mock = true) public function getDocument($id, $mock = true)
{ {
if (is_null($id)) { if (\is_null($id)) {
return new Document([]); return new Document([]);
} }
@ -322,7 +322,7 @@ class Database
*/ */
public function getCount(array $options) public function getCount(array $options)
{ {
$options = array_merge([ $options = \array_merge([
'filters' => [], 'filters' => [],
], $options); ], $options);

View file

@ -24,7 +24,7 @@ class Document extends ArrayObject
public function __construct($input = null, $flags = 0, $iterator_class = 'ArrayIterator') public function __construct($input = null, $flags = 0, $iterator_class = 'ArrayIterator')
{ {
foreach ($input as $key => &$value) { foreach ($input as $key => &$value) {
if (is_array($value)) { if (\is_array($value)) {
if (isset($value['$id']) || isset($value['$collection'])) { if (isset($value['$id']) || isset($value['$collection'])) {
$input[$key] = new self($value); $input[$key] = new self($value);
} else { } else {
@ -76,7 +76,7 @@ class Document extends ArrayObject
*/ */
public function getAttribute($name, $default = null) public function getAttribute($name, $default = null)
{ {
$name = explode('.', $name); $name = \explode('.', $name);
$temp = &$this; $temp = &$this;
@ -109,12 +109,12 @@ class Document extends ArrayObject
$this[$key] = $value; $this[$key] = $value;
break; break;
case self::SET_TYPE_APPEND: case self::SET_TYPE_APPEND:
$this[$key] = (!isset($this[$key]) || !is_array($this[$key])) ? [] : $this[$key]; $this[$key] = (!isset($this[$key]) || !\is_array($this[$key])) ? [] : $this[$key];
array_push($this[$key], $value); \array_push($this[$key], $value);
break; break;
case self::SET_TYPE_PREPEND: case self::SET_TYPE_PREPEND:
$this[$key] = (!isset($this[$key]) || !is_array($this[$key])) ? [] : $this[$key]; $this[$key] = (!isset($this[$key]) || !\is_array($this[$key])) ? [] : $this[$key];
array_unshift($this[$key], $value); \array_unshift($this[$key], $value);
break; break;
} }
@ -154,15 +154,15 @@ class Document extends ArrayObject
*/ */
public function search($key, $value, $scope = null) public function search($key, $value, $scope = null)
{ {
$array = (!is_null($scope)) ? $scope : $this; $array = (!\is_null($scope)) ? $scope : $this;
if (is_array($array) || $array instanceof self) { if (\is_array($array) || $array instanceof self) {
if (isset($array[$key]) && $array[$key] == $value) { if (isset($array[$key]) && $array[$key] == $value) {
return $array; return $array;
} }
foreach ($array as $k => $v) { foreach ($array as $k => $v) {
if ((is_array($v) || $v instanceof self) && (!empty($v))) { if ((\is_array($v) || $v instanceof self) && (!empty($v))) {
$result = $this->search($key, $value, $v); $result = $this->search($key, $value, $v);
if (!empty($result)) { if (!empty($result)) {
@ -210,17 +210,17 @@ class Document extends ArrayObject
$output = array(); $output = array();
foreach ($array as $key => &$value) { foreach ($array as $key => &$value) {
if (!empty($whitelist) && !in_array($key, $whitelist)) { // Export only whitelisted fields if (!empty($whitelist) && !\in_array($key, $whitelist)) { // Export only whitelisted fields
continue; continue;
} }
if (!empty($blacklist) && in_array($key, $blacklist)) { // Don't export blacklisted fields if (!empty($blacklist) && \in_array($key, $blacklist)) { // Don't export blacklisted fields
continue; continue;
} }
if ($value instanceof self) { if ($value instanceof self) {
$output[$key] = $value->getArrayCopy($whitelist, $blacklist); $output[$key] = $value->getArrayCopy($whitelist, $blacklist);
} elseif (is_array($value)) { } elseif (\is_array($value)) {
foreach ($value as $childKey => &$child) { foreach ($value as $childKey => &$child) {
if ($child instanceof self) { if ($child instanceof self) {
$output[$key][$childKey] = $child->getArrayCopy($whitelist, $blacklist); $output[$key][$childKey] = $child->getArrayCopy($whitelist, $blacklist);

View file

@ -75,14 +75,14 @@ class Authorization extends Validator
$permission = null; $permission = null;
foreach ($permissions[$this->action] as $permission) { foreach ($permissions[$this->action] as $permission) {
$permission = str_replace(':{self}', ':'.$this->document->getId(), $permission); $permission = \str_replace(':{self}', ':'.$this->document->getId(), $permission);
if (in_array($permission, self::getRoles())) { if (\in_array($permission, self::getRoles())) {
return true; return true;
} }
} }
$this->message = 'User is missing '.$this->action.' for "'.$permission.'" permission. Only this scopes "'.json_encode(self::getRoles()).'" is given and only this are allowed "'.json_encode($permissions[$this->action]).'".'; $this->message = 'User is missing '.$this->action.' for "'.$permission.'" permission. Only this scopes "'.\json_encode(self::getRoles()).'" is given and only this are allowed "'.\json_encode($permissions[$this->action]).'".';
return false; return false;
} }

View file

@ -38,16 +38,16 @@ class Collection extends Structure
public function isValid($document) public function isValid($document)
{ {
$document = new Document( $document = new Document(
array_merge($this->merge, ($document instanceof Document) ? $document->getArrayCopy() : $document) \array_merge($this->merge, ($document instanceof Document) ? $document->getArrayCopy() : $document)
); );
if (is_null($document->getCollection())) { if (\is_null($document->getCollection())) {
$this->message = 'Missing collection attribute $collection'; $this->message = 'Missing collection attribute $collection';
return false; return false;
} }
if (!in_array($document->getCollection(), $this->collections)) { if (!\in_array($document->getCollection(), $this->collections)) {
$this->message = 'Collection is not allowed'; $this->message = 'Collection is not allowed';
return false; return false;

View file

@ -34,15 +34,15 @@ class Key extends Validator
*/ */
public function isValid($value) public function isValid($value)
{ {
if(!is_string($value)) { if(!\is_string($value)) {
return false; return false;
} }
if (preg_match('/[^A-Za-z0-9\-\_]/', $value)) { if (\preg_match('/[^A-Za-z0-9\-\_]/', $value)) {
return false; return false;
} }
if (mb_strlen($value) > 32) { if (\mb_strlen($value) > 32) {
return false; return false;
} }

View file

@ -50,21 +50,21 @@ class Permissions extends Validator
*/ */
public function isValid($value) public function isValid($value)
{ {
if (!is_array($value) && !empty($value)) { if (!\is_array($value) && !empty($value)) {
$this->message = 'Invalid permissions data structure'; $this->message = 'Invalid permissions data structure';
return false; return false;
} }
foreach ($value as $action => $roles) { foreach ($value as $action => $roles) {
if (!in_array($action, ['read', 'write'])) { if (!\in_array($action, ['read', 'write'])) {
$this->message = 'Unknown action ("'.$action.'")'; $this->message = 'Unknown action ("'.$action.'")';
return false; return false;
} }
foreach ($roles as $role) { foreach ($roles as $role) {
if (!is_string($role)) { if (!\is_string($role)) {
$this->message = 'Permissions role must be a string'; $this->message = 'Permissions role must be a string';
return false; return false;

View file

@ -124,11 +124,11 @@ class Structure extends Validator
*/ */
public function isValid($document) public function isValid($document)
{ {
$document = (is_array($document)) ? new Document($document) : $document; $document = (\is_array($document)) ? new Document($document) : $document;
$this->id = $document->getId(); $this->id = $document->getId();
if (is_null($document->getCollection())) { if (\is_null($document->getCollection())) {
$this->message = 'Missing collection attribute $collection'; $this->message = 'Missing collection attribute $collection';
return false; return false;
@ -136,14 +136,14 @@ class Structure extends Validator
$collection = $this->getCollection($document->getCollection()); $collection = $this->getCollection($document->getCollection());
if (is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
$this->message = 'Collection not found'; $this->message = 'Collection not found';
return false; return false;
} }
$array = $document->getArrayCopy(); $array = $document->getArrayCopy();
$rules = array_merge($this->rules, $collection->getAttribute('rules', [])); $rules = \array_merge($this->rules, $collection->getAttribute('rules', []));
foreach ($rules as $rule) { // Check all required keys are set foreach ($rules as $rule) { // Check all required keys are set
if (isset($rule['key']) && !isset($array[$rule['key']]) if (isset($rule['key']) && !isset($array[$rule['key']])
@ -208,11 +208,11 @@ class Structure extends Validator
} }
if (empty($validator)) { // Error creating validator for property if (empty($validator)) { // Error creating validator for property
$this->message = 'Unknown rule type "'.$ruleType.'" for property "'.htmlspecialchars($key, ENT_QUOTES, 'UTF-8').'"'; $this->message = 'Unknown rule type "'.$ruleType.'" for property "'.\htmlspecialchars($key, ENT_QUOTES, 'UTF-8').'"';
if (empty($ruleType)) { if (empty($ruleType)) {
$this->message = 'Unknown property "'.$key.'" type'. $this->message = 'Unknown property "'.$key.'" type'.
'. Make sure to follow '.strtolower($collection->getAttribute('name', 'unknown')).' collection structure'; '. Make sure to follow '.\strtolower($collection->getAttribute('name', 'unknown')).' collection structure';
} }
return false; return false;
@ -232,7 +232,7 @@ class Structure extends Validator
} }
if ($ruleArray) { // Array of values validation if ($ruleArray) { // Array of values validation
if (!is_array($value)) { if (!\is_array($value)) {
$this->message = 'Property "'.$key.'" must be an array'; $this->message = 'Property "'.$key.'" must be an array';
return false; return false;
@ -260,8 +260,8 @@ class Structure extends Validator
} }
if (!empty($array)) { // No fields should be left unvalidated if (!empty($array)) { // No fields should be left unvalidated
$this->message = 'Unknown properties are not allowed ('.implode(', ', array_keys($array)).') for this collection'. $this->message = 'Unknown properties are not allowed ('.\implode(', ', \array_keys($array)).') for this collection'.
'. Make sure to follow '.strtolower($collection->getAttribute('name', 'unknown')).' collection structure'; '. Make sure to follow '.\strtolower($collection->getAttribute('name', 'unknown')).' collection structure';
return false; return false;
} }

View file

@ -29,7 +29,7 @@ class UID extends Validator
*/ */
public function isValid($value) public function isValid($value)
{ {
if (is_numeric($value)) { if (\is_numeric($value)) {
//return false; //return false;
} }

View file

@ -34,12 +34,12 @@ class CNAME extends Validator
public function isValid($domain) public function isValid($domain)
{ {
try { try {
$records = dns_get_record($domain, DNS_CNAME); $records = \dns_get_record($domain, DNS_CNAME);
} catch (\Throwable $th) { } catch (\Throwable $th) {
return false; return false;
} }
if(!$records || !is_array($records)) { if(!$records || !\is_array($records)) {
return false; return false;
} }

View file

@ -81,7 +81,7 @@ class Origin extends Validator
public function getDescription() public function getDescription()
{ {
if(!array_key_exists($this->client, $this->platforms)) { if(!\array_key_exists($this->client, $this->platforms)) {
return 'Unsupported platform'; return 'Unsupported platform';
} }
@ -99,8 +99,8 @@ class Origin extends Validator
*/ */
public function isValid($origin) public function isValid($origin)
{ {
$scheme = parse_url($origin, PHP_URL_SCHEME); $scheme = \parse_url($origin, PHP_URL_SCHEME);
$host = parse_url($origin, PHP_URL_HOST); $host = \parse_url($origin, PHP_URL_HOST);
$this->host = $host; $this->host = $host;
$this->client = $scheme; $this->client = $scheme;
@ -109,7 +109,7 @@ class Origin extends Validator
return true; return true;
} }
if(in_array($host, $this->clients)) { if(\in_array($host, $this->clients)) {
return true; return true;
} }

View file

@ -20,7 +20,7 @@ class OpenSSL
*/ */
public static function encrypt($data, $method, $key, $options = 0, $iv = '', &$tag = null, $aad = '', $tag_length = 16) public static function encrypt($data, $method, $key, $options = 0, $iv = '', &$tag = null, $aad = '', $tag_length = 16)
{ {
return openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length); return \openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length);
} }
/** /**
@ -36,7 +36,7 @@ class OpenSSL
*/ */
public static function decrypt($data, $method, $password, $options = 1, $iv = '', $tag = '', $aad = '') public static function decrypt($data, $method, $password, $options = 1, $iv = '', $tag = '', $aad = '')
{ {
return openssl_decrypt($data, $method, $password, $options, $iv, $tag, $aad); return \openssl_decrypt($data, $method, $password, $options, $iv, $tag, $aad);
} }
/** /**
@ -46,7 +46,7 @@ class OpenSSL
*/ */
public static function cipherIVLength($method) public static function cipherIVLength($method)
{ {
return openssl_cipher_iv_length($method); return \openssl_cipher_iv_length($method);
} }
/** /**
@ -57,6 +57,6 @@ class OpenSSL
*/ */
public static function randomPseudoBytes($length, &$crypto_strong = null) public static function randomPseudoBytes($length, &$crypto_strong = null)
{ {
return openssl_random_pseudo_bytes($length, $crypto_strong); return \openssl_random_pseudo_bytes($length, $crypto_strong);
} }
} }

View file

@ -112,9 +112,9 @@ class Resize
public function save(string $path = null, string $type = '', int $quality = 75) public function save(string $path = null, string $type = '', int $quality = 75)
{ {
// Create directory with write permissions // Create directory with write permissions
if (null !== $path && !file_exists(dirname($path))) { if (null !== $path && !\file_exists(\dirname($path))) {
if (!@mkdir(dirname($path), 0755, true)) { if (!@\mkdir(\dirname($path), 0755, true)) {
throw new Exception('Can\'t create directory '.dirname($path)); throw new Exception('Can\'t create directory '.\dirname($path));
} }
} }
@ -134,30 +134,30 @@ class Resize
//$this->image->setImageFormat('webp'); //$this->image->setImageFormat('webp');
$signature = $this->image->getImageSignature(); $signature = $this->image->getImageSignature();
$temp = '/tmp/temp-'.$signature.'.'.strtolower($this->image->getImageFormat()); $temp = '/tmp/temp-'.$signature.'.'.\strtolower($this->image->getImageFormat());
$output = '/tmp/output-'.$signature.'.webp'; $output = '/tmp/output-'.$signature.'.webp';
// save temp // save temp
$this->image->writeImages($temp, true); $this->image->writeImages($temp, true);
// convert temp // convert temp
exec("cwebp -quiet -metadata none -q $quality $temp -o $output"); \exec("cwebp -quiet -metadata none -q $quality $temp -o $output");
$data = file_get_contents($output); $data = \file_get_contents($output);
//load webp //load webp
if (empty($path)) { if (empty($path)) {
return $data; return $data;
} else { } else {
file_put_contents($path, $data, LOCK_EX); \file_put_contents($path, $data, LOCK_EX);
} }
$this->image->clear(); $this->image->clear();
$this->image->destroy(); $this->image->destroy();
//delete webp //delete webp
unlink($output); \unlink($output);
unlink($temp); \unlink($temp);
return; return;
@ -165,7 +165,7 @@ class Resize
case 'png': case 'png':
/* Scale quality from 0-100 to 0-9 */ /* Scale quality from 0-100 to 0-9 */
$scaleQuality = round(($quality / 100) * 9); $scaleQuality = \round(($quality / 100) * 9);
/* Invert quality setting as 0 is best, not 9 */ /* Invert quality setting as 0 is best, not 9 */
$invertScaleQuality = 9 - $scaleQuality; $invertScaleQuality = 9 - $scaleQuality;

View file

@ -28,7 +28,7 @@ class GZIP extends Compression
*/ */
public function compress(string $data):string public function compress(string $data):string
{ {
return gzencode($data); return \gzencode($data);
} }
/** /**
@ -40,6 +40,6 @@ class GZIP extends Compression
*/ */
public function decompress(string $data):string public function decompress(string $data):string
{ {
return gzdecode($data); return \gzdecode($data);
} }
} }

View file

@ -56,7 +56,7 @@ class Local extends Device
$path = ''; $path = '';
for ($i = 0; $i < 4; ++$i) { for ($i = 0; $i < 4; ++$i) {
$path = ($i < strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x'; $path = ($i < \strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x';
} }
return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename; return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename;
@ -76,13 +76,13 @@ class Local extends Device
*/ */
public function upload($source, $path):bool public function upload($source, $path):bool
{ {
if (!file_exists(dirname($path))) { // Checks if directory path to file exists if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists
if (!@mkdir(dirname($path), 0755, true)) { if (!@\mkdir(\dirname($path), 0755, true)) {
throw new Exception('Can\'t create directory: '.dirname($path)); throw new Exception('Can\'t create directory: '.\dirname($path));
} }
} }
if (move_uploaded_file($source, $path)) { if (\move_uploaded_file($source, $path)) {
return true; return true;
} }
@ -98,7 +98,7 @@ class Local extends Device
*/ */
public function read(string $path):string public function read(string $path):string
{ {
return file_get_contents($path); return \file_get_contents($path);
} }
/** /**
@ -111,13 +111,13 @@ class Local extends Device
*/ */
public function write(string $path, string $data):bool public function write(string $path, string $data):bool
{ {
if (!file_exists(dirname($path))) { // Checks if directory path to file exists if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists
if (!@mkdir(dirname($path), 0755, true)) { if (!@\mkdir(\dirname($path), 0755, true)) {
throw new Exception('Can\'t create directory '.dirname($path)); throw new Exception('Can\'t create directory '.\dirname($path));
} }
} }
return file_put_contents($path, $data); return \file_put_contents($path, $data);
} }
/** /**
@ -132,13 +132,13 @@ class Local extends Device
*/ */
public function move(string $source, string $target):bool public function move(string $source, string $target):bool
{ {
if (!file_exists(dirname($target))) { // Checks if directory path to file exists if (!\file_exists(\dirname($target))) { // Checks if directory path to file exists
if (!@mkdir(dirname($target), 0755, true)) { if (!@\mkdir(\dirname($target), 0755, true)) {
throw new Exception('Can\'t create directory '.dirname($target)); throw new Exception('Can\'t create directory '.\dirname($target));
} }
} }
if (rename($source, $target)) { if (\rename($source, $target)) {
return true; return true;
} }
@ -157,17 +157,17 @@ class Local extends Device
*/ */
public function delete(string $path, bool $recursive = false):bool public function delete(string $path, bool $recursive = false):bool
{ {
if(is_dir($path) && $recursive) { if(\is_dir($path) && $recursive) {
$files = glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned $files = \glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned
foreach($files as $file) { foreach($files as $file) {
$this->delete($file, true); $this->delete($file, true);
} }
rmdir($path); \rmdir($path);
} }
elseif(is_file($path)) { elseif(\is_file($path)) {
return unlink($path); return \unlink($path);
} }
return false; return false;
@ -184,7 +184,7 @@ class Local extends Device
*/ */
public function getFileSize(string $path):int public function getFileSize(string $path):int
{ {
return filesize($path); return \filesize($path);
} }
/** /**
@ -198,7 +198,7 @@ class Local extends Device
*/ */
public function getFileMimeType(string $path):string public function getFileMimeType(string $path):string
{ {
return mime_content_type($path); return \mime_content_type($path);
} }
/** /**
@ -212,7 +212,7 @@ class Local extends Device
*/ */
public function getFileHash(string $path):string public function getFileHash(string $path):string
{ {
return md5_file($path); return \md5_file($path);
} }
/** /**
@ -230,27 +230,27 @@ class Local extends Device
{ {
$size = 0; $size = 0;
$directory = opendir($path); $directory = \opendir($path);
if (!$directory) { if (!$directory) {
return -1; return -1;
} }
while (($file = readdir($directory)) !== false) { while (($file = \readdir($directory)) !== false) {
// Skip file pointers // Skip file pointers
if ($file[0] == '.') { if ($file[0] == '.') {
continue; continue;
} }
// Go recursive down, or add the file size // Go recursive down, or add the file size
if (is_dir($path.$file)) { if (\is_dir($path.$file)) {
$size += $this->getDirectorySize($path.$file.DIRECTORY_SEPARATOR); $size += $this->getDirectorySize($path.$file.DIRECTORY_SEPARATOR);
} else { } else {
$size += filesize($path.$file); $size += \filesize($path.$file);
} }
} }
closedir($directory); \closedir($directory);
return $size; return $size;
} }
@ -264,7 +264,7 @@ class Local extends Device
*/ */
public function getPartitionFreeSpace():float public function getPartitionFreeSpace():float
{ {
return disk_free_space($this->getRoot()); return \disk_free_space($this->getRoot());
} }
/** /**
@ -276,6 +276,6 @@ class Local extends Device
*/ */
public function getPartitionTotalSpace():float public function getPartitionTotalSpace():float
{ {
return disk_total_space($this->getRoot()); return \disk_total_space($this->getRoot());
} }
} }

View file

@ -40,7 +40,7 @@ class S3 extends Device
$path = ''; $path = '';
for ($i = 0; $i < 4; ++$i) { for ($i = 0; $i < 4; ++$i) {
$path = ($i < strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x'; $path = ($i < \strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x';
} }
return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename; return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename;

View file

@ -27,7 +27,7 @@ class Storage
*/ */
public static function addDevice($name, Device $device) public static function addDevice($name, Device $device)
{ {
if (array_key_exists($name, self::$devices)) { if (\array_key_exists($name, self::$devices)) {
throw new Exception('The device "'.$name.'" is already listed'); throw new Exception('The device "'.$name.'" is already listed');
} }
@ -47,7 +47,7 @@ class Storage
*/ */
public static function getDevice($name) public static function getDevice($name)
{ {
if (!array_key_exists($name, self::$devices)) { if (!\array_key_exists($name, self::$devices)) {
throw new Exception('The device "'.$name.'" is not listed'); throw new Exception('The device "'.$name.'" is not listed');
} }
@ -65,7 +65,7 @@ class Storage
*/ */
public static function exists($name) public static function exists($name)
{ {
return (bool) array_key_exists($name, self::$devices); return (bool) \array_key_exists($name, self::$devices);
} }
/** /**
@ -89,6 +89,6 @@ class Storage
++$i; ++$i;
} }
return round($bytes, $decimals).$units[$i]; return \round($bytes, $decimals).$units[$i];
} }
} }

View file

@ -24,7 +24,7 @@ class FileName extends Validator
return false; return false;
} }
if (!preg_match('/^[a-zA-Z0-9.]+$/', $name)) { if (!\preg_match('/^[a-zA-Z0-9.]+$/', $name)) {
return false; return false;
} }

View file

@ -68,23 +68,23 @@ class FileType extends Validator
return false; return false;
} }
$handle = fopen($path, 'r'); $handle = \fopen($path, 'r');
if (!$handle) { if (!$handle) {
return false; return false;
} }
$bytes = fgets($handle, 8); $bytes = \fgets($handle, 8);
foreach ($this->whiteList as $key) { foreach ($this->whiteList as $key) {
if (strpos($bytes, $this->types[$key]) === 0) { if (\strpos($bytes, $this->types[$key]) === 0) {
fclose($handle); \fclose($handle);
return true; return true;
} }
} }
fclose($handle); \fclose($handle);
return false; return false;
} }

View file

@ -23,13 +23,13 @@ class Template extends View
return ''; return '';
} }
if (is_readable($this->path)) { if (\is_readable($this->path)) {
$template = file_get_contents($this->path); // Include template file $template = \file_get_contents($this->path); // Include template file
} else { } else {
throw new Exception('"'.$this->path.'" template is not readable or not found'); throw new Exception('"'.$this->path.'" template is not readable or not found');
} }
$template = str_replace(array_keys($this->params), array_values($this->params), $template); $template = \str_replace(\array_keys($this->params), \array_values($this->params), $template);
return $template; return $template;
} }
@ -45,7 +45,7 @@ class Template extends View
*/ */
public static function parseURL($url) public static function parseURL($url)
{ {
return parse_url($url); return \parse_url($url);
} }
/** /**
@ -89,10 +89,10 @@ class Template extends View
{ {
$parsed = []; $parsed = [];
parse_str($query1, $parsed); \parse_str($query1, $parsed);
$parsed = array_merge($parsed, $query2); $parsed = \array_merge($parsed, $query2);
return http_build_query($parsed); return \http_build_query($parsed);
} }
} }

View file

@ -26,7 +26,7 @@ class URL
'fragment' => '', 'fragment' => '',
]; ];
return array_merge($default, parse_url($url)); return \array_merge($default, \parse_url($url));
} }
/** /**
@ -41,7 +41,7 @@ class URL
*/ */
static public function unparse(array $url, array $ommit = []):string static public function unparse(array $url, array $ommit = []):string
{ {
if (isset($url['path']) && mb_substr($url['path'], 0, 1) !== '/') { if (isset($url['path']) && \mb_substr($url['path'], 0, 1) !== '/') {
$url['path'] = '/'.$url['path']; $url['path'] = '/'.$url['path'];
} }
@ -87,7 +87,7 @@ class URL
*/ */
static public function parseQuery(string $query):array static public function parseQuery(string $query):array
{ {
parse_str($query, $result); \parse_str($query, $result);
return $result; return $result;
} }
@ -103,6 +103,6 @@ class URL
*/ */
static public function unparseQuery(array $query):string static public function unparseQuery(array $query):string
{ {
return http_build_query($query); return \http_build_query($query);
} }
} }