V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
doyouhaobaby
V2EX  ›  PHP

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

  •  1
     
  •   doyouhaobaby · 2019-12-30 11:23:39 +08:00 · 4570 次点击
    这是一个创建于 1550 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    更新日志

    • [ framework ] 使用 PHP 7.4 的新语法重构代码,主要是整个框架和应用的类属性类型支持。
    • [ framework ] 强化了 php leevel make:entity 功能,能实现局部自动更新表结构,支持两种 getter setter。
    • [ framework ] 修复了实体 Entity 在模拟 replace 场景中不存在主键自动忽略并返回重构
    • [ framework ] 改进多语言文档生成的 uses`` 样式以及删除 Doc::getClassBody 多余的 uses
    • [ framework ] tableColumns 返回更多字段信息,以及加入表的注释,目前用于生成实体的文件名字
    • [ framework ] composer 加入一个常用 scripts,比如 composer migrate,composer test
    • [ framework ] 配置 php_cs no_superfluous_phpdoc_tags 清理掉系统无用的注释,删除掉文件头部的 author version since 等注释
    • [ framework ] 分页第一页从 1 开始,小于 1 将抛出异常统一规范
    • [ framework ] 简化所有验证器规则 Leevel\Validate\Helper\validate_accepted 为 Leevel\Validate\Helper\accepted
    • [ framework ] 修复部分助手函数的 bug,并精简 api 命名,Leevel\Session\Helper|session_set 改为 Leevel\Session\Helper|set
    • [ framework ] 增加部分 HTTP 组件文档
    • [ framework ] 增加小部分 Swoole 文档
    • [ framework ] 新增 Option 配文档
    • [ framework ] 新增 Cache 缓文档
    • [ framework ] 新增 Session 文档
    • [ framework ] 新增 Page 分页文档
    • [ framework ] 新增 Log 日志文档
    • [ framework ] 新增 Seccode 验证码文档
    • [ application ] php 7.4 类型属性支持
    • [ application ] 精简所有注释,删除所有 author version 等信息
    • [ application ] 重新更新到全新的实体 entity
    • [ application ] composer 加入一个常用 scripts,比如 composer migrate,composer test

    RoadMap

    • [ framework ] rc.1-6 是整个框架发布 GA 版最后几个版本。
    • [ framework ] RC 版本只修复 BUG、单元测试 和文档完善,不排除可能有一些必要的功能微调。
    • [ framework ] QueryPHP v1.0.0 正式版本计划是在 2019.12 或者 2020.01 发布。

    安装

    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;
        }
    }
    
    第 1 条附言  ·  2019-12-30 13:47:52 +08:00

    排版有点乱,OSChina 新闻

    连接

    6 条回复    2020-01-17 21:53:28 +08:00
    zuokanyunqishi
        1
    zuokanyunqishi  
       2019-12-30 13:34:08 +08:00 via Android   ❤️ 1
    PHPer 前来支持
    july1115
        2
    july1115  
       2019-12-30 13:36:27 +08:00   ❤️ 1
    支持一下
    ben1024
        3
    ben1024  
       2019-12-30 20:09:47 +08:00
    有采用 preload 吗?
    doyouhaobaby
        4
    doyouhaobaby  
    OP
       2019-12-31 10:40:21 +08:00
    @ben1024 preload php-7.4 自带的,暂时没有放一个 preload 文件,计划测试一下
    CodeCodeStudy
        5
    CodeCodeStudy  
       2020-01-17 10:48:03 +08:00   ❤️ 1
    Zephir 版本的有更新吗?
    doyouhaobaby
        6
    doyouhaobaby  
    OP
       2020-01-17 21:53:28 +08:00
    @CodeCodeStudy 暂时不更新了,没得精力更新了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5295 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:31 · PVG 17:31 · LAX 02:31 · JFK 05:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.