fixes
This commit is contained in:
@@ -31,6 +31,7 @@ class BladeCompiler extends Compiler implements CompilerInterface
|
||||
Concerns\CompilesLoops,
|
||||
Concerns\CompilesRawPhp,
|
||||
Concerns\CompilesStacks,
|
||||
Concerns\CompilesStyles,
|
||||
Concerns\CompilesTranslations,
|
||||
ReflectsClosures;
|
||||
|
||||
@@ -506,6 +507,8 @@ class BladeCompiler extends Compiler implements CompilerInterface
|
||||
{
|
||||
preg_match_all('/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( [\S\s]*? ) \))?/x', $template, $matches);
|
||||
|
||||
$offset = 0;
|
||||
|
||||
for ($i = 0; isset($matches[0][$i]); $i++) {
|
||||
$match = [
|
||||
$matches[0][$i],
|
||||
@@ -521,19 +524,62 @@ class BladeCompiler extends Compiler implements CompilerInterface
|
||||
while (isset($match[4]) &&
|
||||
Str::endsWith($match[0], ')') &&
|
||||
! $this->hasEvenNumberOfParentheses($match[0])) {
|
||||
$rest = Str::before(Str::after($template, $match[0]), ')');
|
||||
if (($after = Str::after($template, $match[0])) === $template) {
|
||||
break;
|
||||
}
|
||||
|
||||
$rest = Str::before($after, ')');
|
||||
|
||||
if (isset($matches[0][$i + 1]) && Str::contains($rest.')', $matches[0][$i + 1])) {
|
||||
unset($matches[0][$i + 1]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$match[0] = $match[0].$rest.')';
|
||||
$match[3] = $match[3].$rest.')';
|
||||
$match[4] = $match[4].$rest;
|
||||
}
|
||||
|
||||
$template = Str::replaceFirst($match[0], $this->compileStatement($match), $template);
|
||||
[$template, $offset] = $this->replaceFirstStatement(
|
||||
$match[0],
|
||||
$this->compileStatement($match),
|
||||
$template,
|
||||
$offset
|
||||
);
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the first match for a statement compilation operation.
|
||||
*
|
||||
* @param string $search
|
||||
* @param string $replace
|
||||
* @param string $subject
|
||||
* @param int $offset
|
||||
* @return array
|
||||
*/
|
||||
protected function replaceFirstStatement($search, $replace, $subject, $offset)
|
||||
{
|
||||
$search = (string) $search;
|
||||
|
||||
if ($search === '') {
|
||||
return $subject;
|
||||
}
|
||||
|
||||
$position = strpos($subject, $search, $offset);
|
||||
|
||||
if ($position !== false) {
|
||||
return [
|
||||
substr_replace($subject, $replace, $position, strlen($search)),
|
||||
$position + strlen($replace),
|
||||
];
|
||||
}
|
||||
|
||||
return [$subject, 0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given expression has the same number of opening and closing parentheses.
|
||||
*
|
||||
@@ -675,7 +721,7 @@ class BladeCompiler extends Compiler implements CompilerInterface
|
||||
* Check the result of a condition.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @param mixed ...$parameters
|
||||
* @return bool
|
||||
*/
|
||||
public function check($name, ...$parameters)
|
||||
|
||||
@@ -115,6 +115,10 @@ class ComponentTagCompiler
|
||||
@(?:class)(\( (?: (?>[^()]+) | (?-1) )* \))
|
||||
)
|
||||
|
|
||||
(?:
|
||||
@(?:style)(\( (?: (?>[^()]+) | (?-1) )* \))
|
||||
)
|
||||
|
|
||||
(?:
|
||||
\{\{\s*\\\$attributes(?:[^}]+?)?\s*\}\}
|
||||
)
|
||||
@@ -176,6 +180,10 @@ class ComponentTagCompiler
|
||||
@(?:class)(\( (?: (?>[^()]+) | (?-1) )* \))
|
||||
)
|
||||
|
|
||||
(?:
|
||||
@(?:style)(\( (?: (?>[^()]+) | (?-1) )* \))
|
||||
)
|
||||
|
|
||||
(?:
|
||||
\{\{\s*\\\$attributes(?:[^}]+?)?\s*\}\}
|
||||
)
|
||||
@@ -506,6 +514,10 @@ class ComponentTagCompiler
|
||||
@(?:class)(\( (?: (?>[^()]+) | (?-1) )* \))
|
||||
)
|
||||
|
|
||||
(?:
|
||||
@(?:style)(\( (?: (?>[^()]+) | (?-1) )* \))
|
||||
)
|
||||
|
|
||||
(?:
|
||||
\{\{\s*\\\$attributes(?:[^}]+?)?\s*\}\}
|
||||
)
|
||||
@@ -563,6 +575,7 @@ class ComponentTagCompiler
|
||||
$attributeString = $this->parseShortAttributeSyntax($attributeString);
|
||||
$attributeString = $this->parseAttributeBag($attributeString);
|
||||
$attributeString = $this->parseComponentTagClassStatements($attributeString);
|
||||
$attributeString = $this->parseComponentTagStyleStatements($attributeString);
|
||||
$attributeString = $this->parseBindAttributes($attributeString);
|
||||
|
||||
$pattern = '/
|
||||
@@ -665,6 +678,27 @@ class ComponentTagCompiler
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse @style statements in a given attribute string into their fully-qualified syntax.
|
||||
*
|
||||
* @param string $attributeString
|
||||
* @return string
|
||||
*/
|
||||
protected function parseComponentTagStyleStatements(string $attributeString)
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/@(style)(\( ( (?>[^()]+) | (?2) )* \))/x', function ($match) {
|
||||
if ($match[1] === 'style') {
|
||||
$match[2] = str_replace('"', "'", $match[2]);
|
||||
|
||||
return ":style=\"\Illuminate\Support\Arr::toCssStyles{$match[2]}\"";
|
||||
}
|
||||
|
||||
return $match[0];
|
||||
}, $attributeString
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the "bind" attributes in a given attribute string into their fully-qualified syntax.
|
||||
*
|
||||
|
||||
19
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesStyles.php
vendored
Normal file
19
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesStyles.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesStyles
|
||||
{
|
||||
/**
|
||||
* Compile the conditional style statement into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileStyle($expression)
|
||||
{
|
||||
$expression = is_null($expression) ? '([])' : $expression;
|
||||
|
||||
return "style=\"<?php echo \Illuminate\Support\Arr::toCssStyles{$expression} ?>\"";
|
||||
}
|
||||
}
|
||||
@@ -221,6 +221,19 @@ class ComponentAttributeBag implements ArrayAccess, Htmlable, IteratorAggregate
|
||||
return $this->merge(['class' => Arr::toCssClasses($classList)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally merge styles into the attribute bag.
|
||||
*
|
||||
* @param mixed|array $styleList
|
||||
* @return static
|
||||
*/
|
||||
public function style($styleList)
|
||||
{
|
||||
$styleList = Arr::wrap($styleList);
|
||||
|
||||
return $this->merge(['style' => Arr::toCssStyles($styleList)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge additional attributes / values into the attribute bag.
|
||||
*
|
||||
@@ -238,9 +251,10 @@ class ComponentAttributeBag implements ArrayAccess, Htmlable, IteratorAggregate
|
||||
|
||||
[$appendableAttributes, $nonAppendableAttributes] = collect($this->attributes)
|
||||
->partition(function ($value, $key) use ($attributeDefaults) {
|
||||
return $key === 'class' ||
|
||||
(isset($attributeDefaults[$key]) &&
|
||||
$attributeDefaults[$key] instanceof AppendableAttributeValue);
|
||||
return $key === 'class' || $key === 'style' || (
|
||||
isset($attributeDefaults[$key]) &&
|
||||
$attributeDefaults[$key] instanceof AppendableAttributeValue
|
||||
);
|
||||
});
|
||||
|
||||
$attributes = $appendableAttributes->mapWithKeys(function ($value, $key) use ($attributeDefaults, $escape) {
|
||||
@@ -248,6 +262,10 @@ class ComponentAttributeBag implements ArrayAccess, Htmlable, IteratorAggregate
|
||||
? $this->resolveAppendableAttributeDefault($attributeDefaults, $key, $escape)
|
||||
: ($attributeDefaults[$key] ?? '');
|
||||
|
||||
if ($key === 'style') {
|
||||
$value = Str::finish($value, ';');
|
||||
}
|
||||
|
||||
return [$key => implode(' ', array_unique(array_filter([$defaultsValue, $value])))];
|
||||
})->merge($nonAppendableAttributes)->all();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.0.2",
|
||||
"ext-json": "*",
|
||||
"ext-tokenizer": "*",
|
||||
"illuminate/collections": "^9.0",
|
||||
"illuminate/container": "^9.0",
|
||||
"illuminate/contracts": "^9.0",
|
||||
|
||||
Reference in New Issue
Block a user