Skip to content

Feature: add limit option to setvalues #2640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 13, 2025

Conversation

moghwan
Copy link
Contributor

@moghwan moghwan commented Aug 4, 2024

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:

  • My CI is 🟢
  • I have covered by unit tests my new code (check build/coverage for coverage report)
  • I have updated the documentation to describe the changes
  • I have updated the changelog

@moghwan moghwan marked this pull request as ready for review August 4, 2024 15:19
@coveralls
Copy link

coveralls commented Aug 4, 2024

Coverage Status

coverage: 96.757%. remained the same
when pulling b7d4a11 on moghwan:feat/add-limit-to-setvalues
into 2a524e2 on PHPOffice:master.

@Progi1984
Copy link
Member

@Progi1984 Progi1984 added the Status: Waiting for feedback Question has been asked, waiting for response from PR author label Aug 7, 2024
@moghwan
Copy link
Contributor Author

moghwan commented Aug 26, 2024

sure thing!

@moghwan
Copy link
Contributor Author

moghwan commented Aug 27, 2024

done

@Progi1984 Progi1984 removed the Status: Waiting for feedback Question has been asked, waiting for response from PR author label Aug 30, 2024
@Progi1984 Progi1984 added this to the 1.3.1 milestone Aug 30, 2024
Copy link
Member

@Progi1984 Progi1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moghwan Could you rebase the PR and update the changelog 1.4.0 ?

After that, it will be a merge.

@Progi1984 Progi1984 added the Status: Waiting for feedback Question has been asked, waiting for response from PR author label Feb 12, 2025
@moghwan
Copy link
Contributor Author

moghwan commented Feb 13, 2025

branch & doc change updated

@Progi1984 Progi1984 merged commit 5c84adf into PHPOffice:master Feb 13, 2025
29 checks passed
@Progi1984 Progi1984 removed the Status: Waiting for feedback Question has been asked, waiting for response from PR author label Feb 13, 2025
@Progi1984
Copy link
Member

@moghwan Thank you for your contribution 🥳

@moghwan
Copy link
Contributor Author

moghwan commented Feb 13, 2025

with pleasure 😁

MichaelPFrey pushed a commit to MichaelPFrey/PHPWord that referenced this pull request Feb 15, 2025
* adding limit option to setValues for multiple values

* add parameter type

* Update 2.0.0.md

* add more replacement for testSetValues

* testSetValues with different limit values

* testSetValues with a zero replacement

* Update 1.3.0.md

* improve tests with variables count check to ensure number of occurrences replaced

* Update 1.4.0.md

* Update 1.3.0.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants