Allow a closure to be passed with image replacement tags
This commit is contained in:
parent
8fbd060148
commit
5a68ef600b
|
|
@ -447,6 +447,13 @@ class TemplateProcessor
|
|||
$width = null;
|
||||
$height = null;
|
||||
$ratio = null;
|
||||
|
||||
// a closure can be passed as replacement value which after resolving, can contain the replacement info for the image
|
||||
// use case: only when a image if found, the replacement tags can be generated
|
||||
if (is_callable($replaceImage)) {
|
||||
$replaceImage = $replaceImage();
|
||||
}
|
||||
|
||||
if (is_array($replaceImage) && isset($replaceImage['path'])) {
|
||||
$imgPath = $replaceImage['path'];
|
||||
if (isset($replaceImage['width'])) {
|
||||
|
|
|
|||
|
|
@ -392,7 +392,9 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
|
|||
$imagePath = __DIR__ . '/_files/images/earth.jpg';
|
||||
|
||||
$variablesReplace = array(
|
||||
'headerValue' => $imagePath,
|
||||
'headerValue' => function () use ($imagePath) {
|
||||
return $imagePath;
|
||||
},
|
||||
'documentContent' => array('path' => $imagePath, 'width' => 500, 'height' => 500),
|
||||
'footerValue' => array('path' => $imagePath, 'width' => 100, 'height' => 50, 'ratio' => false),
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue