Skip to content

Commit d89def7

Browse files
authored
Merge pull request #1 from ruesin/change_config
Change config
2 parents 2aec4de + 7c80672 commit d89def7

14 files changed

Lines changed: 42 additions & 71 deletions

File tree

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
vendor/
33
composer.lock
44
runtime/*
5-
config/constants.php
6-
config/redis.php
7-
config/secrets.php
8-
config/server.php
5+
config/*.php
96
test.php

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# delay-queue
1+
# delay-server-single
22
基于 Redis 实现的延时队列,只提供简单的延时能力,不负责业务相关队列,需要在创建队列时提供业务队列的连接信息,消息到期时自动将消息移动到业务队列。
33

44
## 依赖
@@ -15,7 +15,7 @@ $ composer create-project --prefer-dist ruesin/delay-server-single
1515

1616
## 配置
1717
拷贝`./config/samples/*.php``./config/`,并按需修改:
18-
- `constants.php` 常量定义
18+
- `queue.php` 队列定义
1919
- `redis.php` Redis服务器配置
2020
- `secrets.php` 验证签名的密钥对
2121
- `server.php` 服务启动的配置文件,参考[swover](https://github.com/ruesin/swover)

app/Handle.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __construct($request)
2727
* 创建队列
2828
*
2929
* @return string
30-
* @throws \Exception
3130
*/
3231
public function createQueue()
3332
{
@@ -56,7 +55,6 @@ public function createQueue()
5655
/**
5756
* 删除队列
5857
* @return bool
59-
* @throws \Exception
6058
*/
6159
public function dropQueue()
6260
{
@@ -71,7 +69,6 @@ public function dropQueue()
7169
/**
7270
* 发送消息
7371
* @return bool|string
74-
* @throws \Exception
7572
*/
7673
public function addMessage()
7774
{

app/Utils/Config.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

app/Utils/Queue.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?php
22
namespace App\Utils;
33

4+
use Swover\Utils\Config;
5+
46
class Queue
57
{
68
public static function queueListName()
79
{
8-
return QUEUE_LIST;
10+
return Config::get('queue.list_name');
911
}
1012

1113
public static function queueInfoName()
1214
{
13-
return QUEUE_INFO;
15+
return Config::get('queue.info_name');
1416
}
1517

1618
public static function delayName($queue_name)
1719
{
18-
return $queue_name.DELAY_SUFFIX;
20+
return $queue_name.Config::get('queue.delay_suffix');
1921
}
2022
}

app/Utils/Redis.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace App\Utils;
34

45
/**
@@ -59,7 +60,7 @@ public static function instance($config = [])
5960
public static function close($config = [])
6061
{
6162
$config = self::getConfig($config);
62-
$name = self::configToName($config);
63+
$name = self::configToName($config);
6364

6465
if (isset(self::$_instance[$name])) {
6566
self::$_instance[$name]->quit();
@@ -71,10 +72,10 @@ public static function close($config = [])
7172

7273
private static function getConfig($config)
7374
{
74-
if(!empty($config)) {
75+
if (!empty($config)) {
7576
return $config;
7677
}
77-
return Config::get('redis');
78+
return \Swover\Utils\Config::get('redis');
7879
}
7980

8081
private static function configToName($config)

app/Utils/Sign.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function verify($request)
4040

4141
private static function secret($secretId)
4242
{
43-
$secrets = Config::get('secrets');
43+
$secrets = \Swover\Utils\Config::get('secrets');
4444
return isset($secrets[$secretId]) ? $secrets[$secretId] : false;
4545
}
4646
}

common/helpers.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
(function () {
3+
\Swover\Utils\Config::loadPath(ROOT_DIR.'/config/');
4+
})();

common/start.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
}
1212
],
1313
"require": {
14-
"ruesin/swover": "^1.0",
14+
"ruesin/swover": "^1.1",
1515
"predis/predis": "1.1.1",
1616
"php": ">=7.0",
1717
"ext-json" : "*"
1818
},
1919
"autoload": {
2020
"psr-4": {
2121
"App\\": "app/"
22-
}
22+
},
23+
"files": [
24+
"common/helpers.php"
25+
]
2326
},
2427
"prefer-stable": true,
2528
"scripts": {

0 commit comments

Comments
 (0)