https://github.com/guanhui07/dcr
借鉴Laravel实现的 PHP Framework ,FPM模式、websocket使用的workerman、支持容器、PHP8特性attributes以及反射实现了路由注解、中间件注解、Laravel Orm等特性
https://github.com/guanhui07/dcr
amqp annotation command container crontab event http illuminate-database middleware mysql orm-framework php rabbitmq websocket workerman
Last synced: 21 days ago
JSON representation
借鉴Laravel实现的 PHP Framework ,FPM模式、websocket使用的workerman、支持容器、PHP8特性attributes以及反射实现了路由注解、中间件注解、Laravel Orm等特性
- Host: GitHub
- URL: https://github.com/guanhui07/dcr
- Owner: guanhui07
- License: mit
- Created: 2023-01-19T05:17:47.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-23T14:51:14.000Z (8 months ago)
- Last Synced: 2024-08-23T16:19:31.698Z (8 months ago)
- Topics: amqp, annotation, command, container, crontab, event, http, illuminate-database, middleware, mysql, orm-framework, php, rabbitmq, websocket, workerman
- Language: PHP
- Homepage: https://packagist.org/packages/dcr/framework
- Size: 326 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dcr框架 - 整合各个包,然后模仿laravel 骨架 实现的框架
- 集成 laravel orm
- restful route
- predis
- guzzle
- monolog
- rabbitmq, workerman websocket
- container
- facade
- console
- migrate
- event
- crontab
- middleware 中间件注解
- validate
- monolog
- collection carbon
- dotenv
- PHP8特性attributes以及反射实现路由注解### 安装
```
composer create-project dcr/framework skeleton
```http: 生产不推荐,推荐使用nginx
```
php -S 127.0.0.1:8001 -t ./public
```
websocket: 基础于workerman gateway
```
php ./bin/startWs.php start
```
crontab: 基础于workerman crontab
```
php ./bin/crontab.php start
```## [更多文档](https://github.com/guanhui07/dcr/tree/master/doc)
command 应用
```
php artisan test
```## 路由注解 和 中间件注解 以及Inject注解 使用
```php
testService->testDi();
return apiResponse([]);
}
}
```## 从容器 拿对象 获取 参数
```php
//->all() ->get() ->post() 等方法
ApplicationContext::getContainer()->get(Request::class)->all();
//di()->(Request::class)->all();
```## redis 操作
```php
$redis = Redis::connection();
//->setex ->get ->del ->setnx 等方法 和predis一致
```## orm model ,使用和laravel orm一致
```php
request->post ?? [], [
// add rule
['title', 'min', 40],
['freeTime', 'number'],
]);if ($validate->isFail()) {
var_dump($validate->getErrors());
var_dump($validate->firstError());
}// $postData = $v->all(); // 原始数据
$safeData = $validate->getSafeData(); // 验证通过的安全数据return $safeData
}
```### 获取配置 需要`use DI\Attribute\Inject`
```php
#[Inject]
public Config $config;#[RequestMapping(methods: "GET , POST", path:"/test/config")]
public function config()
{
//di()->get(Config::class)->get('app.debug');
return $this->config->get('app.debug');
}
```## 中间件 需要`app/Middleware/Kernel.php` 配置
```php
handle($request);
return $response;
};
}
}```
### Console 命令应用 需要在`app/Console/Kernel.php` 配置 命令类
```php
addOptByRule('update, up', 'bool;update linux command docs to latest');
$fs->addOptByRule('init, i', 'bool;update linux command docs to latest');
$fs->addOptByRule('search, s', 'string;input keywords for search');// - 这里没有设置必须 可以不传,获取到就是空string
$fs->addArg('keywords', 'the keywords for search or show docs', 'string');
}protected function execute(Input $input, Output $output): void
{
$keywords = $this->flags->getOpt('search', 23);
var_dump($keywords);
$output->info('hello world ...');
}
}```
### event 事件
```php
params = $params;
}
public function getParams()
{
return $this->params;
}
}```
### listener 监听者
```php
getParams());
}
}```
### 触发事件
```php
#[RequestMapping(methods: 'GET , POST', path:'/test/event')]
public function event(): string
{
$params = [
'test' => 23,
];
event(new TestEvent($params),TestEvent::NAME);
// 初始化事件分发器return apiResponse([]);
}
```或者
```php
#[RequestMapping(methods: "GET , POST", path:"/test/event")]
public function event($request, $response): array
{
$params = [
'test' => 23,
];
$dispatcher = EventInstance::instance();
$dispatcher->dispatch(new TestEvent($params), TestEvent::NAME);
}
```### crontab 秒级定时任务 使用的workerman crontab
```php
get(TestRepository::class)->test1();
// di()->get(TestRepository::class)->fromRepos();
}
}
```## 依赖如下组件 并查阅文档 使用 组合了 此框架
```
"illuminate/database": "^8.83", laravel orm
"qiniu/php-sdk": "^7.6", qiniu-sdk
"vlucas/phpdotenv": "^5.4", dotenv
"predis/predis": "^2.0", redis client
"guzzlehttp/guzzle": "^7.5", guzzle client http
"php-amqplib/php-amqplib": "dev-master", rabbitmq
"workerman/gatewayclient": "^3.0", workerman websocket client
"workerman/workerman": "^3.5.23", workerman 基础包 stream fork socket编程 用event扩展性能好
"workerman/gateway-worker": "^3.0.0", workerman websocket
"monolog/monolog": "^2.8", monolog 日志
"nikic/fast-route": "^1.3", restful route 路由
"illuminate/support": "^8.83" laravel collect carbon
doctrine/instantiator 实例化对象不走 构造
"inhere/php-validate": "^2.8", inhere的验证器
"php-di/php-di": "^6.4", 容器 依赖注入 底层反射
"guanhui07/facade": "^1.0" 门面 底层魔术方法__callStatic
"workerman/crontab": "^1.0" crontab 秒级定时任务 ,timer 用event扩展性能好
"doctrine/migrations": "^3.5" 数据库文件迁移
"doctrine/event-manager": "^1.1", 事件 监听 观察者模式 解耦,比如事件投递 任务消费
"middlewares/utils": "^3.3", 中间件 解耦 比如auth cors rate_limit
"inhere/console": "^4.0", console 命令应用
"fzaninotto/faker": "^1.5", fake 数据
"nesbot/carbon": "^2.64" carbon
"opis/closure": "^3.6", 序列化闭包 https://opis.io/closure/3.x/serialize.html
"symfony/finder": "^6.2",
"symfony/console": "^5.1", 命令行应用
"symfony/http-kernel": "^6.2", request response
"intervention/image": "^2.7", 图片处理 水印 缩略图
"gregwar/captcha": "^1.1", 验证码
"elasticsearch/elasticsearch": "7.16", es
```## demo
```
./app/TestController.php
```## test
```
composer test
```## [更多文档](https://github.com/guanhui07/dcr/tree/master/doc)
## 我的其他包:
https://github.com/guanhui07/dcr 借鉴Laravel实现的 PHP Framework ,FPM模式、websocket使用的workerman、支持容器、PHP8特性attributes实现了路由注解、中间件注解、Laravel Orm等特性https://github.com/guanhui07/redis Swoole模式下 Redis连接池
https://github.com/guanhui07/facade facade、门面 fpm模式下可使用
https://github.com/guanhui07/dcr-swoole-crontab 基于swoole实现的crontab秒级定时任务
https://github.com/guanhui07/database 基于 illuminate/database 做的连接池用于适配Swoole的协程环境
https://github.com/guanhui07/dcr-swoole 高性能PHP Framework ,Cli模式,基于Swoole实现,常驻内存,协程框架,支持容器、切面、PHP8特性attributes实现了路由注解、中间件注解、支持Laravel Orm等特性
https://github.com/guanhui07/open-ai chatgpt sdk
https://github.com/guanhui07/timer php定时器,参考了workerman源码 实现一个单进程(守护进程)的定时器。
https://github.com/guanhui07/open-ai open-ai chatgpt调用
https://github.com/guanhui07/geohash 附近的人 geohash