QueryPHP v1.0.0-rc.3 主要用 PHP-7.4 新特性对整个框架进行改造,例外增加多个组件的文档,除此之外对 ORM 实体 Entity 进行了优化。
QueryPHP 1.0.0 正式版快完成了,现在主要是推进文档的编写,少量的优化。
关于 QueryPHP
QueryPHP 是一款现代化的高性能 PHP 渐进式协程框架, 我们还是主要面向传统 PHP-FPM 场景,以工程师用户体验为历史使命,让每一个 PHP 应用都有一个好框架。
百分之百单元测试覆盖直面 Bug,致力于创造高品质的产品 level level leevel,依托 Swoole 协程提升业务性能,此刻未来逐步渐进。 我们的愿景是USE LEEVEL WITH SWOOLE DO BETTER, 让您的业务撑起更多的用户服务。
uses`` 样式以及
删除 Doc::getClassBody 多余的 uses
安装
composer create-project hunzhiwange/queryphp myapp dev-master
php leevel server <Visite http://127.0.0.1:9527/>`</pre>
</div>
![]( https://oscimg.oschina.net/oscnet/2e8f243dcb9231039b5b0737bf30bb32983.jpg)
运行基于 IViewUI 的通用权限系统
<div>
<pre>`cd /data/codes/queryphp/frontend
npm install
npm run dev
cd /data/codes/queryphp
php leevel server
http://127.0.0.1:9528/#/login`</pre>
</div>
![]( https://oscimg.oschina.net/oscnet/11131c6e54ec02e8a55c128dc053dc61b1e.png)
**PHP 7.4 **
**类属性类型支持**
早在 PHP-7.4 alpha.1 开始就拉了一个分支编写 PHP-7.4,所以在这个版本已经全部重构完毕并合并。
[https://github.com/hunzhiwange/framework/blob/master/src/Leevel/Router/Router.php]( https://github.com/hunzhiwange/framework/blob/master/src/Leevel/Router/Router.php)
<div>
<pre>`<?php
declare(strict_types=1);
namespace Leevel\Router;
use Leevel\Di\IContainer;
use Leevel\Http\IRequest;
use Leevel\Http\IResponse;
use Leevel\Http\Response;
use Leevel\Pipeline\Pipeline;
/**
* 路由解析.
*/
class Router implements IRouter
{
/**
* IOC Container.
*
* @var \Leevel\Di\IContainer
*/
protected IContainer $container;
/**
* HTTP 请求
*
* @var \Leevel\Http\IRequest
*/
protected IRequest $request;
/**
* 路由匹配数据.
*
* @var null|array
*/
protected ?array $matchedData = null;
...
}`</pre>
</div>
**短闭包**
[https://github.com/hunzhiwange/framework/blob/master/src/Leevel/Router/Provider/Register.php]( https://github.com/hunzhiwange/framework/blob/master/src/Leevel/Router/Provider/Register.php)
除了短闭包,还有不少协变逆变的应用。
<div>
<pre>`<?php
declare(strict_types=1);
namespace Leevel\Router\Provider;
...
/**
* router 服务提供者.
*/
class Register extends Provider
{
/**
* 注册 router 服务.
*/
protected function router(): void
{
$this->container
->singleton(
'router',
fn (IContainer $container): Router => new Router($container),
);
}
`</pre>
</div>
## **强化的实体生成**
系统支持两种实体展示,功能一致,可以满足不同的方式,支持局部更新 `--refresh`` 和 强制更新 ``--force`。
支持软删除 const DELETE_AT 和 show_prop_black 隐私属性的支持。
**php leevel make:entity user --subdir=user**
[https://github.com/hunzhiwange/queryphp/blob/master/common/Domain/Entity/User/User.php]( https://github.com/hunzhiwange/queryphp/blob/master/common/Domain/Entity/User/User.php)
<div>
<pre>`<?php
declare(strict_types=1);
/*
* This file is part of the your app package.
*
* The PHP Application For Code Poem For You.
* (c) 2018-2099 http://yourdomian.com All rights reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Common\Domain\Entity\User;
use Leevel\Database\Ddd\Entity;
use Leevel\Database\Ddd\Relation\ManyMany;
/**
* 用户.
*/
class User extends Entity
{
/**
* Database table.
*
* @var string
*/
const TABLE = 'user';
/**
* Primary key.
*
* @var string
*/
const ID = 'id';
/**
* Auto increment.
*
* @var string
*/
const AUTO = 'id';
/**
* Entity struct.
*
* - id
* comment: ID type: int(11) unsigned null: false
* key: PRI default: null extra: auto_increment
* - name
* comment: 用户名字 type: varchar(64) null: false
* key: default: extra:
* - num
* comment: 编号 type: varchar(64) null: false
* key: MUL default: extra:
* - password
* comment: 密码 type: varchar(255) null: false
* key: default: extra:
* - email
* comment: Email type: varchar(100) null: false
* key: default: extra:
* - mobile
* comment: 手机 type: char(11) null: false
* key: default: extra:
* - status
* comment: 状态 0=禁用;1=启用; type: tinyint(4) null: false
* key: default: 1 extra:
* - create_at
* comment: 创建时间 type: datetime null: false
* key: default: CURRENT_TIMESTAMP extra:
* - update_at
* comment: 更新时间 type: datetime null: false
* key: default: CURRENT_TIMESTAMP extra: on update CURRENT_TIMESTAMP
* - delete_at
* comment: 删除时间 0=未删除;大于 0=删除时间; type: bigint(20) unsigned null: false
* key: default: 0 extra:
* - create_account
* comment: 创建账号 type: int(11) unsigned null: false
* key: default: 0 extra:
* - update_account
* comment: 更新账号 type: int(11) unsigned null: false
* key: default: 0 extra:
*
* @var array
*/
const STRUCT = [
'id' => [
self::READONLY => true,
],
'name' => [
],
'num' => [
],
'password' => [
self::SHOW_PROP_BLACK => true,
],
'email' => [
],
'mobile' => [
],
'status' => [
],
'create_at' => [
],
'update_at' => [
self::SHOW_PROP_BLACK => true,
],
'delete_at' => [
self::SHOW_PROP_BLACK => true,
],
'create_account' => [
self::SHOW_PROP_BLACK => true,
],
'update_account' => [
self::SHOW_PROP_BLACK => true,
],
'role' => [
self::MANY_MANY => Role::class,
self::MIDDLE_ENTITY => UserRole::class,
self::SOURCE_KEY => 'id',
self::TARGET_KEY => 'id',
self::MIDDLE_SOURCE_KEY => 'user_id',
self::MIDDLE_TARGET_KEY => 'role_id',
self::RELATION_SCOPE => 'role',
],
];
/**
* Soft delete column.
*
* @var string
*/
const DELETE_AT = 'delete_at';
/**
* 状态值.
*
* @var array
*/
const STATUS_ENUM = [
'disable' => [0, '禁用'],
'enable' => [1, '启用'],
];
/**
* Prop data.
*
* @var array
*/
private array $data = [];
/**
* Database connect.
*
* @var mixed
*/
private static $connect;
/**
* Setter.
*
* @param mixed $value
*/
public function setter(string $prop, $value): self
{
$this->data[$this->realProp($prop)] = $value;
return $this;
}
/**
* Getter.
*
* @return mixed
*/
public function getter(string $prop)
{
return $this->data[$this->realProp($prop)] ?? null;
}
/**
* Set database connect.
*
* @param mixed $connect
*/
public static function withConnect($connect): void
{
static::$connect = $connect;
}
/**
* Get database connect.
*/
public static function connect()
{
return static::$connect;
}
/**
* 角色关联查询作用域.
*/
protected function relationScopeRole(ManyMany $relation): void
{
$relation->setColumns(['id', 'name']);
}
}`</pre>
</div>
### php leevel make:entity user --subdir=user --prop
<div>
<pre>`<?php
declare(strict_types=1);
/*
* This file is part of the your app package.
*
* The PHP Application For Code Poem For You.
* (c) 2018-2099 http://yourdomian.com All rights reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Common\Domain\Entity\User;
use Leevel\Database\Ddd\Entity;
/**
* 用户.
*/
class User extends Entity
{
/**
* Database table.
*
* @var string
*/
const TABLE = 'user';
/**
* Primary key.
*
* @var string
*/
const ID = 'id';
/**
* Auto increment.
*
* @var string
*/
const AUTO = 'id';
/**
* Entity struct.
*
* - id
* comment: ID type: int(11) unsigned null: false
* key: PRI default: null extra: auto_increment
* - name
* comment: 用户名字 type: varchar(64) null: false
* key: default: extra:
* - num
* comment: 编号 type: varchar(64) null: false
* key: MUL default: extra:
* - password
* comment: 密码 type: varchar(255) null: false
* key: default: extra:
* - email
* comment: Email type: varchar(100) null: false
* key: default: extra:
* - mobile
* comment: 手机 type: char(11) null: false
* key: default: extra:
* - status
* comment: 状态 0=禁用;1=启用; type: tinyint(4) null: false
* key: default: 1 extra:
* - create_at
* comment: 创建时间 type: datetime null: false
* key: default: CURRENT_TIMESTAMP extra:
* - update_at
* comment: 更新时间 type: datetime null: false
* key: default: CURRENT_TIMESTAMP extra: on update CURRENT_TIMESTAMP
* - delete_at
* comment: 删除时间 0=未删除;大于 0=删除时间; type: bigint(20) unsigned null: false
* key: default: 0 extra:
* - create_account
* comment: 创建账号 type: int(11) unsigned null: false
* key: default: 0 extra:
* - update_account
* comment: 更新账号 type: int(11) unsigned null: false
* key: default: 0 extra:
*
* @var array
*/
const STRUCT = [
'id' => [
self::READONLY => true,
],
'name' => [
],
'num' => [
],
'password' => [
],
'email' => [
],
'mobile' => [
],
'status' => [
],
'create_at' => [
],
'update_at' => [
self::SHOW_PROP_BLACK => true,
],
'delete_at' => [
self::SHOW_PROP_BLACK => true,
],
'create_account' => [
self::SHOW_PROP_BLACK => true,
],
'update_account' => [
self::SHOW_PROP_BLACK => true,
],
];
/**
* Soft delete column.
*
* @var string
*/
const DELETE_AT = 'delete_at';
/**
* ID.
*/
private $_id;
/**
* 用户名字.
*/
private $_name;
/**
* 编号.
*/
private $_num;
/**
* 密码.
*/
private $_password;
/**
* Email.
*/
private $_email;
/**
* 手机.
*/
private $_mobile;
/**
* 状态 0=禁用;1=启用;.
*/
private $_status;
/**
* 创建时间.
*/
private $_createAt;
/**
* 更新时间.
*/
private $_updateAt;
/**
* 删除时间 0=未删除;大于 0=删除时间;.
*/
private $_deleteAt;
/**
* 创建账号.
*/
private $_createAccount;
/**
* 更新账号.
*/
private $_updateAccount;
/**
* Database connect.
*
* @var mixed
*/
private static $connect;
/**
* Setter.
*
* @param mixed $value
*/
public function setter(string $prop, $value): self
{
$this->{'_'.$this->realProp($prop)} = $value;
return $this;
}
/**
* Getter.
*
* @return mixed
*/
public function getter(string $prop)
{
return $this->{'_'.$this->realProp($prop)};
}
/**
* Set database connect.
*
* @param mixed $connect
*/
public static function withConnect($connect): void
{
static::$connect = $connect;
}
/**
* Get database connect.
*/
public static function connect()
{
return static::$connect;
}
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.