TomasVotruba / bladestan

PHPStan analysis for Blade templates
https://tomasvotruba.com/blog/introducing-bladestan-phpstan-analysis-of-blade-templates/
MIT License
286 stars 13 forks source link

Fix processing @include with data given in a variable #46

Closed AJenbo closed 1 year ago

AJenbo commented 1 year ago

Fixes #26

The regex was not taking including data as a variable in to account, and there where also some minor errors in how the string was escaped.

The block for matching variable names was taken from here: https://www.php.net/language.variables.basics

Proper escaping was done by using regex101's generate code function, this is also why # was swapped for / so the code can be copied directly in the future with out having to manually modify it.

Technically @include accepts arbitrary PHP, but this will at least give everyone a way to adjust things to something that works.

Example:

@include('template', ['foo' => 'bar', ...$extra] + more())

Can now be written as:

@php
$data = ['foo' => 'bar', ...$extra] + more();
@endphp
@include('template', $data)
TomasVotruba commented 1 year ago

Thank you :partying_face: