$chunks =
preg_split('#<esi\:include\s+(.*?)\s*(?:/|</esi\:include)>#',
$content, -1, \PREG_SPLIT_DELIM_CAPTURE
);
$i = 1;
while (isset($chunks[$i])) { $options =
[];
preg_match_all('/(src|onerror|alt)="([^"]*?)"/',
$chunks[$i],
$matches, \PREG_SET_ORDER
);
foreach ($matches as $set) { $options[$set[1
]] =
$set[2
];
} if (!
isset($options['src'
])) { throw new \
RuntimeException('Unable to process an ESI tag without a "src" attribute.'
);
} $chunks[$i] =
$boundary.
$options['src'
]."\n".
($options['alt'
] ?? ''
)."\n".
('continue'
=== ($options['onerror'
] ?? ''
))."\n";
$i += 2;
} $content =
$boundary.
implode('',
$chunks).
$boundary;
$response->
setContent($content);
$response->headers->
set('X-Body-Eval', 'ESI'
);
// remove ESI/1.0 from the Surrogate-Control header