Skip to content

Commit 66206c8

Browse files
committed
Update docs
1 parent cad7ade commit 66206c8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

docs/source/nonStandardExtensions/filter.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ Custom transforming filter
360360

361361
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:
362362

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+
363365
.. code-block:: php
364366
365367
namespace MyApp\Model\Generator\Filter;
@@ -378,7 +380,7 @@ If you want to provide a custom filter which transforms a value (eg. redirect da
378380
379381
// $customer will contain the current value of the property the filter is applied to
380382
// $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
382384
{
383385
return $data !== null ? $customer->serialize($additionalOptions) : null;
384386
}

0 commit comments

Comments
 (0)