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

ACPT-1493: Reset via reflection for ApplicationServer #286

Merged
merged 6 commits into from
Oct 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/pages/development/components/app-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ For this purpose, we should implement the following:
```php
class Cache implements ResetAfterRequestInterface
```
New in 2.4.8: ResetAfterRequestInterface doesn't have to be added to the class. The `_resetState()` method will be found by reflection and called as if it was implementing ResetAfterRequestInterface. This feature was added to allow modules to be backwards compatible with previous versions < 2.4.7 which don't have this interface.
jeff-matthews marked this conversation as resolved.
Show resolved Hide resolved

Add the implementation of the `_resetState()` method with overriding `$data` property to its initial state - empty array:

Expand All @@ -192,3 +193,33 @@ public function _resetState(): void
$this->data = [];
}
```


New in 2.4.8: An optional alternative to adding a _resetState method to a class has been added. Instead of adding _resetState to a class, a reset.json file may be added to a modules etc directory. The reset.json file will define which properties of a class will be reset, and what they will be reset to after a request.
jeff-matthews marked this conversation as resolved.
Show resolved Hide resolved

This feature was added to allow modules to be backwards compatible with previous versions < 2.4.7 which don't have the ResetAfterRequestInterface interface and also for classes where new public functions cannot be added. It also makes it possible to add reset behaviour to classes for modules that aren't under your control.

Here's an example. A class `Magento\Reward\Model\Total\Quote\Reward` inherits from `Magento\Quote\Model\Quote\Address\Total\AbstractTotal`. A reset.json file could be added to both of their modules.
jeff-matthews marked this conversation as resolved.
Show resolved Hide resolved

```
jeff-matthews marked this conversation as resolved.
Show resolved Hide resolved
"Magento\\Quote\\Model\\Quote\\Address\\Total\\AbstractTotal": {
"_code": null,
"_address": null,
"_canAddAmountToAddress": true,
"_canSetAddressAmount": true,
"_itemRowTotalKey": null,
"total": null
}
```

and

```
jeff-matthews marked this conversation as resolved.
Show resolved Hide resolved
{
"Magento\\Reward\\Model\\Total\\Quote\\Reward": {
"_code": "_code"
}
}
```

Both of these reset.json definitions will be used for a Reward object, and they will be called in proper order of inheritance so that subclasses can have specializations to their reset values that get called after the base class.
jeff-matthews marked this conversation as resolved.
Show resolved Hide resolved
Loading