Comments

dawehner’s picture

Component: base system » documentation

I guess this is the right component.

klausi’s picture

And we should document where this interface is used, namely with the "needs_destruction" tag for services. I just had to reverse engineer that since searching for the interface name yielded no results and I wanted to know where the actual destruction happens.

klausi’s picture

Status: Active » Needs review
StatusFileSize
new2.41 KB

klausi opened a new pull request for this issue.

dawehner’s picture

+++ b/core/lib/Drupal/Core/DestructableInterface.php
@@ -9,6 +9,9 @@
 interface DestructableInterface {

Note: We have some form of standard for those kind of documentation: https://www.drupal.org/files/issues/document_service_tags-2417789-17.patch

jhodgdon’s picture

Status: Needs review » Needs work

Great!

One small nitpick: in the core.api.php section of the patch:

+ *   instantiated. Services should implement the
+ *   \Drupal\Core\DestructableInterface in this case.

I would take out "the". We usually just say "Foo implements BarInterface" not "Foo implements *the* BarInterface".

Other than that, looks good to me and if "the" is removed I'd be in favor of RTBC.

Regarding @service_tag, that has not been adopted yet. See
#2264047: [meta] Document service definition tags

klausi’s picture

Status: Needs work » Needs review
StatusFileSize
new2.4 KB

klausi pushed some commits to the pull request.

For an interdiff please see the list of recent commits.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

The feedback from @jhodgdon got addressed,

For now this seems to be an improvement, so let's get it in.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

So... these look like good improvements to make, but none of them actually does what the issue title states, which is explain why DestructableInterface is useful. :)

 /**
  * The interface for services that need explicit destruction.
+ *

Can we add a thing under here like:

/**
  * The interface for services that need explicit destruction.
  * 
  * This is useful for services that are likely to terminate before the 
  * request formally ends.

...or whatever the actual reason you'd implement this as a module developer is?

jacobsanford’s picture

Status: Needs work » Needs review
StatusFileSize
new2.51 KB
new555 bytes

Added information requested in #8. Thanks for input!

I kept it terse and close to recommended text, but included a bit about rebuild/recreation due to use in caching or similar - not just termination.

jhodgdon’s picture

Status: Needs review » Needs work

Hm. There seems to be some disagreement... In core.api.php we have:

  * - needs_destruction: Indicates that a destruct() method needs to be called
  *   at the end of a request to finalize operations, if this service was
- *   instantiated.
+ *   instantiated. Services should implement \Drupal\Core\DestructableInterface
+ *   in this case.

Then in the interface, it says:

+ *
+ * This is useful for services that are likely to need termination or rebuild
+ * before the request formally ends.
+ *
+ * Services using this interface need to be registered with the
+ * "needs_destruction" tag.

So in the core.api.php file, it indicates that destruct() is called at the end of the request, but in the interface, it kind of implies that it could get rebuilt or terminated before the request ends. This is confusing to me. How would it get rebuilt??!? It seems like all that happens is that the destruct() method gets called, which I think is not a rebuild, and it's at the very end of the request...

So it seems like really what this means is that if your service class can just get destroyed normally when the PHP class goes away (or using the usual PHP class desctructor method), you don't need this interface, but if you have some kind of cleanup to do, you need this, right? What would be an example?

jacobsanford’s picture

At first look I assumed that it was both : extending DestructableInterface (and setting the tag) gave you a ready-baked way to destroy (and control what destruction meant with ::destruct()) at the end of the request, as well as offering a method to reinitialize it on demand if desired. I will admit I can now find no use of the latter in the API:

https://api.drupal.org/api/drupal/core!lib!Drupal!Core!DestructableInterface.php/interface/DestructableInterface/8

And in fact 'destruct' doesn't even remotely imply reincarnation-like behavior. I think your confusion is valid, and agree that the documentation should only show the first case.

jacobsanford’s picture

Status: Needs work » Needs review
StatusFileSize
new2.53 KB
new687 bytes

Enclosed are discussed changes. Thanks for review!

Regards.

dawehner’s picture

+++ b/core/lib/Drupal/Core/DestructableInterface.php
@@ -9,6 +9,12 @@
+ * This is useful for services that need to perform additional tasks to
+ * finalize operations or clean up before they are terminated.

We should explain that those runs ideally after the response is sent.

jacobsanford’s picture

Sure thing - thanks for review. Requested changes are attached.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, thanks!

  • xjm committed 3542d9a on 8.0.x
    Issue #2447365 by JacobSanford, klausi, dawehner, jhodgdon, webchick:...
xjm’s picture

Title: Let's explain in DestructableInterface, why its useful » Let's explain in DestructableInterface why it is useful
Status: Reviewed & tested by the community » Fixed

Thanks, this makes the purpose of the interface more clear. "The interface for services that need explicit destruction" was kind of intriguing and dramatic by itself. ;)

This issue only changes documentation, so per https://www.drupal.org/core/beta-changes, this can be completed any time during the Drupal 8 beta phase. Committed and pushed to 8.0.x (with credit for reviewers).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.