Skip to content

Commit 6c82abe

Browse files
committed
Move filter interfaces into production repository for custom filters in a single class
1 parent 6547053 commit 6c82abe

File tree

12 files changed

+16
-61
lines changed

12 files changed

+16
-61
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"require": {
1414
"symplify/easy-coding-standard": "^7.2.3",
15-
"wol-soft/php-json-schema-model-generator-production": "^0.12.1",
15+
"wol-soft/php-json-schema-model-generator-production": "^0.12.2",
1616
"wol-soft/php-micro-template": "^1.3.2",
1717

1818
"php": ">=7.2",

docs/source/nonStandardExtensions/filter.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ You can implement custom filter and use them in your schema files. You must add
283283
->addFilter(new UppercaseFilter())
284284
);
285285
286-
Your filter must implement the interface **PHPModelGenerator\\PropertyProcessor\\Filter\\FilterInterface**. Make sure the given callable array returned by **getFilter** is accessible as well during the generation process as during code execution using the generated model.
286+
Your filter must implement the interface **PHPModelGenerator\\Filter\\FilterInterface**. Make sure the given callable array returned by **getFilter** is accessible as well during the generation process as during code execution using the generated model.
287287
The callable filter method must be a static method. Internally it will be called via *call_user_func_array*. A custom filter may look like:
288288

289289
.. code-block:: php
290290
291291
namespace MyApp\Model\Generator\Filter;
292292
293-
use PHPModelGenerator\PropertyProcessor\Filter\FilterInterface;
293+
use PHPModelGenerator\Filter\FilterInterface;
294294
295295
class UppercaseFilter implements FilterInterface
296296
{
@@ -391,7 +391,7 @@ The option will be available if your JSON-Schema uses the object-notation for th
391391
Custom transforming filter
392392
^^^^^^^^^^^^^^^^^^^^^^^^^^
393393

394-
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:
394+
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\\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:
395395

396396
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.
397397

@@ -400,7 +400,7 @@ The custom serializer method will be called if the model utilizing the custom fi
400400
namespace MyApp\Model\Generator\Filter;
401401
402402
use MyApp\Model\ManuallyWrittenModels\Customer;
403-
use PHPModelGenerator\PropertyProcessor\Filter\TransformingFilterInterface;
403+
use PHPModelGenerator\Filter\TransformingFilterInterface;
404404
405405
class CustomerFilter implements TransformingFilterInterface
406406
{

src/Model/GeneratorConfiguration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace PHPModelGenerator\Model;
66

77
use PHPModelGenerator\Exception\InvalidFilterException;
8+
use PHPModelGenerator\Filter\FilterInterface;
9+
use PHPModelGenerator\Filter\TransformingFilterInterface;
810
use PHPModelGenerator\PropertyProcessor\Filter\DateTimeFilter;
9-
use PHPModelGenerator\PropertyProcessor\Filter\FilterInterface;
1011
use PHPModelGenerator\PropertyProcessor\Filter\NotEmptyFilter;
11-
use PHPModelGenerator\PropertyProcessor\Filter\TransformingFilterInterface;
1212
use PHPModelGenerator\PropertyProcessor\Filter\TrimFilter;
1313
use PHPModelGenerator\Utils\ClassNameGenerator;
1414
use PHPModelGenerator\Utils\ClassNameGeneratorInterface;

src/Model/Validator/FilterValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use PHPModelGenerator\Exception\Filter\IncompatibleFilterException;
88
use PHPModelGenerator\Exception\Filter\InvalidFilterValueException;
99
use PHPModelGenerator\Exception\SchemaException;
10+
use PHPModelGenerator\Filter\FilterInterface;
11+
use PHPModelGenerator\Filter\TransformingFilterInterface;
1012
use PHPModelGenerator\Model\GeneratorConfiguration;
1113
use PHPModelGenerator\Model\Property\PropertyInterface;
12-
use PHPModelGenerator\PropertyProcessor\Filter\FilterInterface;
13-
use PHPModelGenerator\PropertyProcessor\Filter\TransformingFilterInterface;
1414
use PHPModelGenerator\Utils\RenderHelper;
1515
use ReflectionException;
1616
use ReflectionMethod;

src/PropertyProcessor/Filter/DateTimeFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PHPModelGenerator\PropertyProcessor\Filter;
66

77
use PHPModelGenerator\Filter\DateTime;
8+
use PHPModelGenerator\Filter\TransformingFilterInterface;
89

910
/**
1011
* Class DateTimeFilter

src/PropertyProcessor/Filter/FilterInterface.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/PropertyProcessor/Filter/FilterProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace PHPModelGenerator\PropertyProcessor\Filter;
66

77
use PHPModelGenerator\Exception\SchemaException;
8+
use PHPModelGenerator\Filter\TransformingFilterInterface;
89
use PHPModelGenerator\Model\GeneratorConfiguration;
910
use PHPModelGenerator\Model\Property\PropertyInterface;
10-
use PHPModelGenerator\Model\Property\Serializer\TransformingFilterSerializer;
1111
use PHPModelGenerator\Model\Schema;
1212
use PHPModelGenerator\Model\Validator;
1313
use PHPModelGenerator\Model\Validator\EnumValidator;

src/PropertyProcessor/Filter/NotEmptyFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PHPModelGenerator\PropertyProcessor\Filter;
66

7+
use PHPModelGenerator\Filter\FilterInterface;
78
use PHPModelGenerator\Filter\NotEmpty;
89

910
/**

src/PropertyProcessor/Filter/TransformingFilterInterface.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/PropertyProcessor/Filter/TrimFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PHPModelGenerator\PropertyProcessor\Filter;
66

7+
use PHPModelGenerator\Filter\FilterInterface;
78
use PHPModelGenerator\Filter\Trim;
89

910
/**

src/SchemaProcessor/PostProcessor/SerializationPostProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
namespace PHPModelGenerator\SchemaProcessor\PostProcessor;
66

77
use JsonSerializable;
8+
use PHPModelGenerator\Filter\TransformingFilterInterface;
89
use PHPModelGenerator\Interfaces\SerializationInterface;
910
use PHPModelGenerator\Model\GeneratorConfiguration;
1011
use PHPModelGenerator\Model\Schema;
1112
use PHPModelGenerator\Model\Validator\FilterValidator;
12-
use PHPModelGenerator\PropertyProcessor\Filter\TransformingFilterInterface;
1313
use PHPModelGenerator\Traits\SerializableTrait;
1414

1515
/**

tests/Basic/FilterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
use PHPModelGenerator\Exception\InvalidFilterException;
99
use PHPModelGenerator\Exception\SchemaException;
1010
use PHPModelGenerator\Exception\ValidationException;
11+
use PHPModelGenerator\Filter\FilterInterface;
12+
use PHPModelGenerator\Filter\TransformingFilterInterface;
1113
use PHPModelGenerator\Filter\Trim;
1214
use PHPModelGenerator\Model\GeneratorConfiguration;
1315
use PHPModelGenerator\PropertyProcessor\Filter\DateTimeFilter;
14-
use PHPModelGenerator\PropertyProcessor\Filter\FilterInterface;
15-
use PHPModelGenerator\PropertyProcessor\Filter\TransformingFilterInterface;
1616
use PHPModelGenerator\PropertyProcessor\Filter\TrimFilter;
1717
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
1818

0 commit comments

Comments
 (0)