QueryPHP v1-rc.3 发布,更新到 PHP -7.4

2019-12-30 11:23:39 +08:00
 doyouhaobaby

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, 让您的业务撑起更多的用户服务。

更新日志

RoadMap

安装

composer create-project hunzhiwange/queryphp myapp dev-master
php leevel server &lt;Visite http://127.0.0.1:9527/&gt;`</pre>
</div>

![]( https://oscimg.oschina.net/oscnet/2e8f243dcb9231039b5b0737bf30bb32983.jpg)

&nbsp;

运行基于 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>`&lt;?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>`&lt;?php

declare(strict_types=1);

namespace Leevel\Router\Provider;

...

/**
 * router 服务提供者.
 */
class Register extends Provider
{
    /**
     * 注册 router 服务.
     */
    protected function router(): void
    {
        $this-&gt;container
            -&gt;singleton(
                'router',
                fn (IContainer $container): Router =&gt; new Router($container),
            );
    }
`</pre>
</div>

&nbsp;

## **强化的实体生成**

系统支持两种实体展示,功能一致,可以满足不同的方式,支持局部更新 `--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>`&lt;?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' =&gt; [
            self::READONLY =&gt; true,
        ],
        'name' =&gt; [
        ],
        'num' =&gt; [
        ],
        'password' =&gt; [
            self::SHOW_PROP_BLACK =&gt; true,
        ],
        'email' =&gt; [
        ],
        'mobile' =&gt; [
        ],
        'status' =&gt; [
        ],
        'create_at' =&gt; [
        ],
        'update_at' =&gt; [
            self::SHOW_PROP_BLACK =&gt; true,
        ],
        'delete_at' =&gt; [
            self::SHOW_PROP_BLACK =&gt; true,
        ],
        'create_account' =&gt; [
            self::SHOW_PROP_BLACK =&gt; true,
        ],
        'update_account' =&gt; [
            self::SHOW_PROP_BLACK =&gt; true,
        ],
        'role'      =&gt; [
            self::MANY_MANY              =&gt; Role::class,
            self::MIDDLE_ENTITY          =&gt; UserRole::class,
            self::SOURCE_KEY             =&gt; 'id',
            self::TARGET_KEY             =&gt; 'id',
            self::MIDDLE_SOURCE_KEY      =&gt; 'user_id',
            self::MIDDLE_TARGET_KEY      =&gt; 'role_id',
            self::RELATION_SCOPE         =&gt; 'role',
        ],
    ];

    /**
     * Soft delete column.
     *
     * @var string
     */
    const DELETE_AT = 'delete_at';

    /**
     * 状态值.
     *
     * @var array
     */
    const STATUS_ENUM = [
        'disable' =&gt; [0, '禁用'],
        'enable'  =&gt; [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-&gt;data[$this-&gt;realProp($prop)] = $value;

        return $this;
    }

    /**
     * Getter.
     *
     * @return mixed
     */
    public function getter(string $prop)
    {
        return $this-&gt;data[$this-&gt;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-&gt;setColumns(['id', 'name']);
    }
}`</pre>
</div>

### php leevel make:entity user --subdir=user --prop

<div>
<pre>`&lt;?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' =&gt; [
            self::READONLY =&gt; true,
        ],
        'name' =&gt; [
        ],
        'num' =&gt; [
        ],
        'password' =&gt; [
        ],
        'email' =&gt; [
        ],
        'mobile' =&gt; [
        ],
        'status' =&gt; [
        ],
        'create_at' =&gt; [
        ],
        'update_at' =&gt; [
            self::SHOW_PROP_BLACK =&gt; true,
        ],
        'delete_at' =&gt; [
            self::SHOW_PROP_BLACK =&gt; true,
        ],
        'create_account' =&gt; [
            self::SHOW_PROP_BLACK =&gt; true,
        ],
        'update_account' =&gt; [
            self::SHOW_PROP_BLACK =&gt; 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-&gt;{'_'.$this-&gt;realProp($prop)} = $value;

        return $this;
    }

    /**
     * Getter.
     *
     * @return mixed
     */
    public function getter(string $prop)
    {
        return $this-&gt;{'_'.$this-&gt;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;
    }
}
4603 次点击
所在节点    PHP
6 条回复
zuokanyunqishi
2019-12-30 13:34:08 +08:00
PHPer 前来支持
july1115
2019-12-30 13:36:27 +08:00
支持一下
ben1024
2019-12-30 20:09:47 +08:00
有采用 preload 吗?
doyouhaobaby
2019-12-31 10:40:21 +08:00
@ben1024 preload php-7.4 自带的,暂时没有放一个 preload 文件,计划测试一下
CodeCodeStudy
2020-01-17 10:48:03 +08:00
Zephir 版本的有更新吗?
doyouhaobaby
2020-01-17 21:53:28 +08:00
@CodeCodeStudy 暂时不更新了,没得精力更新了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/633494

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX