Skip to content

Commit 0841373

Browse files
committed
first commit
0 parents  commit 0841373

File tree

180 files changed

+20726
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+20726
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.env
2+
.htaccess
3+
.user.ini
4+
/log/
5+
runtime
6+
vendor
7+
.idea
8+
Test.php
9+
composer.lock
10+
.phpunit.result.cache
11+
.php-cs-fixer.cache
12+
13+
14+

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Noah Buscher
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# dcr_swoole框架 - 整合各种包,模仿laravel hyperf 骨架 造的一个简单框架骨架
2+
3+
- 集成 laravel orm , restful route, redis, guzzle monolog
4+
- http websocket
5+
- rabbitmq
6+
- container
7+
- event
8+
- middleware
9+
- validate
10+
- monolog
11+
- collection
12+
- carbon
13+
- dotenv
14+
-- 支持路由注解 中间件注解
15+
16+
### 分层 (demo未按此方式)
17+
controller -> service ->repository->model
18+
19+
### http:
20+
21+
```
22+
php ./bin/start.php http:start
23+
```
24+
25+
### websocket:
26+
27+
```
28+
php ./bin/start.php ws:start
29+
```
30+
31+
### console:
32+
33+
```
34+
php artisan test2
35+
```
36+
37+
### crontab:
38+
39+
```
40+
/config/crontab.php enable 改为 true 开启
41+
```
42+
43+
### migrate:
44+
45+
```
46+
php migrate.php migrations:generate
47+
php migrate.php migrations:migrate
48+
49+
```
50+
51+
### container
52+
53+
```
54+
ApplicationContext::getContainer()
55+
或 di()
56+
57+
58+
```
59+
60+
## 路由注解和中间件注解
61+
```php
62+
#[RequestMapping(methods: "GET , POST" , path:"/api/json")]
63+
#[Middlewares(AuthMiddleware::class , TestMiddleware::class)]
64+
public function test()
65+
{
66+
return 'hello';
67+
}
68+
```
69+
70+
### 更多例子
71+
72+
/app/Controller/TestController.php
73+
74+
### composer依赖组件
75+
76+
```
77+
"doctrine/event-manager": "^1.1", 事件监听
78+
"doctrine/migrations": "^3.5", migrate
79+
"elasticsearch/elasticsearch": "7.16", es
80+
"firebase/php-jwt": "^6.3", jwt token
81+
"gregwar/captcha": "^1.1", captcha
82+
"guanhui07/database": "^1.0", laravel orm 改
83+
"guanhui07/dcr-swoole-crontab": "^1.0", crontab
84+
"guanhui07/guzzle": "^1.0", guzzle client
85+
"guanhui07/redis": "^1.0", redis pool
86+
"inhere/console": "^4.1", console command
87+
"inhere/php-validate": "^2.8", validate 验证器
88+
"intervention/image": "^2.7", image操作
89+
"middlewares/utils": "^3.0", middleware中间件
90+
"monolog/monolog": "^2.8", monolog
91+
"mwangithegreat/faker": "^1.9", faker造数据
92+
"nesbot/carbon": "^2.6", carbon time
93+
"nikic/fast-route": "^1.3", nikic的 resful route
94+
"opis/closure": "^3.6", 闭包序列化
95+
"php-amqplib/php-amqplib": "dev-master", rabbitmq
96+
"php-di/php-di": "^7.0", 依赖注入 di container
97+
"qiniu/php-sdk": "^7.7", 七牛cdn
98+
"spatie/image": "^2.2",
99+
"symfony/finder": "^5.0", symfony finder
100+
"vlucas/phpdotenv": "^5.4" dotenv读取
101+
```
102+
103+
## 关联
104+
105+
参考 hyperf laravel webman 项目
106+
107+
https://github.com/guanhui07/dcr fpm以及workerman实现websocket
108+
109+
https://github1s.com/walkor/webman-framework
110+
111+
https://github1s.com/hyperf/hyperf
112+
113+
https://github1s.com/laravel/laravel
114+
115+
https://github.com/SerendipitySwow/Serendipity-job
116+
117+
https://github.com/sunsgneayo/annotation 路由注解参考
118+
119+
120+
### todo:
121+
类似`hyperf`实现 Command Crontab AutoController Cacheable 等注解
122+

app/Console/BaseInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Console;
6+
7+
interface BaseInterface
8+
{
9+
public function handle();
10+
}

app/Console/Command/Test2.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Console\Command;
6+
7+
use App\Repository\TestRepository;
8+
use DcrSwoole\Utils\ApplicationContext;
9+
use Inhere\Console\IO\Input;
10+
use Inhere\Console\IO\Output;
11+
use Toolkit\PFlag\FlagsParser;
12+
13+
/**
14+
* Class Test2
15+
* @package app\Console\Command
16+
* php artisan test2
17+
*/
18+
class Test2 extends \Inhere\Console\Command
19+
{
20+
protected static string $name = 'test2';
21+
22+
protected static string $desc = 'print system ENV information';
23+
24+
protected function configFlags(FlagsParser $fs): void
25+
{
26+
// 绑定选项
27+
$fs->addOptByRule('update, up', 'bool;update linux command docs to latest');
28+
$fs->addOptByRule('init, i', 'bool;update linux command docs to latest');
29+
$fs->addOptByRule('search, s', 'string;input keywords for search');
30+
31+
// 绑定参数
32+
// - 这里没有设置必须 可以不传,获取到就是空string
33+
$fs->addArg('keywords', 'the keywords for search or show docs', 'string');
34+
}
35+
36+
protected function execute(Input $input, Output $output)
37+
{
38+
$keywords = $this->flags->getOpt('search', 23);
39+
var_dump($keywords);
40+
//
41+
// $name = $this->flags->getFirstArg();
42+
// if ( !$name && !$keywords) {
43+
// // env | grep XXX
44+
// $output->aList($_SERVER, 'ENV Information', ['ucFirst' => false]);
45+
// return;
46+
// }
47+
ApplicationContext::getContainer()->get(TestRepository::class)->fromRepos();
48+
$output->info("hello world ...");
49+
}
50+
}

app/Console/Command/Test2Consumer.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Console\Command;
6+
7+
use App\Service\Consumer\BalancePayConsumer;
8+
use Inhere\Console\IO\Input;
9+
use Inhere\Console\IO\Output;
10+
11+
/**
12+
* 测试使用 rabbitmq 消费者
13+
* Class Test2Consumer
14+
* @package app\Console\Command
15+
* php artisan test2_consumer
16+
*/
17+
class Test2Consumer extends \Inhere\Console\Command
18+
{
19+
protected static string $name = 'test2_consumer';
20+
21+
protected static string $desc = 'print system ENV information';
22+
23+
protected function execute(Input $input, Output $output)
24+
{
25+
go(function () {
26+
$producer = new BalancePayConsumer();
27+
$producer->consumer('balance_pay');
28+
});
29+
\Swoole\Event::wait();
30+
}
31+
}

app/Console/Kernel.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Console;
6+
7+
/**
8+
* 所有的命令类注册 类
9+
* Class Kernel
10+
*/
11+
class Kernel
12+
{
13+
/**
14+
* @todo 通过反射实现#Command注解
15+
* @see https://github.com/inhere/php-console/wiki
16+
*/
17+
public static function getCommands(): array
18+
{
19+
return [
20+
\App\Console\Command\Test2::class,
21+
\App\Console\Command\Test2Consumer::class,
22+
];
23+
}
24+
}

0 commit comments

Comments
 (0)