定制 bfg/doc 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bfg/doc

Composer 安装命令:

composer require bfg/doc

包简介

Php doc block generator

README 文档

README

A system for describing the behavior of classes where magic methods are used so as not to lose connection with the classes.

What is it for?

Its main purpose is to use it to describe your magic methods or properties that are accumulated in the properties of the class.

Install

composer require bfg/doc

Principle of operation

For a convenient description of properties, I wrote this logic on the attribute system that was added to php 8.

The kernel searches for files in all project folders, except for the following: {base_path}/public, {base_path}/vendor, {base_path}/routes, {base_path}/resources, {base_path}/storage, {base_path}/runtimes, {base_path}/database.

And it ignores all named folders: node_modules, css, js.

Searches for files with the *.php extension and checks for the existence of a class in the file.

To avoid difficulties, it is necessary to create a separate file for each class.

Usage

In total, for generating helpers, I created 2 main attributes:

/**
 * @props string $type Doc var type: "@method" 
 * @props array|string|null $var_type Doc type of var
 * @props string|null $name Doc name of var
 * @props string|null $description Doc description of the var
 */
use Bfg\Doc\Attributes\Doc($type, $var_type, $name|null, $description|null);

The first attribute Bfg\Doc\Attributes\Doc is needed just to designate a property that will extend the capabilities of the class.

/**
 * @props string $name Class namespace for mixin helper
 */
use Bfg\Doc\Attributes\DocClassName($name);

The second attribute Bfg\Doc\Attributes\DocClassName is needed to indicate the name of the class into which these properties will be added.

This can be useful if you are making a package that can extend its properties as needed.

I also added several aliases for the Bfg\Doc\Attributes\Doc attribute:

// To generate method helpers
use Bfg\Doc\Attributes\DocMethods($var_type, $name|null, $description|null);

// To generate property helpers
use Bfg\Doc\Attributes\DocProperties($var_type, $name|null, $description|null);

// To generate method helpers from array
use Bfg\Doc\Attributes\DocMethodsFromArray($var_type, $description|null);

// To generate property helpers from array
use Bfg\Doc\Attributes\DocPropertiesFromArray($var_type, $description|null);

Macro strings:

  • Global:
    • {name} - The name of variable
  • Array:
    • {key} - Key of array
    • {value} - Value of array
  • Variable:
    • {value} - Value of variable
    • {type} - Type of variable
    • {value_construct} - The value class construct props
  • Class name:
    • {class} - The name of class
    • {namespace} - The namespace of class

Example

use Bfg\Doc\Attributes\DocMethodsFromArray;
use Bfg\Doc\Attributes\DocPropertiesFromArray;
use Bfg\Doc\Attributes\DocClassName;

/**
 * Class PropsData
 * 
 * Result:
 * @method PropsData|static test() From inputs property for test method
 * @[type] [var_type]       [name] [description]
 * @property-read PropsData $simple_form
 * @[type]       [var_type] [name]
 *
 * And if you want you can add the "DocClassName" and created this class like mixin
 * @mixin \Bfg\Doc\Attributes\PropDataBlocks
 */
class PropsData
{
    /**
     * @var array|string[]
     */
    #[DocMethodsFromArray(['{value}', 'static'], 'From {name} property for {key} method')]
    static array $inputs = [
        'test' => PropsData::class
    ];

    /**
     * @var array|string[]
     */
    #[DocPropertiesFromArray]
    protected array $forms = [
        'simple_form' => PropsData::class
    ];

    /**
     * @var array|string[]
     */
    #[DocPropertiesFromArray, DocClassName('PropDataBlocks')]
    protected array $blocks = [
        'simple_block' => PropsData::class
    ];
}

Run

To start the generator, just call the artisan command:

php artisan make:docs

or

composer dump-autoload

bfg/doc 适用场景与选型建议

bfg/doc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60.41k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 06 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「doc」 「block」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bfg/doc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bfg/doc 我们能提供哪些服务?
定制开发 / 二次开发

基于 bfg/doc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 60.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 16
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-23