Skip to content

Commit

Permalink
Processor: replace automatic meta cache clearing with a reset() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Jan 18, 2025
1 parent 7eef857 commit c69b42d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

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

### Changed

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

### Removed

- `DefaultProcessor` - automatic meta cache reset after main `process()` call (performance optimization)

## [0.2.0](https://github.com/orisai/object-mapper/compare/0.1.0...0.2.0) - 2024-06-22

### Added
Expand Down
9 changes: 5 additions & 4 deletions src/Processing/DefaultProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public function __construct(MetaLoader $metaLoader, RuleManager $ruleManager, Ob
$this->rawValuesMap = new RawValuesMap();
}

public function reset(): void
{
$this->metaCache = [];
}

/**
* @param mixed $data
* @throws InvalidData
Expand Down Expand Up @@ -120,10 +125,6 @@ private function processBase($data, string $class, ?Options $options, bool $init

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

if ($options->getProcessedClasses() === [$class]) {
$this->metaCache = [];
}

return [$processedData, $holder, $mappedObjectContext, $callContext];
}

Expand Down
5 changes: 5 additions & 0 deletions src/Processing/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public function processSkippedFields(
?Options $options = null
): void;

/**
* Reset object to its initial state
*/
public function reset(): void;

}

0 comments on commit c69b42d

Please sign in to comment.