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

Cloning #96

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Cloning #96

wants to merge 18 commits into from

Conversation

lippserd
Copy link
Member

No description provided.

@cla-bot cla-bot bot added the cla/signed label Nov 29, 2022
@lippserd lippserd force-pushed the cloning branch 2 times, most recently from 834bd7a to be97fd2 Compare November 29, 2022 09:33
@lippserd lippserd force-pushed the cloning branch 2 times, most recently from 477d42e to a5863dc Compare December 13, 2022 12:48
@TAINCER TAINCER force-pushed the cloning branch 10 times, most recently from 15ff4e8 to c5c51ab Compare December 15, 2022 16:29
src/Attributes.php Outdated Show resolved Hide resolved
src/Attributes.php Outdated Show resolved Hide resolved
src/Attributes.php Outdated Show resolved Hide resolved
src/Attributes.php Outdated Show resolved Hide resolved
src/Attributes.php Outdated Show resolved Hide resolved
src/BaseHtmlElement.php Outdated Show resolved Hide resolved
src/BaseHtmlElement.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
@TAINCER TAINCER force-pushed the cloning branch 2 times, most recently from ad3f164 to e2b718f Compare January 9, 2023 11:36
src/Attributes.php Outdated Show resolved Hide resolved
src/Attributes.php Outdated Show resolved Hide resolved
src/BaseHtmlElement.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
Copy link
Member Author

@lippserd lippserd left a comment

Choose a reason for hiding this comment

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

Although this requires more effort, I would rather test the expected HTML instead of asserting that the output is not the same, as this could be caused by anything.

src/Attributes.php Outdated Show resolved Hide resolved
src/Attributes.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
@lippserd lippserd marked this pull request as ready for review January 16, 2023 10:11
@nilmerg nilmerg added this to the v0.7.0 milestone Jan 16, 2023
@lippserd
Copy link
Member Author

@TAINCER Please rebase.

@lippserd
Copy link
Member Author

lippserd commented Jan 17, 2023

@TAINCER @nilmberg has found that by keeping a reference to $this the object can only be destroyed at the end of the script. With a manual unset() call nothing happens. Since PHP 7.4, WeakReference is available as a workaround. But since we are at PHP 7.2+, we have to solve this differently. Instead of keeping a reference to $this, we store the spl_object_id() and compare it later with the ID of the callback this.

@TAINCER TAINCER force-pushed the cloning branch 2 times, most recently from 7d84d39 to 34a7d97 Compare January 17, 2023 10:12
tests/CloneTest.php Outdated Show resolved Hide resolved
tests/CloneTest.php Outdated Show resolved Hide resolved
nilmerg
nilmerg previously approved these changes Feb 2, 2023
Copy link
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

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

LGTM!

Now please push this on a different branch, rebased with master, and create a new PR. You're the author and @lippserd can't approve otherwise.

@nilmerg nilmerg mentioned this pull request Feb 2, 2023
@nilmerg nilmerg removed this from the v0.7.0 milestone Feb 2, 2023
Timm Ortloff and others added 5 commits February 10, 2023 09:16
After cloning elements, each own attribute callback must be rebound so
that the clones continue to work together.
We already have subclasses that override ensureAssembled() to execute
code before assemble() is called. From now on, initAssemble() should be
used for such purposes. initAssemble() is also introduced with the idea
that it will be used to set the object ID used for the rebinding
callbacks in BaseHtmlElement.
Currently the object ID is only set if the element has attributes. This
made sense since callbacks only need to be rebound after cloning the
element if attributes are set. However, with upcoming changes we will
also rebind callbacks of all content elements so that the object id
needs to be available in cases where the element has no attributes but
content.
…ively

Instead of cloning the content of each content element individually, the
entire content is cloned once, also preserving the object graph.
Subclasses of HtmlDocument that need to adjust the cloned content, for
example to rebind callbacks, can now use a promise resolved with an
SplObjectStorage that provides each original and its cloned element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants