mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Rework identity provider for the legacy OAuth2 tokens [skip ci]
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
namespace common\components\Redis;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
class Key {
|
||||
|
||||
private $key;
|
||||
|
||||
public function __construct(...$key) {
|
||||
if (empty($key)) {
|
||||
throw new InvalidArgumentException('You must specify at least one key.');
|
||||
}
|
||||
|
||||
$this->key = $this->buildKey($key);
|
||||
}
|
||||
|
||||
public function getKey(): string {
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return Yii::$app->redis->get($this->key);
|
||||
}
|
||||
|
||||
public function setValue($value): self {
|
||||
Yii::$app->redis->set($this->key, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete(): self {
|
||||
Yii::$app->redis->del($this->getKey());
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function exists(): bool {
|
||||
return (bool)Yii::$app->redis->exists($this->key);
|
||||
}
|
||||
|
||||
public function expire(int $ttl): self {
|
||||
Yii::$app->redis->expire($this->key, $ttl);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function expireAt(int $unixTimestamp): self {
|
||||
Yii::$app->redis->expireat($this->key, $unixTimestamp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function buildKey(array $parts): string {
|
||||
$keyParts = [];
|
||||
foreach ($parts as $part) {
|
||||
$keyParts[] = str_replace('_', ':', $part);
|
||||
}
|
||||
|
||||
return implode(':', $keyParts);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
namespace common\components\Redis;
|
||||
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
class Set extends Key implements IteratorAggregate {
|
||||
|
||||
public function add($value): self {
|
||||
Yii::$app->redis->sadd($this->getKey(), $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function remove($value): self {
|
||||
Yii::$app->redis->srem($this->getKey(), $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function members(): array {
|
||||
return Yii::$app->redis->smembers($this->getKey());
|
||||
}
|
||||
|
||||
public function getValue(): array {
|
||||
return $this->members();
|
||||
}
|
||||
|
||||
public function exists(string $value = null): bool {
|
||||
if ($value === null) {
|
||||
return parent::exists();
|
||||
}
|
||||
|
||||
return (bool)Yii::$app->redis->sismember($this->getKey(), $value);
|
||||
}
|
||||
|
||||
public function diff(array $sets): array {
|
||||
return Yii::$app->redis->sdiff([$this->getKey(), implode(' ', $sets)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getIterator() {
|
||||
return new ArrayIterator($this->members());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user