歡迎您光臨本站 註冊首頁

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

←手機掃碼閱讀     admin @ 2019-12-30 , reply:0

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 <Visite http://127.0.0.1:9527/>

 

運行基於 IViewUI 的通用許可權系統


cd /data/codes/queryphp/frontend
npm install
npm run dev

cd /data/codes/queryphp
php leevel server

http://127.0.0.1:9528/#/login

PHP 7.4

類屬性類型支持

早在 PHP-7.4 alpha.1 開始就拉了一個分支編寫 PHP-7.4,所以在這個版本已經全部重構完畢併合並。

https://github.com/hunzhiwange/framework/blob/master/src/Leevel/Router/Router.php


<?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;

    ...
}

短閉包

https://github.com/hunzhiwange/framework/blob/master/src/Leevel/Router/Provider/Register.php

除了短閉包,還有不少協變逆變的應用。


<?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),
            );
    }

 

強化的實體生成

系統支持兩種實體展示,功能一致,可以滿足不同的方式,支持局部更新 `--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


<?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']);
    }
}

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


<?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;
    }
}

 


[admin ]

來源:OsChina
連結:https://www.oschina.net/news/112435/queryphp-1-rc3-released
QueryPHP v1-rc.3 發布,更新到 PHP-7.4已經有242次圍觀

http://coctec.com/news/all/show-post-221944.html