mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Добавлена поддержка для "внутренних" scopes, запросить которые во время oauth процесса нельзя
This commit is contained in:
18
common/components/Annotations/Reader.php
Normal file
18
common/components/Annotations/Reader.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace common\components\Annotations;
|
||||
|
||||
class Reader extends \Minime\Annotations\Reader {
|
||||
|
||||
/**
|
||||
* Поначаду я думал кэшировать эту штуку, но потом забил, т.к. всё всё равно завернул
|
||||
* в Yii::$app->cache и как-то надобность в отдельном кэше отпала, так что пока забьём
|
||||
* и оставим как заготовку на будущее
|
||||
*
|
||||
* @return \Minime\Annotations\Interfaces\ReaderInterface
|
||||
*/
|
||||
public static function createFromDefaults() {
|
||||
return parent::createFromDefaults();
|
||||
//return new self(new \Minime\Annotations\Parser(), new RedisCache());
|
||||
}
|
||||
|
||||
}
|
65
common/components/Annotations/RedisCache.php
Normal file
65
common/components/Annotations/RedisCache.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace common\components\Annotations;
|
||||
|
||||
use common\components\Redis\Key;
|
||||
use common\components\Redis\Set;
|
||||
use Minime\Annotations\Interfaces\CacheInterface;
|
||||
use yii\helpers\Json;
|
||||
|
||||
class RedisCache implements CacheInterface {
|
||||
|
||||
/**
|
||||
* Generates uuid for a given docblock string
|
||||
* @param string $docblock docblock string
|
||||
* @return string uuid that maps to the given docblock
|
||||
*/
|
||||
public function getKey($docblock) {
|
||||
return md5($docblock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an annotation AST to cache
|
||||
*
|
||||
* @param string $key cache entry uuid
|
||||
* @param array $annotations annotation AST
|
||||
*/
|
||||
public function set($key, array $annotations) {
|
||||
$this->getRedisKey($key)->setValue(Json::encode($annotations))->expire(3600);
|
||||
$this->getRedisKeysSet()->add($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves cached annotations from docblock uuid
|
||||
*
|
||||
* @param string $key cache entry uuid
|
||||
* @return array cached annotation AST
|
||||
*/
|
||||
public function get($key) {
|
||||
$result = $this->getRedisKey($key)->getValue();
|
||||
if ($result === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Json::decode($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets cache
|
||||
*/
|
||||
public function clear() {
|
||||
/** @var array $keys */
|
||||
$keys = $this->getRedisKeysSet()->getValue();
|
||||
foreach ($keys as $key) {
|
||||
$this->getRedisKey($key)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
private function getRedisKey(string $key): Key {
|
||||
return new Key('annotations', 'cache', $key);
|
||||
}
|
||||
|
||||
private function getRedisKeysSet(): Set {
|
||||
return new Set('annotations', 'cache', 'keys');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user