-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEXT-25364 - Implement new scalar value flow storer for simply data s…
…tore logics in flows
- Loading branch information
1 parent
666394f
commit c606529
Showing
88 changed files
with
1,541 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
title: Flow storer with scalar values | ||
date: 2023-02-02 | ||
area: core | ||
tags: [flow, storer, scalar, deprecation] | ||
--- | ||
|
||
## Context | ||
At the moment we have a bunch of different `FlowStorer` implementations. Most of them are used to store scalar values without any restore logic. Each of the Storer class has an own interface which is used to identify if the data of the event should be stored. This leads to much boilerplate code when adding new storer implementations or when plugins want to bypass some for events. | ||
|
||
## Decision | ||
|
||
We introduce a generic `ScalarValuesAware` interface which can be used to store simple values which should be simply stored and restored one to one: | ||
|
||
```php | ||
interface ScalarValuesAware | ||
{ | ||
public const STORE_VALUES = 'scalar_values'; | ||
/** @return array<string, scalar|null|array> */ | ||
public function getValues(): array; | ||
} | ||
``` | ||
|
||
This event can be used in different events which needs a simple storage logic: | ||
|
||
```php | ||
class SomeFlowAwareEvent extends Event implements ScalarStoreAware, FlowEventAware | ||
{ | ||
public function __construct(private readonly string $url) { } | ||
public function getValues(): array | ||
{ | ||
return ['url' => $this->url]; | ||
} | ||
} | ||
``` | ||
|
||
To store and restore this data, we provide a simple `FlowStorer` implementation: | ||
|
||
```php | ||
class ScalarValuesStorer extends FlowStorer | ||
{ | ||
public function store(FlowEventAware $event, array $stored): array | ||
{ | ||
if (!$event instanceof ScalarValuesAware) return $stored | ||
$stored[ScalarValuesAware::STORE_VALUES] = $event->getValues(); | ||
return $stored; | ||
} | ||
public function restore(StorableFlow $storable): void | ||
{ | ||
$values = $storable->getStore(ScalarValuesAware::STORE_VALUES); | ||
foreach ($values as $key => $value) { | ||
$storable->setData($key, $value); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Consequences | ||
- It is no more necessary to implement storer classes to just store and restore scalar values. | ||
- We deprecate all current `Aware` interface and `Storer` classes which can simply replaced by this new implementation | ||
- Following storer and interfaces will be deprecated: | ||
- ConfirmUrlStorer > ConfirmUrlAware | ||
- ContactFormDataStorer > ContactFormDataAware | ||
- ContentsStorer > ContentsAware | ||
- ContextTokenStorer > ContextTokenAware | ||
- DataStorer > DataAware | ||
- EmailStorer > Email Aware | ||
- MailStorer > Mail Aware | ||
- NameStorer > NameAware | ||
- RecipientsStorer > RecipientsAware | ||
- ResetUrlStorer > ResetUrlAware | ||
- ReviewFormDataStorer > ReviewFormDataAware | ||
- ShopNameStorer > ShopNameAware | ||
- SubjectStorer > SubjectAware | ||
- TemplateDataStorer > TemplateDataAware | ||
- UrlStorer > UrlAware | ||
- Affected events will be updated to use the new `ScalarStoreAware` interface. | ||
- Existing `*Aware` events will stay in the event implementation and will be marked as deprecated. | ||
- Developers can much easier store and restore values without providing a lot of boilerplate code. | ||
- Deprecated classes will be removed in v6.6.0.0 | ||
- All interface and storer logic will remain until the next major and has to be compatible with each other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
--- | ||
title: Minify flow storer | ||
issue: NEXT-25364 | ||
author: Oliver Skroblin | ||
author_email: o.skroblin@shopware.com | ||
--- | ||
# Core | ||
* Added new `ScalarValuesAware` and `ScalarValuesStorer` class, which allows to store scalar values for flows. | ||
* Deprecated diverse flow storer classes and interfaces in favor of the new `ScalarValuesStorer` class: | ||
* `ConfirmUrlAware` | ||
* `ContactFormDataAware` | ||
* `ContentsAware` | ||
* `ContextTokenAware` | ||
* `DataAware` | ||
* `EmailAware` | ||
* `MediaUploadedAware` | ||
* `NameAware` | ||
* `RecipientsAware` | ||
* `ResetUrlAware` | ||
* `ReviewFormDataAware` | ||
* `ScalarStoreAware` | ||
* `ShopNameAware` | ||
* `SubjectAware` | ||
* `TemplateDataAware` | ||
* `UrlAware` | ||
* `ConfirmUrlStorer` | ||
* `ContactFormDataStorer` | ||
* `ContentsStorer` | ||
* `ContextTokenStorer` | ||
* `DataStorer` | ||
* `EmailStorer` | ||
* `NameStorer` | ||
* `RecipientsStorer` | ||
* `ResetUrlStorer` | ||
* `ReviewFormDataStorer` | ||
* `ScalarFlowStorer` | ||
* `ScalarValuesStorer` | ||
* `ShopNameStorer` | ||
* `SubjectStorer` | ||
* `TemplateDataStorer` | ||
* `UrlStorer` | ||
* Replaced deprecated flow storer interfaces in the flow event with the new `ScalarValuesAware` interface in the following events: | ||
* `CustomerAccountRecoverRequestEvent` | ||
* `CustomerBeforeLoginEvent` | ||
* `CustomerDoubleOptInRegistrationEvent` | ||
* `CustomerLoginEvent` | ||
* `DoubleOptInGuestOrderEvent` | ||
* `ContactFormEvent` | ||
* `MailBeforeSentEvent` | ||
* `MailBeforeValidateEvent` | ||
* `MailErrorEvent` | ||
* `MailSentEvent` | ||
* `MediaUploadedEvent` | ||
* `NewsletterRegisterEvent` | ||
* `ReviewFormEvent` | ||
* `ProductExportLoggingEvent` | ||
* `UserRecoveryRequestEvent` | ||
___ | ||
# Upgrade Information | ||
## Deprecated diverse flow storer classes and interfaces in favor of the new `ScalarValuesStorer` class | ||
We deprecated diverse flow storer interfaces in favor of the new `ScalarValuesAware` class. The new `ScalarValuesAware` class allows to store scalar values much easier for flows without implementing own storer and interface classes. | ||
If you implemented one of the deprecated interfaces or implemented an own interface and storer class to store simple values, you should replace it with the new `ScalarValuesAware` class. | ||
|
||
```php | ||
|
||
// before | ||
class MyEvent extends Event implements \Shopware\Core\Content\Flow\Dispatching\Aware\UrlAware | ||
{ | ||
private string $url; | ||
|
||
public function __construct(string $url) | ||
{ | ||
$this->url = $url; | ||
} | ||
|
||
public function getUrl(): string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
// ... | ||
} | ||
|
||
// after | ||
|
||
class MyEvent extends Event implements \Shopware\Core\Content\Flow\Dispatching\Aware\ScalarValuesAware | ||
{ | ||
private string $url; | ||
|
||
public function __construct(string $url) | ||
{ | ||
$this->url = $url; | ||
} | ||
|
||
public function getScalarValues(): array | ||
{ | ||
return [ | ||
'url' => $this->url, | ||
// ... | ||
]; | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
The deprecated flow storer interfaces are: | ||
* `ConfirmUrlAware` | ||
* `ContactFormDataAware` | ||
* `ContentsAware` | ||
* `ContextTokenAware` | ||
* `DataAware` | ||
* `EmailAware` | ||
* `MediaUploadedAware` | ||
* `NameAware` | ||
* `RecipientsAware` | ||
* `ResetUrlAware` | ||
* `ReviewFormDataAware` | ||
* `ScalarStoreAware` | ||
* `ShopNameAware` | ||
* `SubjectAware` | ||
* `TemplateDataAware` | ||
* `UrlAware` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.