spiral/ide-helper

此包已废弃,不再维护。未建议替代包。

Spiral 框架 IDE 辅助工具

v0.9.6 2017-06-29 11:56 UTC

This package is auto-updated.

Last update: 2024-01-29 03:07:11 UTC


README

Latest Stable Version Total Downloads License Scrutinizer Code Quality Coverage Status

此模块为 Spiral 框架组件(如控制器、请求过滤器、记录、文档等)生成 IDE 帮助文件。

安装

composer require spiral/ide-helper
./spiral register spiral/ide-helper && ./spiral console:reload

使用

./spiral ide-helper

配置和术语

模块通过 config/modules/ide-helper.php 文件进行配置。

配置包含 3 个部分:writerslocatorsscopes

查看配置文件

locators 部分包含模块使用的任何定位器。定位器是一个负责搜索类及其[魔法]成员的类。

writers 部分包含模块使用的任何编写器。编写器负责将定位器收集的内容写入某个目的地。

定位器和编写器都必须由关联数组表示,其中键是定位器或编写器的人名,值是类字符串或 \Spiral\Core\Container\Autowire 实例(可以通过 bind 方法获得)。

scopes 部分也是关联数组,其中键是作用域的人名,值是作用域定义。作用域定义由要执行的定位器和编写器的数量组成,如上配置所示,以了解语法。每个作用域都是独立执行的。

该包包括以下定位器和编写器

  • BindingsLocator — 查找简短绑定(SharedTrait)
  • ContainersLocator — 查找容器及其绑定
  • DocumentsLocator — 查找文档及其字段
  • RecordsLocator — 查找记录及其字段
  • FilePerClassWriter — 将每个类写入其自己的文件
  • SingleFileWriter — 将所有内容写入一个文件

扩展

自定义定位器

要创建自己的定位器,必须实现 \Spiral\IdeHelper\Locators\LocatorInerface

interface LocatorInterface
{
    /**
     * @return ClassDefinition[]
     */
    public function locate(): array;
}

然后将其在配置文件中注册。

自定义编写器

与自定义定位器相同,但使用 \Spiral\IdeHelper\Writers\WriterInterface 接口

interface WriterInterface
{
    /**
     * @param ClassDefinition[] $classes
     */
    public function write(array $classes);
}

FilePerClassWriterSingleFileWriter 使用 \Spiral\IdeHelper\Rendere\RendererInterface 进行内容渲染,因此如果您只想更改文件的外观,可以创建自己的实现。

interface RendererInterface
{
    /**
     * @param ClassDefinition[] $classes
     * @return string
     */
    public function render(array $classes): string;
}