spatie/laravel-blade-comments
Composer 安装命令:
composer require spatie/laravel-blade-comments
包简介
Add debug comments to your rendered output
README 文档
README
When looking at the HTML of a rendered page, it might not be obvious to you anymore which Blade view is responsible for which HTML. This package will add HTML before and after each rendered view, so you immediately know to which Blade view / component to go to change the output.
When you inspect a part of the page using your favourite browser's dev tools, you'll immediately see which Blade view rendered that particular piece of content. Here's a demo where we inspected the breadcrumbs on our own company site. It is immediately clear that the breadcrumbs are rendered by the front.pages.docs.partials.breadcrumbs Blade view.
At the top of the HTML document, we'll also add some extra information about the topmost Blade view and the request.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require spatie/laravel-blade-comments --dev
You can optionally publish the config file with:
php artisan vendor:publish --tag="blade-comments-config"
This is the content of the published config file:
return [ 'enable' => env('APP_DEBUG'), /** * Add a comment at the beginning and end of every blade * containing the relative path to the blade file. */ 'blade_paths' => true, /* * These classes provide regex for adding comments for * various Blade directives. */ 'blade_commenters' => [ Spatie\BladeComments\Commenters\BladeCommenters\BladeComponentCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\ExtendsCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\IncludeCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\LivewireComponentCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\LivewireDirectiveCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\SectionCommenter::class, ], /* * These classes will add comments at the top of the response. */ 'request_commenters' => [ Spatie\BladeComments\Commenters\RequestCommenters\ViewCommenter::class, Spatie\BladeComments\Commenters\RequestCommenters\RouteCommenter::class, ], /* * This middleware will add extra information about the request * to the start of a rendered HTML page. */ 'middleware' => [ Spatie\BladeComments\Http\Middleware\AddRequestComments::class, ], /* * This class is responsible for calling the registered Blade commenters. * In most cases, you don't need to modify this class. */ 'precompiler' => Spatie\BladeComments\BladeCommentsPrecompiler::class, 'excludes' => [ /** * Add includes you don't want to be affected by the package here. * For example: * 'styles.theme', * 'partials.sidebar', */ 'includes' => [ ], /** * Add sections you don't want to be affected by the package here. * These sections will not have HTML comments added around @yield directives * For example: * 'header', * 'message', */ 'sections' => [ ], ], ];
Usage
After the package is installed, you'll immediately see that HTML comments are injected at the start and end of every Blade view.
Excluding views
Sometimes you might not want to have an HTML comment being wrapped around an include. For example when you use a partial to add some CSS to a page.
In these cases you can add views to the excludes.includes array in the config file.
Excluding sections
Sometimes you might not want HTML comments wrapping around @yield directives. For example when they're used within HTML attributes or meta tags.
In these cases you can add sections to the excludes.sections array in the config file.
Using your own Blade Commenters
You can easily extend the package to add more comments. In the blade_commenters key of the blade_commenters config file, you can add your own BladeCommenter. A BladeCommenter is any class that implements the following interface:
namespace Spatie\BladeComments\Commenters\BladeCommenters; interface BladeCommenter { /* * Should return a regex pattern that will be used * in preg_replace. */ public function pattern(): string; /* * Should return a replacement string that will be * used in preg_replace. */ public function replacement(): string; }
Take a look at the BladeCommenters that ship with the package for an example.
Using your own request commenters
The package adds useful information about the request at the top of the HTML page. This is done by the so called request commenters . You'll find the default request commenters in the request_commenters key of the blade-comments config file.
You can add your own request commenters there. A RequestCommentor is any class that implements the following interface:
namespace Spatie\BladeComments\Commenters\RequestCommenters; use Illuminate\Http\Request; use Symfony\Component\HttpFoundation\Response; interface RequestCommenter { public function comment(Request $request, Response $response): ?string; }
If the comment function returns a string, it will be injected at the top of the HTML document. Take a look at the request commenters that ship with the package for an example.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
spatie/laravel-blade-comments 适用场景与选型建议
spatie/laravel-blade-comments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 335.17k 次下载、GitHub Stars 达 179, 最近一次更新时间为 2023 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「view」 「comments」 「laravel」 「blade」 「spatie」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spatie/laravel-blade-comments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spatie/laravel-blade-comments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spatie/laravel-blade-comments 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Debug your SimpleBus EventBus and CommandBus
nice output for debug functions for PHP 5.3
Twig extension for Timber which outputs HTML comments before and after the `include` tag
Laravel comment system
Comments system for your Laravel application. Features: can be used to comment on any model, HTML filter customization (HTMLPurifier), API, comment rating, replies, events, auth rules ...
统计信息
- 总下载量: 335.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 179
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-29

