Skip to content

Commit c69b42d

Browse files
committed
Processor: replace automatic meta cache clearing with a reset() method
1 parent 7eef857 commit c69b42d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- `ArrayShapeRule` - allows processing of arrays with predefined keys
1313
- `ArgsFieldContext` - args validation context which adds access to the property's default value
14+
- `Processor` - `reset()` method for resetting to initial state (clearing meta cache)
1415

1516
### Changed
1617

@@ -31,6 +32,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3132
- `ArrayShapeType`
3233
- `getFields()` always returns the same instances
3334

35+
### Removed
36+
37+
- `DefaultProcessor` - automatic meta cache reset after main `process()` call (performance optimization)
38+
3439
## [0.2.0](https://github.com/orisai/object-mapper/compare/0.1.0...0.2.0) - 2024-06-22
3540

3641
### Added

src/Processing/DefaultProcessor.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public function __construct(MetaLoader $metaLoader, RuleManager $ruleManager, Ob
6868
$this->rawValuesMap = new RawValuesMap();
6969
}
7070

71+
public function reset(): void
72+
{
73+
$this->metaCache = [];
74+
}
75+
7176
/**
7277
* @param mixed $data
7378
* @throws InvalidData
@@ -120,10 +125,6 @@ private function processBase($data, string $class, ?Options $options, bool $init
120125

121126
$processedData = $this->processData($data, $mappedObjectContext, $callContext);
122127

123-
if ($options->getProcessedClasses() === [$class]) {
124-
$this->metaCache = [];
125-
}
126-
127128
return [$processedData, $holder, $mappedObjectContext, $callContext];
128129
}
129130

src/Processing/Processor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ public function processSkippedFields(
4646
?Options $options = null
4747
): void;
4848

49+
/**
50+
* Reset object to its initial state
51+
*/
52+
public function reset(): void;
53+
4954
}

0 commit comments

Comments
 (0)