You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/nonStandardExtensions/filter.rst
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -360,6 +360,8 @@ Custom transforming filter
360
360
361
361
If you want to provide a custom filter which transforms a value (eg. redirect data into a manually written model, transforming between data types [eg. accepting values as an integer but handle them internally as binary strings]) you must implement the **PHPModelGenerator\\PropertyProcessor\\Filter\\TransformingFilterInterface**. This interface adds the **getSerializer** method to your filter. The method is similar to the **getFilter** method. It must return a callable which is available during the render process as well as during code execution. The returned callable must return null or a string and undo a transformation (eg. the serializer method of the builtin **dateTime** filter transforms a DateTime object back into a formatted string). The serializer method will be called with the current value of the property as the first argument and with the (optionally provided) additional options of the filter as the second argument. Your custom transforming filter might look like:
362
362
363
+
The custom serializer method will be called if the model utilizing the custom filter is generated with `serialization methods<../gettingStarted.html#serialization-methods>`__ and *toArray* or *toJSON* is called.
364
+
363
365
.. code-block:: php
364
366
365
367
namespace MyApp\Model\Generator\Filter;
@@ -378,7 +380,7 @@ If you want to provide a custom filter which transforms a value (eg. redirect da
378
380
379
381
// $customer will contain the current value of the property the filter is applied to
380
382
// $additionalOptions will contain all additional options from the JSON Schema
381
-
public static function instantiateCustomer(?Customer $customer, array $additionalOptions): ?string
383
+
public static function serializeCustomer(?Customer $customer, array $additionalOptions): ?string
0 commit comments