├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── blade-comments.php └── src ├── BladeCommentsPrecompiler.php ├── BladeCommentsServiceProvider.php ├── Commenters ├── BladeCommenters │ ├── AnonymousBladeComponentCommenter.php │ ├── BladeCommenter.php │ ├── BladeCommenterWithCallback.php │ ├── BladeComponentCommenter.php │ ├── ExtendsCommenter.php │ ├── IncludeCommenter.php │ ├── IncludeIfCommenter.php │ ├── IncludeUnlessCommenter.php │ ├── IncludeWhenCommenter.php │ ├── LivewireComponentCommenter.php │ ├── LivewireDirectiveCommenter.php │ └── SectionCommenter.php └── RequestCommenters │ ├── RequestCommenter.php │ ├── RouteCommenter.php │ └── ViewCommenter.php └── Http └── Middleware └── AddRequestComments.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-blade-comments` will be documented in this file. 4 | 5 | ## 1.4.0 - 2025-05-09 6 | 7 | ### What's Changed 8 | 9 | * Add config option to exclude sections by @wvdongen in https://github.com/spatie/laravel-blade-comments/pull/37 10 | 11 | ### New Contributors 12 | 13 | * @wvdongen made their first contribution in https://github.com/spatie/laravel-blade-comments/pull/37 14 | 15 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/1.3.1...1.4.0 16 | 17 | ## 1.3.1 - 2025-02-21 18 | 19 | ### What's Changed 20 | 21 | * Bump aglipanci/laravel-pint-action from 2.3.1 to 2.4 by @dependabot in https://github.com/spatie/laravel-blade-comments/pull/26 22 | * Bump dependabot/fetch-metadata from 1.6.0 to 2.1.0 by @dependabot in https://github.com/spatie/laravel-blade-comments/pull/27 23 | * Bump dependabot/fetch-metadata from 2.1.0 to 2.2.0 by @dependabot in https://github.com/spatie/laravel-blade-comments/pull/28 24 | * Bump dependabot/fetch-metadata from 2.2.0 to 2.3.0 by @dependabot in https://github.com/spatie/laravel-blade-comments/pull/30 25 | * Bump aglipanci/laravel-pint-action from 2.4 to 2.5 by @dependabot in https://github.com/spatie/laravel-blade-comments/pull/31 26 | * Laravel 12.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-blade-comments/pull/32 27 | 28 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/1.3.0...1.3.1 29 | 30 | ## 1.3.0 - 2024-03-07 31 | 32 | ### What's Changed 33 | 34 | * Bump stefanzweifel/git-auto-commit-action from 4 to 5 by @dependabot in https://github.com/spatie/laravel-blade-comments/pull/19 35 | * Bump aglipanci/laravel-pint-action from 2.3.0 to 2.3.1 by @dependabot in https://github.com/spatie/laravel-blade-comments/pull/22 36 | * Bump actions/checkout from 3 to 4 by @dependabot in https://github.com/spatie/laravel-blade-comments/pull/16 37 | * Laravel 11.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-blade-comments/pull/24 38 | 39 | ### New Contributors 40 | 41 | * @laravel-shift made their first contribution in https://github.com/spatie/laravel-blade-comments/pull/24 42 | 43 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/1.2.2...1.3.0 44 | 45 | ## 1.2.2 - 2023-10-17 46 | 47 | ### What's Changed 48 | 49 | - fix: includes with data sometimes throw exceptions by @StyleShit in https://github.com/spatie/laravel-blade-comments/pull/20 50 | 51 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/1.2.1...1.2.2 52 | 53 | ## 1.2.1 - 2023-10-09 54 | 55 | ### What's Changed 56 | 57 | - test: fix failing livewire test by @StyleShit in https://github.com/spatie/laravel-blade-comments/pull/18 58 | - fix: conditional includes are not working properly on Windows by @StyleShit in https://github.com/spatie/laravel-blade-comments/pull/17 59 | 60 | ### New Contributors 61 | 62 | - @StyleShit made their first contribution in https://github.com/spatie/laravel-blade-comments/pull/18 63 | 64 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/1.2.0...1.2.1 65 | 66 | ## 1.2.0 - 2023-08-14 67 | 68 | ### What's Changed 69 | 70 | - Use more inclusive terms. by @timvandijck in https://github.com/spatie/laravel-blade-comments/pull/15 71 | 72 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/1.1.0...1.2.0 73 | 74 | ## 1.1.0 - 2023-08-11 75 | 76 | ### What's Changed 77 | 78 | - Minor tweaks by @utsavsomaiya in https://github.com/spatie/laravel-blade-comments/pull/9 79 | - Bump dependabot/fetch-metadata from 1.5.1 to 1.6.0 by @dependabot in https://github.com/spatie/laravel-blade-comments/pull/10 80 | - Feature/blacklist by @timvandijck in https://github.com/spatie/laravel-blade-comments/pull/14 81 | 82 | ### New Contributors 83 | 84 | - @utsavsomaiya made their first contribution in https://github.com/spatie/laravel-blade-comments/pull/9 85 | - @timvandijck made their first contribution in https://github.com/spatie/laravel-blade-comments/pull/14 86 | 87 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/1.0.3...1.1.0 88 | 89 | ## 1.0.3 - 2023-06-19 90 | 91 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/1.0.2...1.0.3 92 | 93 | ## 1.0.2 - 2023-06-16 94 | 95 | ### What's Changed 96 | 97 | - Fixes typo in README.md by @fsamapoor in https://github.com/spatie/laravel-blade-comments/pull/5 98 | - Add Laravel 9 support. 99 | 100 | ### New Contributors 101 | 102 | - @fsamapoor made their first contribution in https://github.com/spatie/laravel-blade-comments/pull/5 103 | 104 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/1.0.1...1.0.2 105 | 106 | ## 1.0.1 - 2023-05-31 107 | 108 | - Fixes issue with @yield directives that have extra params. 109 | 110 | ## 1.0.0 - 2023-05-30 111 | 112 | **Full Changelog**: https://github.com/spatie/laravel-blade-comments/compare/0.0.1...1.0.0 113 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) spatie 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Add debug comments to your rendered output 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-blade-comments.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-blade-comments) 4 | [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-blade-comments/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/spatie/laravel-blade-comments/actions?query=workflow%3Arun-tests+branch%3Amain) 5 | [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-blade-comments/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/spatie/laravel-blade-comments/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) 6 | [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-blade-comments.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-blade-comments) 7 | 8 | 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. 9 | 10 | 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](https://spatie.be). It is immediately clear that the breadcrumbs are rendered by the `front.pages.docs.partials.breadcrumbs` Blade view. 11 | 12 | ![screenshot](https://github.com/spatie/laravel-blade-comments/blob/main/docs/breadcrumbs.jpg) 13 | 14 | At the top of the HTML document, we'll also add some extra information about the topmost Blade view and the request. 15 | 16 | ![screenshot](https://github.com/spatie/laravel-blade-comments/blob/main/docs/page.jpg) 17 | 18 | ## Support us 19 | 20 | [](https://spatie.be/github-ad-click/laravel-blade-comments) 21 | 22 | We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). 23 | 24 | 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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). 25 | 26 | ## Installation 27 | 28 | You can install the package via composer: 29 | 30 | ```bash 31 | composer require spatie/laravel-blade-comments --dev 32 | ``` 33 | 34 | You can optionally publish the config file with: 35 | 36 | ```bash 37 | php artisan vendor:publish --tag="blade-comments-config" 38 | ``` 39 | 40 | This is the content of the published config file: 41 | 42 | ```php 43 | return [ 44 | 'enable' => env('APP_DEBUG'), 45 | 46 | /* 47 | * These classes provide regex for adding comments for 48 | * various Blade directives. 49 | */ 50 | 'blade_commenters' => [ 51 | Spatie\BladeComments\Commenters\BladeCommenters\BladeComponentCommenter::class, 52 | Spatie\BladeComments\Commenters\BladeCommenters\AnonymousBladeComponentCommenter::class, 53 | Spatie\BladeComments\Commenters\BladeCommenters\ExtendsCommenter::class, 54 | Spatie\BladeComments\Commenters\BladeCommenters\IncludeCommenter::class, 55 | Spatie\BladeComments\Commenters\BladeCommenters\IncludeIfCommenter::class, 56 | Spatie\BladeComments\Commenters\BladeCommenters\IncludeWhenCommenter::class, 57 | Spatie\BladeComments\Commenters\BladeCommenters\LivewireComponentCommenter::class, 58 | Spatie\BladeComments\Commenters\BladeCommenters\LivewireDirectiveCommenter::class, 59 | Spatie\BladeComments\Commenters\BladeCommenters\SectionCommenter::class, 60 | ], 61 | 62 | /* 63 | * These classes will add comments at the top of the response. 64 | */ 65 | 'request_commenters' => [ 66 | Spatie\BladeComments\Commenters\RequestCommenters\ViewCommenter::class, 67 | Spatie\BladeComments\Commenters\RequestCommenters\RouteCommenter::class, 68 | ], 69 | 70 | /* 71 | * This middleware will add extra information about the request 72 | * to the start of a rendered HTML page. 73 | */ 74 | 'middleware' => [ 75 | Spatie\BladeComments\Http\Middleware\AddRequestComments::class, 76 | ], 77 | 78 | /* 79 | * This class is responsible for calling the registered Blade commenters. 80 | * In most case, you don't need to modify this class. 81 | */ 82 | 'precompiler' => Spatie\BladeComments\BladeCommentsPrecompiler::class, 83 | 84 | 'excludes' => [ 85 | /** 86 | * Add includes you don't want to be affected by the package here. 87 | * For example: 88 | * 'styles.theme', 89 | * 'partials.sidebar', 90 | */ 91 | 'includes' => [ 92 | 93 | ], 94 | 95 | /** 96 | * Add sections you don't want to be affected by the package here. 97 | * These sections will not have HTML comments added around @yield directives 98 | * For example: 99 | * 'header', 100 | * 'message', 101 | */ 102 | 'sections' => [ 103 | 104 | ], 105 | ] 106 | ]; 107 | ``` 108 | 109 | ## Usage 110 | 111 | After the package is installed, you'll immediately see that HTML comments are injected at the start and end of every Blade view. 112 | 113 | ## Excluding views 114 | 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. 115 | In these cases you can add views to the `excludes.includes` array in the config file. 116 | 117 | ## Excluding sections 118 | Sometimes you might not want HTML comments wrapping around `@yield` directives. For example when they're used within HTML attributes or meta tags. 119 | In these cases you can add sections to the `excludes.sections` array in the config file. 120 | 121 | ### Using your own Blade Commenters 122 | 123 | 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: 124 | 125 | ```php 126 | namespace Spatie\BladeComments\Commenters\BladeCommenters; 127 | 128 | interface BladeCommenter 129 | { 130 | /* 131 | * Should return a regex pattern that will be used 132 | * in preg_replace. 133 | */ 134 | public function pattern(): string; 135 | 136 | /* 137 | * Should return a replacement string that will be 138 | * used in preg_replace. 139 | */ 140 | public function replacement(): string; 141 | } 142 | ``` 143 | 144 | Take a look at the `BladeCommenters` that ship with the package for an example. 145 | 146 | ### Using your own request commenters 147 | 148 | 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. 149 | 150 | You can add your own request commenters there. A `RequestCommentor` is any class that implements the following interface: 151 | 152 | ```php 153 | namespace Spatie\BladeComments\Commenters\RequestCommenters; 154 | 155 | use Illuminate\Http\Request; 156 | use Symfony\Component\HttpFoundation\Response; 157 | 158 | interface RequestCommenter 159 | { 160 | public function comment(Request $request, Response $response): ?string; 161 | } 162 | ``` 163 | 164 | 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. 165 | 166 | ## Testing 167 | 168 | ```bash 169 | composer test 170 | ``` 171 | 172 | ## Changelog 173 | 174 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 175 | 176 | ## Contributing 177 | 178 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 179 | 180 | ## Security Vulnerabilities 181 | 182 | Please review [our security policy](../../security/policy) on how to report security vulnerabilities. 183 | 184 | ## Credits 185 | 186 | - [Tim Van Dijck](https://github.com/timvandijck) 187 | - [Freek Van der Herten](https://github.com/freekmurze) 188 | - [All Contributors](../../contributors) 189 | 190 | ## License 191 | 192 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 193 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spatie/laravel-blade-comments", 3 | "description": "Add debug comments to your rendered output", 4 | "keywords": [ 5 | "spatie", 6 | "laravel", 7 | "laravel-blade-comments", 8 | "debug", 9 | "blade", 10 | "view", 11 | "comments" 12 | ], 13 | "homepage": "https://github.com/spatie/laravel-blade-comments", 14 | "license": "MIT", 15 | "authors": [ 16 | { 17 | "name": "Tim Van Dijck", 18 | "email": "tim@spatie.be", 19 | "role": "Developer" 20 | }, 21 | { 22 | "name": "Freek Van der Herten", 23 | "email": "freek@spatie.be", 24 | "role": "Developer" 25 | } 26 | ], 27 | "require": { 28 | "php": "^8.2", 29 | "illuminate/contracts": "^10|^11.0|^12.0", 30 | "illuminate/view": "^10|^11.0|^12.0", 31 | "spatie/laravel-package-tools": "^1.19" 32 | }, 33 | "require-dev": { 34 | "laravel/pint": "^1.21", 35 | "livewire/livewire": ">=3.5.20", 36 | "nunomaduro/collision": "^7|^8.6.1", 37 | "orchestra/testbench": "^8.5.4|^9.11|^10.0", 38 | "pestphp/pest": "^2.6.1|^3.7.4", 39 | "pestphp/pest-plugin-arch": "^2.1.2|^3.0", 40 | "pestphp/pest-plugin-laravel": "^2.0|^3.1", 41 | "spatie/laravel-ray": "^1.39.1", 42 | "spatie/pest-plugin-snapshots": "^2.2.0" 43 | }, 44 | "autoload": { 45 | "psr-4": { 46 | "Spatie\\BladeComments\\": "src/", 47 | "Spatie\\BladeComments\\Database\\Factories\\": "database/factories/" 48 | } 49 | }, 50 | "autoload-dev": { 51 | "psr-4": { 52 | "Spatie\\BladeComments\\Tests\\": "tests/" 53 | } 54 | }, 55 | "scripts": { 56 | "post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", 57 | "analyse": "vendor/bin/phpstan analyse", 58 | "test": "vendor/bin/pest", 59 | "test-coverage": "vendor/bin/pest --coverage", 60 | "format": "vendor/bin/pint" 61 | }, 62 | "config": { 63 | "sort-packages": true, 64 | "allow-plugins": { 65 | "pestphp/pest-plugin": true, 66 | "phpstan/extension-installer": true 67 | } 68 | }, 69 | "extra": { 70 | "laravel": { 71 | "providers": [ 72 | "Spatie\\BladeComments\\BladeCommentsServiceProvider" 73 | ] 74 | } 75 | }, 76 | "minimum-stability": "dev", 77 | "prefer-stable": true 78 | } 79 | -------------------------------------------------------------------------------- /config/blade-comments.php: -------------------------------------------------------------------------------- 1 | env('APP_DEBUG'), 5 | 6 | /* 7 | * These classes provide regex for adding comments for 8 | * various Blade directives. 9 | */ 10 | 'blade_commenters' => [ 11 | Spatie\BladeComments\Commenters\BladeCommenters\BladeComponentCommenter::class, 12 | Spatie\BladeComments\Commenters\BladeCommenters\AnonymousBladeComponentCommenter::class, 13 | Spatie\BladeComments\Commenters\BladeCommenters\ExtendsCommenter::class, 14 | Spatie\BladeComments\Commenters\BladeCommenters\IncludeCommenter::class, 15 | Spatie\BladeComments\Commenters\BladeCommenters\IncludeIfCommenter::class, 16 | Spatie\BladeComments\Commenters\BladeCommenters\IncludeWhenCommenter::class, 17 | Spatie\BladeComments\Commenters\BladeCommenters\IncludeUnlessCommenter::class, 18 | Spatie\BladeComments\Commenters\BladeCommenters\LivewireComponentCommenter::class, 19 | Spatie\BladeComments\Commenters\BladeCommenters\LivewireDirectiveCommenter::class, 20 | Spatie\BladeComments\Commenters\BladeCommenters\SectionCommenter::class, 21 | ], 22 | 23 | /* 24 | * These classes will add comments at the top of the response. 25 | */ 26 | 'request_commenters' => [ 27 | Spatie\BladeComments\Commenters\RequestCommenters\ViewCommenter::class, 28 | Spatie\BladeComments\Commenters\RequestCommenters\RouteCommenter::class, 29 | ], 30 | 31 | /* 32 | * This middleware will add extra information about the request 33 | * to the start of a rendered HTML page. 34 | */ 35 | 'middleware' => [ 36 | Spatie\BladeComments\Http\Middleware\AddRequestComments::class, 37 | ], 38 | 39 | /* 40 | * This class is responsible for calling the registered Blade commenters. 41 | * In most cases, you don't need to modify this class. 42 | */ 43 | 'precompiler' => Spatie\BladeComments\BladeCommentsPrecompiler::class, 44 | 45 | 'excludes' => [ 46 | /** 47 | * Add includes you don't want to be affected by the package here. 48 | * For example: 49 | * 'styles.theme', 50 | * 'partials.sidebar', 51 | */ 52 | 'includes' => [ 53 | 54 | ], 55 | 56 | /** 57 | * Add sections you don't want to be affected by the package here. 58 | * These sections will not have HTML comments added around @yield directives 59 | * For example: 60 | * 'header', 61 | * 'message', 62 | */ 63 | 'sections' => [ 64 | 65 | ], 66 | ], 67 | ]; 68 | -------------------------------------------------------------------------------- /src/BladeCommentsPrecompiler.php: -------------------------------------------------------------------------------- 1 | pattern(), 16 | fn (array $matches) => $commenter->replacementCallback($matches), 17 | $bladeContent, 18 | ); 19 | 20 | continue; 21 | } 22 | 23 | $bladeContent = preg_replace( 24 | $commenter->pattern(), 25 | $commenter->replacement(), 26 | $bladeContent, 27 | ); 28 | } 29 | 30 | return $bladeContent; 31 | } 32 | 33 | /** 34 | * @return array 35 | */ 36 | protected static function commenters(): array 37 | { 38 | return collect(config('blade-comments.blade_commenters')) 39 | ->map(fn (string $class) => app($class)) 40 | ->toArray(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/BladeCommentsServiceProvider.php: -------------------------------------------------------------------------------- 1 | name('laravel-blade-comments') 16 | ->hasConfigFile(); 17 | } 18 | 19 | public function packageBooted(): void 20 | { 21 | if (! config('blade-comments.enable')) { 22 | return; 23 | } 24 | 25 | $this 26 | ->registerMiddleware() 27 | ->registerPrecompiler(); 28 | } 29 | 30 | protected function registerPrecompiler(): self 31 | { 32 | $precompilerClass = config('blade-comments.precompiler'); 33 | 34 | Blade::precompiler(fn (string $string) => $precompilerClass::execute($string)); 35 | 36 | return $this; 37 | } 38 | 39 | protected function registerMiddleware(): self 40 | { 41 | $kernel = resolve(Kernel::class); 42 | 43 | collect(config('blade-comments.middleware')) 44 | ->each(function ($middleware) use ($kernel) { 45 | $kernel->appendMiddlewareToGroup('web', $middleware); 46 | }); 47 | 48 | return $this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/AnonymousBladeComponentCommenter.php: -------------------------------------------------------------------------------- 1 | $1'; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/BladeCommenter.php: -------------------------------------------------------------------------------- 1 | $0'; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/ExtendsCommenter.php: -------------------------------------------------------------------------------- 1 | $0'; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/IncludeCommenter.php: -------------------------------------------------------------------------------- 1 | [\'\"]){$excludesRegex}(.*?)\k(,(.*))?\)/s"; 17 | } 18 | 19 | public function replacement(): string 20 | { 21 | return '$0'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/IncludeIfCommenter.php: -------------------------------------------------------------------------------- 1 | [\'\"]){$excludesRegex}(.*?)\k(,(.*))?\)/s"; 17 | } 18 | 19 | public function replacement(): string 20 | { 21 | return '$0'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/IncludeUnlessCommenter.php: -------------------------------------------------------------------------------- 1 | $0'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/IncludeWhenCommenter.php: -------------------------------------------------------------------------------- 1 | $0'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/LivewireComponentCommenter.php: -------------------------------------------------------------------------------- 1 | ]*\s*\/?>)/"; 10 | } 11 | 12 | public function replacement(): string 13 | { 14 | return '$1'; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/LivewireDirectiveCommenter.php: -------------------------------------------------------------------------------- 1 | $0'; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Commenters/BladeCommenters/SectionCommenter.php: -------------------------------------------------------------------------------- 1 | ]*<\/title>)/"; 14 | } else { 15 | $regex = "/@yield(\((?:[^)(]+|(?1))*+\))(?![^<>]*<\/title>)/"; 16 | } 17 | 18 | return $regex; 19 | } 20 | 21 | public function replacementCallback(array $matches): string 22 | { 23 | preg_match('/@yield\(\'([^\']+)\'/', $matches[0], $parameters); 24 | $name = $parameters[1]; 25 | 26 | return "{$matches[0]}"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Commenters/RequestCommenters/RequestCommenter.php: -------------------------------------------------------------------------------- 1 | route()->getAction(); 15 | 16 | if (! isset($routeAction['controller'])) { 17 | return null; 18 | } 19 | 20 | $route = $routeAction['controller']; 21 | 22 | $comment .= "'; 29 | 30 | return $comment; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Commenters/RequestCommenters/ViewCommenter.php: -------------------------------------------------------------------------------- 1 | original->name(); 18 | 19 | return ""; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Http/Middleware/AddRequestComments.php: -------------------------------------------------------------------------------- 1 | shouldAddComments($response)) { 19 | return $response; 20 | } 21 | 22 | $newContent = $this->newResponseContent($request, $response); 23 | 24 | $response->setContent($newContent); 25 | 26 | return $response; 27 | } 28 | 29 | protected function shouldAddComments(Response $response): bool 30 | { 31 | if (! $response instanceof LaravelResponse) { 32 | return false; 33 | } 34 | 35 | if (! Str::contains($response->headers->get('content-type'), 'text/html')) { 36 | return false; 37 | } 38 | 39 | if (gettype($response->original) !== 'object') { 40 | return false; 41 | } 42 | 43 | return true; 44 | } 45 | 46 | protected function newResponseContent(Request $request, Response $response): string 47 | { 48 | $comments = collect(config('blade-comments.request_commenters')) 49 | ->map(fn (string $class) => app($class)) 50 | ->map(fn (RequestCommenter $commenter) => $commenter->comment($request, $response)) 51 | ->filter() 52 | ->implode(PHP_EOL); 53 | 54 | return "{$comments}{$response->getContent()}"; 55 | } 56 | } 57 | --------------------------------------------------------------------------------