ihor-radchenko/laravel-ide-helper-macros

为Laravel可宏定义类生成phpDoc。

1.0.6 2019-01-17 20:23 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:38:01 UTC


README

建议与Laravel IDE Helper一起使用,它会为您的IDE生成辅助文件,以便能够高亮显示和理解一些Laravel特定的语法。此包可以根据宏定义特质为Laravel类生成phpDocs。

安装

使用以下命令使用composer安装此包

composer require --dev ihor-radchenko/laravel-ide-helper-macros

如果您正在使用Laravel 5.4或更低版本,您必须手动注册IdeHelperMacrosServiceProvider

配置

运行以下命令将配置文件发布到config/ide-helper-macros.php

php artisan vendor:publish --provider="IhorRadchenko\LaravelIdeHelperMacros\IdeHelperMacrosServiceProvider"

为Laravel宏定义类自动生成phpDoc

您需要在某些服务提供者中添加宏或mixin,例如

/**
 * Bootstrap services.
 *
 * @return void
 */
public function boot(): void
{
    /**
     * @param array $data
     *
     * @return \Illuminate\Http\Response
     */
    \Illuminate\Http\Response::macro('addContent', function (array $data) {
        /** @var \Illuminate\Http\Response $this */
        $response = $this;
        $content = json_decode($response->getContent(), true);
        if (is_array($content)) {
            $response->setContent(json_encode(array_merge($content, $data)));
        }

        return $response;
    });
}

然后运行以下命令生成phpDocs IDE辅助文件

php artisan ide-helper:macros

之后,以下代码块将在\Illuminate\Http\Response类中生成

/**
 * Illuminate\Http\Response
 *
 * @method \Illuminate\Http\Response addContent(array $data)
 * @package ide_helper_macros
 */
class Response extends BaseResponse
{