AutoMapper – Declarative data mapper for PHP 7

综合编程 2018-01-31 阅读原文

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()

Leonid Mamchenkov

责编内容by:Leonid Mamchenkov阅读原文】。感谢您的支持!


mac下grpc(golang server + php client)实践 目前微服务这么流行,RPC框架也是百花齐放,本文讲述一下mac下grpc的开发环境搭建,其中server端使用golang,客户端使用php。 服务端 golang grpc安装 这里列出了一个参考,由于grpc在github上的文件目录有改动,所以直接按官方的安装,会出404资源...
Angular 6 Appointment Calendar Component (TypeScri... Simple appointment scheduling application built using Angular 6. The calendar view is created using DayPilot Pro Angular 2 Calendar component. The ...
Using “Not Quite JSON” with PHP One of the odd side effects of JSON’s wide spread success is how often you’ll run across data that’s not quite json A hello world example loo...
Freek van Der Herten: When empty is not empty As PHP developers, dealing with the "helpful" automatic type shifting the language performs can sometimes be challenging. It can lead to some inte...
PHP Foreach Pass by reference: Duplicati... I just had some very strange behavior with a simple php script I was writing. I reduced it to the minimum necessary to recreate the bug: This out...