AutoMapper – Declarative data mapper for PHP 7

综合编程 2018-01-31

AutoMapper
can map data from array/object to existing array/object or marshal a new one.

Mapping rules specified in declarative way using three simple definitions:

  • From
    definition ( From::create
    or via short function from
    ) — maps single field from source to target. Supports chainable functions:

    • ->convert(callable $callable)
      — converts input value to another one via any callable;
    • ->trim()
      — trims value to eliminate whitespaces (suitable for strings);
    • ->default($defaultValue)
      — returns default value if source field is missing;
    • ->ignoreMissing()
      — ignores target field if source field is missing;
    • ->ignoreEmpty()
      — ignores target field if source field is empty.
  • Aggregate
    definition ( Aggregate::create
    or via short function aggregate
    ) — maps multiple fields from source to single target field. Supports chainable functions:

    • ->trim()
      — trims aggregated value
    • ->ignoreEmpty()
      — ignores target field if aggregated value is empty.
  • Value
    definition ( Value::create
    or via short function value
    ) — maps constant value to target field. Supports chainable functions:

    • ->trim()
    • ->ignoreEmpty()

All missing source fields can be ignored via AutoMapper::create(...)->ignoreAllMissing()
modifier.

Leonid Mamchenkov

责编内容by:Leonid Mamchenkov (源链)。感谢您的支持!

您可能感兴趣的

Pass array with ajax and php I need to add a class to some elements based on the time without page reload ...
View message after sending How can I display an alert after a user clicks a submit button in a form? I wa...
Reverse-proxying a SOAP API accessed via PHP’... I'm documenting this here, just because it's something I imagine I might have to...
Convert string to table using php I am trying to generate the array structure as coding style so it can be used fo...
PHP creates 3D Array from Array with 3 Values For the loop creating an array with a value less than ex...