DataMutator API
Complete API reference for DataMutator.
Constructor
Section titled “Constructor”__construct(array &$data)
Section titled “__construct(array &$data)”Create a new DataMutator instance.
$mutator = new DataMutator($data);Static Methods
Section titled “Static Methods”make(array &$data): self
Section titled “make(array &$data): self”Create a new instance (fluent).
$mutator = DataMutator::make($data);Set Methods
Section titled “Set Methods”set(string $path, mixed $value): self
Section titled “set(string $path, mixed $value): self”Set value at path.
$mutator->set('user.name', 'John Doe');setMultiple(array $values): self
Section titled “setMultiple(array $values): self”Set multiple values.
$mutator->setMultiple([ 'user.name' => 'John', 'user.email' => 'john@example.com',]);Unset Methods
Section titled “Unset Methods”unset(string $path): self
Section titled “unset(string $path): self”Remove value at path.
$mutator->unset('user.password');unsetMultiple(array $paths): self
Section titled “unsetMultiple(array $paths): self”Remove multiple paths.
$mutator->unsetMultiple(['user.password', 'user.token']);Merge Methods
Section titled “Merge Methods”merge(string $path, array $value): self
Section titled “merge(string $path, array $value): self”Merge array at path.
$mutator->merge('user.settings', ['theme' => 'dark']);mergeRecursive(string $path, array $value): self
Section titled “mergeRecursive(string $path, array $value): self”Recursively merge array.
$mutator->mergeRecursive('config', $newConfig);Array Methods
Section titled “Array Methods”push(string $path, mixed $value): self
Section titled “push(string $path, mixed $value): self”Push value to array.
$mutator->push('user.tags', 'admin');pull(string $path, mixed $default = null): mixed
Section titled “pull(string $path, mixed $default = null): mixed”Remove and return value.
$value = $mutator->pull('user.temp_data');Transform Methods
Section titled “Transform Methods”transform(string $path, callable $callback): self
Section titled “transform(string $path, callable $callback): self”Transform value at path.
$mutator->transform('user.name', fn($v) => strtoupper($v));Utility Methods
Section titled “Utility Methods”toArray(): array
Section titled “toArray(): array”Get modified array.
$data = $mutator->toArray();getReference(): array
Section titled “getReference(): array”Get reference to array.
$ref = &$mutator->getReference();See Also
Section titled “See Also”- DataMutator Guide - Complete guide
- Dot-Notation - Path syntax