mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Don't crash when @stack['componentScripts'] is empty and properly format the output
This commit is contained in:
@@ -479,20 +479,23 @@
|
|||||||
$reflection = new \ReflectionClass($__env);
|
$reflection = new \ReflectionClass($__env);
|
||||||
$property = $reflection->getProperty('pushes');
|
$property = $reflection->getProperty('pushes');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
|
||||||
// Take every line into a new array, one element per line
|
|
||||||
$filteredStack = array_map(function($value)
|
|
||||||
{
|
|
||||||
return explode("#SEP#", str_replace(array("\n", "\r", "\t"), '#SEP#', trim($value)));
|
|
||||||
}, $property->getValue($__env)['componentScripts']);
|
|
||||||
|
|
||||||
// Flatten the array into a single one, only keep unique lines, remove empty lines
|
|
||||||
$filteredStack = array_filter(array_unique(array_merge(...$filteredStack)));
|
|
||||||
|
|
||||||
// Write it back
|
|
||||||
$env = $property->getValue($__env);
|
$env = $property->getValue($__env);
|
||||||
$env['componentScripts'] = $filteredStack;
|
|
||||||
$property->setValue($__env, $env);
|
if (array_key_exists('componentScripts', $env))
|
||||||
|
{
|
||||||
|
// Take every line into a new array, one element per line
|
||||||
|
$filteredStack = array_map(function($value)
|
||||||
|
{
|
||||||
|
return explode("#SEP#", str_replace(array("\n", "\r", "\t"), '#SEP#', trim($value)));
|
||||||
|
}, $env['componentScripts']);
|
||||||
|
|
||||||
|
// Flatten the array into a single one, only keep unique lines, remove empty lines, add a defined new line
|
||||||
|
$filteredStack = preg_filter('/$/', "\n", array_filter(array_unique(array_merge(...$filteredStack))));
|
||||||
|
|
||||||
|
// Write it back
|
||||||
|
$env['componentScripts'] = $filteredStack;
|
||||||
|
$property->setValue($__env, $env);
|
||||||
|
}
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
@stack('componentScripts')
|
@stack('componentScripts')
|
||||||
|
Reference in New Issue
Block a user