PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Feature: add limit option to setvalues

Open moghwan opened this issue 6 months ago • 4 comments

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

moghwan avatar Aug 04 '24 15:08 moghwan