Skip to content

Commit aa25407

Browse files
committed
新的架构
1 parent 54ebf4a commit aa25407

File tree

15 files changed

+433
-1252
lines changed

15 files changed

+433
-1252
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
# framework
2-
framework
1+
# PHP-Sword
2+
3+
> 基于EasySwoole的PHP常驻内存开发框架
4+
5+
## 主要特性
6+
7+
* 采用`PHP7`强类型(严格模式)
8+
* 支持更多的`PSR`规范
9+
* 基于Swoole常驻内存
10+
* 协程TCP、UDP、WEB_SOCKET 服务端
11+
12+
## 安装
13+
14+
~~~
15+
composer require php-sword/storage
16+
~~~
17+
18+
19+
## 参与开发
20+
21+
> 直接提交PR或者Issue即可
22+
23+
## 版权信息
24+
25+
本项目遵循Apache2.0 开源协议发布,并提供免费使用。
26+
27+
本项目包含的第三方源码和二进制文件之版权信息另行标注。
28+
29+
更多细节参阅 [LICENSE.txt](LICENSE.txt)

composer.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"name": "php-sword/framework",
3-
"keywords": [
4-
"php",
5-
"swoole",
6-
"sword"
7-
],
3+
"type": "library",
4+
"keywords": ["php", "swoole", "easyswoole", "sword", "storage"],
5+
"homepage" : "https://github.com/php-sword/framework",
86
"license": "Apache-2.0",
97
"authors": [
108
{
@@ -15,17 +13,15 @@
1513
"description": "The phpSword Framework.",
1614
"require": {
1715
"php": "^7.2",
18-
"ext-pdo": "*",
19-
"ext-redis": "*",
2016
"ext-json": "*",
21-
"ext-mbstring": "*"
17+
"easyswoole/easyswoole": "^3.4"
2218
},
2319
"require-dev": {
2420
},
2521
"autoload": {
2622
"files": [],
2723
"psr-4": {
28-
"sword\\": "src/sword/"
24+
"Sword\\": "src/"
2925
}
3026
}
3127
}

src/Command/App.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
4+
namespace Sword\Command;
5+
6+
7+
use EasySwoole\Command\AbstractInterface\CommandInterface;
8+
use EasySwoole\Command\CommandManager;
9+
10+
class App implements CommandInterface
11+
{
12+
public function commandName(): string
13+
{
14+
return 'app';
15+
}
16+
17+
public function desc(): string
18+
{
19+
return '用户自定义';
20+
}
21+
22+
public function exec(): string
23+
{
24+
$manager = CommandManager::getInstance();
25+
/** 获取原始未变化的argv */
26+
$manager->getOriginArgv();
27+
// var_dump($manager->getOriginArgv());
28+
29+
/**
30+
* 经过处理的数据
31+
* 比如 1 2 3 a=1 aa=123
32+
* 处理之后就变成[1, 2, 3, 'a' => 1, 'aa' => 123]
33+
*/
34+
$manager->getArgs();
35+
36+
/**
37+
* 获取选项
38+
* 比如 --config=dev -d
39+
* 处理之后就是['config' => 'dev', 'd' => true]
40+
*/
41+
$manager->getOpts();
42+
43+
/**
44+
* 根据下标或者键来获取值
45+
*/
46+
$manager->getArg('a');
47+
// var_dump($manager->getArg('a'));
48+
49+
/**
50+
* 根据键来获取选项
51+
*/
52+
$manager->getOpt('config');
53+
54+
/**
55+
* 检测在args中是否存在该下标或者键
56+
*/
57+
$manager->issetArg(1);
58+
59+
/**
60+
* 检测在opts中是否存在该键
61+
*/
62+
$manager->issetOpt('test');
63+
64+
return '自定义命令行执行方法';
65+
}
66+
67+
public function help(\EasySwoole\Command\AbstractInterface\CommandHelpInterface $commandHelp): \EasySwoole\Command\AbstractInterface\CommandHelpInterface
68+
{
69+
$commandHelp->addAction('test','测试方法');
70+
$commandHelp->addActionOpt('-no','不输出详细信息');
71+
return $commandHelp;
72+
}
73+
}

src/Command/Help.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Sword\Command;
4+
5+
use EasySwoole\Command\AbstractInterface\CommandInterface;
6+
use EasySwoole\Command\CommandManager;
7+
8+
class Help implements CommandInterface
9+
{
10+
public function commandName(): string
11+
{
12+
return 'help';
13+
}
14+
15+
public function desc(): string
16+
{
17+
return 'Display this help message';
18+
}
19+
20+
public function exec(): string
21+
{
22+
23+
// $manager = CommandManager::getInstance();
24+
25+
26+
return '帮助消息';
27+
}
28+
29+
public function help(\EasySwoole\Command\AbstractInterface\CommandHelpInterface $commandHelp): \EasySwoole\Command\AbstractInterface\CommandHelpInterface
30+
{
31+
// $commandHelp->addAction('test','测试方法');
32+
// $commandHelp->addActionOpt('-no','不输出详细信息');
33+
return $commandHelp;
34+
}
35+
}

src/Command/Nginx.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
4+
namespace Sword\Command;
5+
6+
7+
use EasySwoole\Command\AbstractInterface\CommandInterface;
8+
use EasySwoole\Command\CommandManager;
9+
10+
class Nginx implements CommandInterface
11+
{
12+
public function commandName(): string
13+
{
14+
return 'app';
15+
}
16+
17+
public function desc(): string
18+
{
19+
return '用户自定义';
20+
}
21+
22+
public function exec(): string
23+
{
24+
$manager = CommandManager::getInstance();
25+
/** 获取原始未变化的argv */
26+
$manager->getOriginArgv();
27+
// var_dump($manager->getOriginArgv());
28+
29+
/**
30+
* 经过处理的数据
31+
* 比如 1 2 3 a=1 aa=123
32+
* 处理之后就变成[1, 2, 3, 'a' => 1, 'aa' => 123]
33+
*/
34+
$manager->getArgs();
35+
36+
/**
37+
* 获取选项
38+
* 比如 --config=dev -d
39+
* 处理之后就是['config' => 'dev', 'd' => true]
40+
*/
41+
$manager->getOpts();
42+
43+
/**
44+
* 根据下标或者键来获取值
45+
*/
46+
$manager->getArg('a');
47+
// var_dump($manager->getArg('a'));
48+
49+
/**
50+
* 根据键来获取选项
51+
*/
52+
$manager->getOpt('config');
53+
54+
/**
55+
* 检测在args中是否存在该下标或者键
56+
*/
57+
$manager->issetArg(1);
58+
59+
/**
60+
* 检测在opts中是否存在该键
61+
*/
62+
$manager->issetOpt('test');
63+
64+
return '自定义命令行执行方法';
65+
}
66+
67+
public function help(\EasySwoole\Command\AbstractInterface\CommandHelpInterface $commandHelp): \EasySwoole\Command\AbstractInterface\CommandHelpInterface
68+
{
69+
$commandHelp->addAction('test','测试方法');
70+
$commandHelp->addActionOpt('-no','不输出详细信息');
71+
return $commandHelp;
72+
}
73+
}

src/Db.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* This file is part of Sword.
4+
* @link http://sword.kyour.cn
5+
* @document http://sword.kyour.cn/doc
6+
* @contact kyour@vip.qq.com
7+
* @license http://github.com/php-sword/sword/blob/master/LICENSE
8+
*/
9+
namespace Sword;
10+
11+
use EasySwoole\Mysqli\QueryBuilder;
12+
use EasySwoole\ORM\DbManager;
13+
14+
/**
15+
* Class Db
16+
* 基于查询构造器的封装,以支持类似ThinkPHP的查询构造器
17+
* @package Sword
18+
*/
19+
class Db extends QueryBuilder
20+
{
21+
22+
private $tableName;
23+
24+
public static function new(string $table = ''): Db
25+
{
26+
return (new static())->table($table);
27+
}
28+
29+
public function table(string $table): Db
30+
{
31+
$this->tableName = $table;
32+
return $this;
33+
}
34+
35+
//使where支持数组
36+
public function where($whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND'): Db
37+
{
38+
39+
if(is_array($whereProp)){
40+
foreach ($whereProp as $v) {
41+
parent::where($v[0], $v[1], $v[2]?? '=', $v[3]?? 'AND');
42+
}
43+
}else{
44+
parent::where($whereProp, $whereValue, $operator, $cond);
45+
}
46+
return $this;
47+
}
48+
49+
public function getSql($action = 'find') :string
50+
{
51+
52+
$this->getOne($this->tableName);
53+
return $this->getLastPrepareQuery();
54+
}
55+
56+
public function find(): ?array
57+
{
58+
$this->getOne($this->tableName);
59+
$data = DbManager::getInstance()->query($this, true, 'default');
60+
return $data->getResultOne();
61+
}
62+
63+
public function findAll()
64+
{
65+
$this->get($this->tableName);
66+
$data = DbManager::getInstance()->query($this, true, 'default');
67+
return $data->getResult();
68+
}
69+
70+
public function updateData(...$data)
71+
{
72+
parent::update($this->tableName, ...$data);
73+
$data = DbManager::getInstance()->query($this, true, 'default');
74+
return $data->getResult();
75+
}
76+
77+
public function insertData(...$data)
78+
{
79+
parent::insert($this->tableName, ...$data);
80+
$data = DbManager::getInstance()->query($this, true, 'default');
81+
return $data->getLastInsertId();
82+
}
83+
84+
}

src/SwordEvent.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* This file is part of Sword.
4+
* @link http://sword.kyour.cn
5+
* @document http://sword.kyour.cn/doc
6+
* @contact kyour@vip.qq.com
7+
* @license http://github.com/php-sword/sword/blob/master/LICENSE
8+
*/
9+
10+
namespace Sword;
11+
12+
use EasySwoole\Command\CommandManager;
13+
14+
class SwordEvent
15+
{
16+
/**
17+
* EasySwoole框架的 bootstrap 事件
18+
* 发生在框架初始化之前
19+
*/
20+
public static function bootstrap()
21+
{
22+
// 加载助手函数
23+
require_once __DIR__."/helper.php";
24+
25+
// 时区设置
26+
date_default_timezone_set(config('app.timezone') ?: 'Asia/Shanghai');
27+
28+
// 添加命令行
29+
CommandManager::getInstance()->addCommand(new \Sword\Command\Help());
30+
31+
}
32+
33+
public static function initialize()
34+
{
35+
36+
}
37+
38+
public static function mainServerCreate()
39+
{
40+
41+
}
42+
43+
}

0 commit comments

Comments
 (0)