2016-02-14 23:20:10 +05:30
|
|
|
<?php
|
|
|
|
namespace common\models;
|
|
|
|
|
2016-12-10 02:12:07 +05:30
|
|
|
use common\components\Annotations\Reader;
|
|
|
|
use ReflectionClass;
|
|
|
|
use Yii;
|
|
|
|
|
2016-11-27 21:49:13 +05:30
|
|
|
class OauthScope {
|
2016-02-14 23:20:10 +05:30
|
|
|
|
2016-12-18 04:50:53 +05:30
|
|
|
/**
|
|
|
|
* @owner user
|
|
|
|
*/
|
2016-02-23 03:19:46 +05:30
|
|
|
const OFFLINE_ACCESS = 'offline_access';
|
2016-12-18 04:50:53 +05:30
|
|
|
/**
|
|
|
|
* @owner user
|
|
|
|
*/
|
2016-02-23 03:19:46 +05:30
|
|
|
const MINECRAFT_SERVER_SESSION = 'minecraft_server_session';
|
2016-12-18 04:50:53 +05:30
|
|
|
/**
|
|
|
|
* @owner user
|
|
|
|
*/
|
2016-08-06 19:06:24 +05:30
|
|
|
const ACCOUNT_INFO = 'account_info';
|
2016-12-18 04:50:53 +05:30
|
|
|
/**
|
|
|
|
* @owner user
|
|
|
|
*/
|
2016-08-04 00:35:19 +05:30
|
|
|
const ACCOUNT_EMAIL = 'account_email';
|
2016-12-18 04:50:53 +05:30
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @owner machine
|
|
|
|
*/
|
2016-12-10 02:12:07 +05:30
|
|
|
const ACCOUNT_BLOCK = 'account_block';
|
|
|
|
|
2016-12-18 04:50:53 +05:30
|
|
|
public static function find(): OauthScopeQuery {
|
|
|
|
return new OauthScopeQuery(static::queryScopes());
|
2016-12-10 02:12:07 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private static function queryScopes(): array {
|
|
|
|
$cacheKey = 'oauth-scopes-list';
|
|
|
|
$scopes = false;
|
|
|
|
if ($scopes === false) {
|
|
|
|
$scopes = [];
|
|
|
|
$reflection = new ReflectionClass(static::class);
|
|
|
|
$constants = $reflection->getConstants();
|
|
|
|
$reader = Reader::createFromDefaults();
|
|
|
|
foreach ($constants as $constName => $value) {
|
|
|
|
$annotations = $reader->getConstantAnnotations(static::class, $constName);
|
|
|
|
$isInternal = $annotations->get('internal', false);
|
2016-12-18 04:50:53 +05:30
|
|
|
$owner = $annotations->get('owner', 'user');
|
2016-12-10 02:12:07 +05:30
|
|
|
$keyValue = [
|
|
|
|
'value' => $value,
|
2016-12-18 04:50:53 +05:30
|
|
|
'internal' => $isInternal,
|
|
|
|
'owner' => $owner,
|
2016-12-10 02:12:07 +05:30
|
|
|
];
|
|
|
|
$scopes[$constName] = $keyValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Yii::$app->cache->set($cacheKey, $scopes, 3600);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $scopes;
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|