PHPWord
PHPWord copied to clipboard
Feature: add limit option to setvalues
Description
This PR adds a limit parameter to the setValues function, which itself is uses within with setValue. This will help to avoid to minimize written if the limit is needed for a bulk search&replace operation.
example:
$templateProcessor = new TemplateProcessor('sample.docx');
$firstname = 'John';
$middlename = 'Mc';
$lastname = 'Doe';
// current
$templateProcessor->setValues([
"firstname" => $firstname,
"middlename" => $middlename,
"lastname" => $lastname,
]);
// assuming we want to change the only the "first" name variables:
// workaround
$templateProcessor->setValue("firstname", $firstname, 1);
$templateProcessor->setValue("middlename", $middlename, 1);
$templateProcessor->setValue("lastname", $lastname, 1);
// improvement
$templateProcessor->setValues([
"firstname" => $firstname,
"middlename" => $middlename,
"lastname" => $lastname,
], 1);
Checklist:
- [x] My CI is :green_circle:
- [x] I have covered by unit tests my new code (check build/coverage for coverage report)
- [ ] I have updated the documentation to describe the changes
- [x] I have updated the changelog
coverage: 96.757%. remained the same when pulling b7d4a11aefea9adb641de17ec2661c4017486779 on moghwan:feat/add-limit-to-setvalues into 2a524e2445e27b293c9b3e0f3945f312cedac3a1 on PHPOffice:master.
@moghwan Hi, could you add Unit Tests, please ?
https://github.com/PHPOffice/PHPWord/blob/master/tests/PhpWordTests/TemplateProcessorTest.php#L597
sure thing!
done
branch & doc change updated
@moghwan Thank you for your contribution 🥳
with pleasure 😁