yogcloud/framework

此包的最新版本(1.20.0)没有可用的许可信息。

YogCloud 快速框架

1.20.0 2022-10-03 08:02 UTC

This package is auto-updated.

Last update: 2024-09-22 07:13:13 UTC


README

中文

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

基于 Hyperf 框架的组件,具有快速安装的特点

composer require yogcloud/framework

功能

提供 Controller Request Model Service Interface 完整的构建命令集

$ php bin/hyperf
 fs
  fs:controller        Generate controller, Generated by default in app/Controller
  fs:model             Generate Model, default generate app/Model, Automatic generated Service,Interface
  fs:request           Generate request, Generated by default in app/Request
  fs:service           Generate service, Generated by default in app/Service
  fs:serviceInterface  Generate service interface, Generated by default in app/Service
server
    server:restart       Restart hyperf servers.
    server:start         Start hyperf servers.
    server:stop          Stop hyperf servers.

一键代码生成,快速开发

php bin/hyperf.php fs:model test

Model App\Model\Test was created.
success:[/demo/app/Rpc/TestServiceInterface.php]
success:[/demo/app/Service/TestService.php]

生成代码

    /**
     * Query single entry - by ID.
     * @param int $id ID
     * @param array|string[] $columns Query field
     * @return array
     */
    public function getOneById(int $id, array $columns = ['*']): array;

    /**
     * Query single - according to the where condition.
     * @param array $where
     * @param array|string[] $columns
     * @param array Optional ['orderByRaw'=> 'id asc', 'with' = []]
     * @return array
     */
    public function findByWhere(array $where, array $columns=['*'], array $options = []): array;

    /**
     * Query multiple - by ID.
     * @param array $ids ID
     * @param array|string[] $columns
     * @return array
     */
    public function getAllById(array $ids, array $columns = ['*']): array;

    /**
     * Query multiple items according to where criteria.
     * @param array $where
     * @param array $columns
     * @param array  ['orderByRaw'=> 'id asc', 'with' = [], 'selectRaw' => 'count(*) as count']
     * @return array
     */
    public function getManyByWhere(array $where, array $columns = ['*'], array $options = []): array;

    /**
     * Multiple pages.
     * @param array $where
     * @param array|string[] $columns
     * @param array $options  ['orderByRaw'=> 'id asc', 'perPage' => 15, 'page' => null, 'pageName' => 'page']
     * @return array
     */
    public function getPageList(array $where, array $columns = ['*'], array $options = []): array;

    /**
     * Add single.
     * @param array $data
     * @return int
     */
    public function createOne(array $data): int;

    /**
     * Add multiple.
     * @param array $data
     * @return bool
     */
    public function createAll(array $data): bool;

    /**
     * Modify single entry - according to ID.
     * @param int $id id
     * @param array $data
     * @return int
     */
    public function updateOneById(int $id, array $data): int;

    /**
     * Modify multiple - according to ID.
     * @param array $where
     * @param array $data
     * @return int
     */
    public function updateByWhere(array $where, array $data): int;

    /**
     * Delete - Single.
     * @param int $id
     * @return int
     */
    public function deleteOne(int $id): int;

    /**
     * Delete - multiple.
     * @param array $ids
     * @return int
     */
    public function deleteAll(array $ids): int;

    /**
     * Handle native SQL operations.
     * @param mixed $raw
     * @param array $where
     * @return array
     */
    public function rawWhere($raw, array $where = []): array;

    /**
     * Get a single value
     * @param string $column
     * @param array $where
     * @return string
     */
    public function valueWhere(string $column, array $where): string;

多应用开发

生成代码在应用外部

因为最初的设计是为了多插件和多功能模块

对于 Hyperf/Utils/CodeGen 需要读取 composer-psr4 因此

"autoload": {
    "psr-4": {
        "App\\": "src/",
        "Demo\\Plugin\\Test": "plugin/demo/test/src/"
    }
}

更新缓存

composer dump-autoload -o

生成

php bin/hyperf fs:model test --path plugin/demo/test/src

生成的 TestService 可以轻松操作数据,节省大部分开发时间

生成 Service --cache false 可以禁用缓存(默认启用)

请求后生成缓存,更新/删除时删除缓存(默认 TTL 为 9000 秒,不会一直占用资源)

提示

期待您发现更多提示。欢迎提交 PR

  1. 为查询列提供一个别名
'selectRaw' => 'sum(`id`) as sum'
  1. 通过闭包构建 where 子句
[function ($q) {
    $q->where('id', '=', 1)->orWhere('id', '=', 2);
}]

许可协议

Apache License Version 2.0, https://apache.ac.cn/licenses/