mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Implemented PHP-CS-Fixer support
This commit is contained in:
@@ -43,7 +43,7 @@ class EmailRenderer extends Component {
|
||||
$this->renderer->setBaseDomain($this->buildBasePath());
|
||||
}
|
||||
|
||||
public function getBaseDomain() : string {
|
||||
public function getBaseDomain(): string {
|
||||
return $this->_baseDomain;
|
||||
}
|
||||
|
||||
|
@@ -106,7 +106,6 @@ class ElyDecorator implements DecoratorInterface {
|
||||
$topPadding,
|
||||
$multiple
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
private function encodeSvgToBase64(string $filePath): string {
|
||||
|
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
namespace common\components\RabbitMQ;
|
||||
|
||||
use yii\base\Exception;
|
||||
use yii\helpers\Json;
|
||||
use PhpAmqpLib\Channel\AMQPChannel;
|
||||
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
use yii\base\Exception;
|
||||
use yii\helpers\Json;
|
||||
|
||||
/**
|
||||
* Не гибкий компонент для работы с RabbitMQ, заточенный под нужны текущего проекта
|
||||
@@ -17,20 +17,10 @@ use PhpAmqpLib\Message\AMQPMessage;
|
||||
*/
|
||||
class Component extends \yii\base\Component {
|
||||
|
||||
const TYPE_TOPIC = 'topic';
|
||||
const TYPE_DIRECT = 'direct';
|
||||
const TYPE_HEADERS = 'headers';
|
||||
const TYPE_FANOUT = 'fanout';
|
||||
|
||||
/**
|
||||
* @var AMQPStreamConnection
|
||||
*/
|
||||
protected $amqpConnection;
|
||||
|
||||
/**
|
||||
* @var AMQPChannel[]
|
||||
*/
|
||||
protected $channels = [];
|
||||
public const TYPE_TOPIC = 'topic';
|
||||
public const TYPE_DIRECT = 'direct';
|
||||
public const TYPE_HEADERS = 'headers';
|
||||
public const TYPE_FANOUT = 'fanout';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -57,6 +47,16 @@ class Component extends \yii\base\Component {
|
||||
*/
|
||||
public $vhost = '/';
|
||||
|
||||
/**
|
||||
* @var AMQPStreamConnection
|
||||
*/
|
||||
protected $amqpConnection;
|
||||
|
||||
/**
|
||||
* @var AMQPChannel[]
|
||||
*/
|
||||
protected $channels = [];
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -115,6 +115,30 @@ class Component extends \yii\base\Component {
|
||||
$channel->basic_publish(...$this->preparePublishArgs($message, $exchangeName, $routingKey, $publishArgs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns prepaired AMQP message.
|
||||
*
|
||||
* @param string|array|object $message
|
||||
* @param array $properties
|
||||
* @return AMQPMessage
|
||||
* @throws Exception If message is empty.
|
||||
*/
|
||||
public function prepareMessage($message, $properties = null) {
|
||||
if ($message instanceof AMQPMessage) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
if (empty($message)) {
|
||||
throw new Exception('AMQP message can not be empty');
|
||||
}
|
||||
|
||||
if (is_array($message) || is_object($message)) {
|
||||
$message = Json::encode($message);
|
||||
}
|
||||
|
||||
return new AMQPMessage($message, $properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Объединяет переданный набор аргументов с поведением по умолчанию
|
||||
*
|
||||
@@ -150,28 +174,4 @@ class Component extends \yii\base\Component {
|
||||
], $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns prepaired AMQP message.
|
||||
*
|
||||
* @param string|array|object $message
|
||||
* @param array $properties
|
||||
* @return AMQPMessage
|
||||
* @throws Exception If message is empty.
|
||||
*/
|
||||
public function prepareMessage($message, $properties = null) {
|
||||
if ($message instanceof AMQPMessage) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
if (empty($message)) {
|
||||
throw new Exception('AMQP message can not be empty');
|
||||
}
|
||||
|
||||
if (is_array($message) || is_object($message)) {
|
||||
$message = Json::encode($message);
|
||||
}
|
||||
|
||||
return new AMQPMessage($message, $properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -157,7 +157,7 @@ class Connection extends Component implements ConnectionInterface {
|
||||
/**
|
||||
* @var array List of available redis commands http://redis.io/commands
|
||||
*/
|
||||
const REDIS_COMMANDS = [
|
||||
public const REDIS_COMMANDS = [
|
||||
'BLPOP', // key [key ...] timeout Remove and get the first element in a list, or block until one is available
|
||||
'BRPOP', // key [key ...] timeout Remove and get the last element in a list, or block until one is available
|
||||
'BRPOPLPUSH', // source destination timeout Pop a value from a list, push it to another list and return it; or block until one is available
|
||||
@@ -368,14 +368,6 @@ class Connection extends Component implements ConnectionInterface {
|
||||
*/
|
||||
private $_client;
|
||||
|
||||
public function getConnection() : ClientInterface {
|
||||
if ($this->_client === null) {
|
||||
$this->_client = new Client($this->prepareParams(), $this->options);
|
||||
}
|
||||
|
||||
return $this->_client;
|
||||
}
|
||||
|
||||
public function __call($name, $params) {
|
||||
$redisCommand = mb_strtoupper($name);
|
||||
if (in_array($redisCommand, self::REDIS_COMMANDS)) {
|
||||
@@ -385,6 +377,14 @@ class Connection extends Component implements ConnectionInterface {
|
||||
return parent::__call($name, $params);
|
||||
}
|
||||
|
||||
public function getConnection(): ClientInterface {
|
||||
if ($this->_client === null) {
|
||||
$this->_client = new Client($this->prepareParams(), $this->options);
|
||||
}
|
||||
|
||||
return $this->_client;
|
||||
}
|
||||
|
||||
public function executeCommand(string $name, array $params = []) {
|
||||
return $this->getConnection()->$name(...$params);
|
||||
}
|
||||
|
@@ -30,11 +30,13 @@ class Key {
|
||||
|
||||
public function setValue($value): self {
|
||||
$this->getRedis()->set($this->key, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete(): self {
|
||||
$this->getRedis()->del([$this->getKey()]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -44,17 +46,19 @@ class Key {
|
||||
|
||||
public function expire(int $ttl): self {
|
||||
$this->getRedis()->expire($this->key, $ttl);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function expireAt(int $unixTimestamp): self {
|
||||
$this->getRedis()->expireat($this->key, $unixTimestamp);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function buildKey(array $parts): string {
|
||||
$keyParts = [];
|
||||
foreach($parts as $part) {
|
||||
foreach ($parts as $part) {
|
||||
$keyParts[] = str_replace('_', ':', $part);
|
||||
}
|
||||
|
||||
|
@@ -8,11 +8,13 @@ class Set extends Key implements IteratorAggregate {
|
||||
|
||||
public function add($value): self {
|
||||
$this->getRedis()->sadd($this->getKey(), $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function remove($value): self {
|
||||
$this->getRedis()->srem($this->getKey(), $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@@ -6,7 +6,7 @@ use Yii;
|
||||
|
||||
class Api {
|
||||
|
||||
const BASE_DOMAIN = 'http://skinsystem.ely.by';
|
||||
private const BASE_DOMAIN = 'http://skinsystem.ely.by';
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
|
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\components;
|
||||
|
||||
class UserFriendlyRandomKey {
|
||||
|
||||
public static function make ($length = 18) {
|
||||
public static function make(int $length = 18) {
|
||||
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
||||
$numChars = strlen($chars);
|
||||
$key = '';
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
|
||||
|
||||
/**
|
||||
* Этот класс был использован для изначальной генерации паролей на Ely.by и сейчас должен быть планомерно выпилен
|
||||
* с проекта с целью заменить этот алгоритм каким-нибудь посерьёзнее.
|
||||
|
Reference in New Issue
Block a user