Skip to content
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

Use XML API instead of string replacement in cloneBlock and replaceBlock #1354

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

czosel
Copy link
Contributor

@czosel czosel commented Apr 23, 2018

Description

This started as a simple update of #541, but turned into a rewrite of the clone/replace functionality based on DOMDocument APIs.

I'd be glad to get some feedback on this before I start making the tests pass.

Fixes #316, #341, #867

Checklist:

  • I have run composer run-script check --timeout=0 and no errors were reported
  • The new code is covered by unit tests (check build/coverage for coverage report)

Implements the fonction gave by brad-jones on the issue :
PHPOffice#341 (comment)
@czosel czosel changed the title (WIP) Fix cloneblock replaceblock (WIP) Update cloneBlock and replaceBlock Apr 23, 2018
@czosel czosel force-pushed the fix-cloneblock-replaceblock branch 2 times, most recently from aca145c to 5f5f9d0 Compare April 23, 2018 17:03
@czosel czosel force-pushed the fix-cloneblock-replaceblock branch from 5f5f9d0 to 232ab1f Compare April 24, 2018 07:52
@czosel czosel changed the title (WIP) Update cloneBlock and replaceBlock Update cloneBlock and replaceBlock Apr 24, 2018
@czosel czosel force-pushed the fix-cloneblock-replaceblock branch 2 times, most recently from 3e8ea9a to 5574e21 Compare April 25, 2018 14:42
@czosel
Copy link
Contributor Author

czosel commented Apr 25, 2018

Would be great if someone could take a first look before I'm making all the tests pass 😃
@troosan

@troosan
Copy link
Contributor

troosan commented Apr 25, 2018

I think it is indeed much safer to treat xml as xml instead of trying to parse it with regular expressions (although the memory consumption is probably not the same?)!

The only problem with this refactoring is that it will probably make most of the currently open pull requests (add image, delete row, ...) very hard to merge.

Any refactoring of this magnitude will definitely need complete test coverage to be sure we do not introduce regressions.

I'm planning on having version 0.16 dedicated to the TemplateProcessor.

@troosan
Copy link
Contributor

troosan commented Apr 25, 2018

as a first remark, wouldn't it be better to parse the tempDocumentMainPart to XML only once.
as the code is now, you are parsing it in each method, if you have 20 replacements to run on a document, it will mean parsing the whole document as many times.

@czosel
Copy link
Contributor Author

czosel commented Apr 25, 2018

Thanks for your feedback @troosan!

wouldn't it be better to parse the tempDocumentMainPart to XML only once

Definitely - I took this shortcut for now just to avoid having to refactor even more 😄 But if we agree that this is the way to go forward, it's definitely worth it to make sure the parsing is only done once.

The only problem with this refactoring is that it will probably make most of the currently open pull requests (add image, delete row, ...) very hard to merge.

You're right - but I guess in the long run it makes most sense to make sure that we're building on a solid foundation.

@troosan troosan added this to the v0.16.0 milestone Jul 15, 2018
@troosan troosan changed the title Update cloneBlock and replaceBlock Use XML API instead of string replacement in cloneBlock and replaceBlock Jul 19, 2018
@nguyenk
Copy link

nguyenk commented Oct 25, 2018

First of all thank you so much for your work.

I'm very impatient to see your PR merged, because this might solve some of my problems in using phpword.

What is the current state of that PR ? Can I do something to make it go further ?

@czosel
Copy link
Contributor Author

czosel commented Oct 25, 2018

Hi @nguyenk! Unfortunately, I don't think I'll find the time to finish this PR in the near future. While current state seems to work, it still needs to be optimized (parse to XML only once) and it lacks proper testing. It would be awesome if you could try to continue work on this - let me know if there is anything I could help with!

@troosan troosan modified the milestones: v0.16.0, Later Dec 8, 2018
@PowerKiKi PowerKiKi changed the base branch from develop to master November 16, 2022 21:11
@Progi1984 Progi1984 force-pushed the master branch 2 times, most recently from 6a60ae7 to 2d9f999 Compare August 30, 2023 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants