Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
base system
Priority:
Major
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
1 Mar 2014 at 08:49 UTC
Updated:
14 Jul 2017 at 12:08 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
xanoComment #2
berdirI really think we shouldn't move this on two lines. 3 characters more and it would be too long anyway ;)
not sure why the method needs to be renamed? We can't name it after both methods and __sleep() is just as important ;)
The reason it is declared on the class is that it can be public, so that this assertion can work.
I don't think it should be removed. Maybe changed to assert with an empty array. or do = NULL instead of array() ?
Comment #3
xanoWhat about this? By splitting the tests for
__sleep()and__wakeup(), we make debugging easier.Comment #5
jhodgdonThere's an issue
#2206175: Document traits that use methods on interfaces
which is proposing a standard for how to document Traits.
The suggestions there (not official standards yet but probably a good idea):
a) Add a @see in the main Trait doc block referencing the interface whose methods it is implementing.
b) Document each method as:
Comment #6
xano@jhodgdon: those documentation standards do not apply here, as we are not implementing interface methods.
Comment #7
jhodgdonYeah, we updated the standards for cases like this where it's not implementing an interface. Discussion is ongoing...
Meanwhile, a minor issue to fix in the current patch, and a question:
a)DependencySerialization.php
After @deprecated the next line should be indented two spaces. (like after any other tag)
b) So you are replacing two different abstract classes with the same trait? How come we had two?
Comment #8
berdirI don't see a second class, the other one is a test that's changed so much that it doesn't show up as renamed anymore apparently.
However, I would expect a second removal as mentioned in IRC, and that's in \Drupal\Core\Plugin\PluginBase.
Comment #9
jhodgdonMy mistake on the second class. Not sure what I was looking at. Maybe I should put my glasses on. :)
Comment #10
sunComing from #2210873: Let plugin bags use the DependencySerializationTrait (was: EditorAdminTest fails on PHP 5.4 silently with unicorn editor)
AFAICS, this trait will have to be used pretty much by every service, controller, form, plugin, and generally all classes that get services injected, because no class can know whether it is going to be serialized somewhere else...?
This trait introduces a dependency on the global state construct of
\Drupal::getContainer()to every class that uses it...?Usage of this trait means that a class cannot implement
__sleep()+__wakeup()on its own anymore, unless it implements the following fugliness:cf. http://php.net/manual/en/language.oop5.traits.php#language.oop5.traits.c...
Hrm. All of that sounds very concerning.
I wonder whether we shouldn't change this trait implementation to use the
\Serializableinterface instead?→ Apply the trait to the injected services themselves, instead of each and every single consuming class?
(untested pseudo code)
Or perhaps we have to rethink entirely — if the state of injected dependencies cannot be serialized/unserialized with other objects (because the state may differ in the context in which unserialization happens), then why are we storing those stateful objects on the serializable object in the first place?
That appears to be the root cause, and this entire futzing with serialization only exists to prevent serialization of class members that shouldn't be class members to begin with?
For example, why can't we do this instead?
→ No more stateful services in class members of the consuming class.
→
serialize()works as-is.Only
unserialize()needs to re-inject the services from the container.Comment #11
berdir\Serializable is messed up on 5.4+, or maybe we messed up but at least right now, we have to use __unserialize() in a lot of places instead of the interface.
Comment #12
xanoThat was added to #3, but lost in #6. It's back in this one again.
Comment #14
xanoDuh.
Comment #15
Crell commentedsun: The root problem here is that we're serializing objects that we have no business serializing, ie, those that have big service chains. The base class this trait is replacing is already a disgusting hack. The real answer is to adjust our key serializable objects to not have direct dependencies on services.
Comment #16
effulgentsia commented@Crell: How do we do that? Forms are one of our key serializable objects, and very often have a dependency on a plugin manager and/or other services provided by the module. In fact isn't that precisely what a good UI/API separation within a module would always lead to?
Comment #17
effulgentsia commentedPerhaps we can fix that: #2183275-17: Use cache for $form, kv for $form_state.
Comment #18
Crell commentedI totally forgot this issue was here and just redid it. :-/ However, I went ahead and converted all usages to the trait outright. Let's see if the bot likes it or not...
This patch JUST does a straight conversion; it doesn't change anything else about the base class/trait. Its existence is a code smell but that's a separate matter from just making it a trait.
Comment #19
Crell commented14: drupal_2208115_14.patch queued for re-testing.
Comment #22
xanoComment #24
xanoI just realized this meant that you didn't re-roll and created a completely different patch, which is not the most helpful way to file another patch in an existing issue, TBH.
Comment #26
xanoWe just ran into
(source php.net)
Comment #27
yesct commentedComment #28
tim.plunkettI'm having to copy this code into yet another class, :\
Comment #29
damiankloip commentedSo we basically have to not have configFactory private on FormBase, which is not the end of the world by any means IMO.. OR, not have this issue. Using Serializable is not an option as we can't implement an interface from a trait. So then in that case we are back to what we have now anyway :)
Comment #31
damiankloip commentedSorry, branch rebasing fail.
Comment #33
damiankloip commentedAnother one crept in.
Comment #34
yched commentedShould be pretty close now ;-)
Comment #35
damiankloip commentedhehe
Comment #36
berdirShould we instead update the comment to state something like "Never use this directly, use self::config() instead"? It's still correct even if it's protected again.
Looks great otherwise, if there ever was a class that's destined to become a trait then it's this ;)
Note that I just RTBC'd #2283929: Clean up condition plugins to have schema support and to allow them to be optional, if that gets in first, we need to update that and add the trait there as well.
Comment #37
damiankloip commentedThanks. Good point - added a comment to that effect back in.
Comment #38
berdirWorks for me, the linked issue above was committed, so we need to update the class there as well.
Comment #39
damiankloip commentedNice, there we go.
Comment #40
xanoI opened #2284977: Remove \Drupal\Core\Plugin\PluginBase as a follow-up.
Comment #41
berdirGreat, I think this is ready :)
Comment #42
dries commentedCommitted to 8.x. Thanks.
Comment #45
andypostNow #2849674: Complex job in ViewExecutable::unserialize() causes data corruption going to remove the trait from
ViewExecutable