承接 thruster/data-mapper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thruster/data-mapper

Composer 安装命令:

composer require thruster/data-mapper

包简介

Thruster DataMapper Component

README 文档

README

[Latest Version] (https://github.com/ThrusterIO/data-mapper/releases) [Software License] (LICENSE) [Build Status] (https://travis-ci.org/ThrusterIO/data-mapper) [Code Coverage] (https://scrutinizer-ci.com/g/ThrusterIO/data-mapper) [Quality Score] (https://scrutinizer-ci.com/g/ThrusterIO/data-mapper) [Total Downloads] (https://packagist.org/packages/thruster/data-mapper)

[Email] (mailto:team@thruster.io)

The Thruster DataMapper Component. Provides fast and efficient way to map data from one format to another.

Install

Via Composer

$ composer require thruster/data-mapper

For PHP < 7.0

For older PHP version than PHP7 there is branch php5

$ composer require thruster/data-mapper ">=1.0,<2.0"

Usage

Simple Data Mapping

class SimpleMapper extends BaseDataMapper {
    /**
     * @param Request $input
     */
    public function map($input)
    {
        return [
            'id' => $input->getId(),
            'name' => $input->getName()
        ];
    }
}

$dataMappers = new DataMappers();
$dataMappers->addMapper(new SimpleMapper());
$dataMappers->getMapper(SimpleMapper::class)->map($input);

Nested Data Mapping

class ItemMapper extends BaseDataMapper {
    /**
     * @param Request $input
     */
    public function map($input)
    {
        return [
            'id' => $input->getId(),
            'name' => $input->getName()
        ];
    }
}

class MainMapper extends BaseDataMapper {
    /**
     * @param Request $input
     */
    public function map($input)
    {
        return [
            'id' => $input->getId(),
            'name' => $input->getName(),
            'items' => $this->getMapper(ItemMapper::class)->mapCollection($input->getItems())
        ];
    }
}

$dataMappers = new DataMappers();
$dataMappers->addMapper(new MainMapper());
$dataMappers->addMapper(new ItemMapper());
$dataMappers->getMapper(MainMapper::class)->map($input);

Validateable Data Mapping

class UserRegistrationMapper extends BaseDataMapper implements ValidateableDataMapperInterface {
    /**
     * @param Request $input
     */
    public function map($input)
    {
        $user = new User();
        
        $user->setUsername($input->get('username'));
        $user->setPassword($input->get('password'));
    }

    public function supports($input) : bool
    {
        return ($input instanceof Request);
    }
    
    public function getValidationGroups($input) : array
    {
        return ['full'];
    }
}

$dataMappers = new DataMappers();
$dataMappers->setValidator(Validation::createValidator());

$dataMappers->addMapper(new UserRegistrationMapper());
$dataMappers->getMapper(UserRegistrationMapper::class)->map($input);

Standalone Data Mapping

$simpleMapper = new DataMapper(
    new class extends BaseDataMapper {
        /**
         * @param Request $input
         */
        public function map($input)
        {
            return [
                'id' => $input->getId(),
                'name' => $input->getName()
            ];
        }
    
        public function supports($input) : bool
        {
            return true;
        }
    }
);

$simpleMapper->map($input);

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

License

Please see License File for more information.

统计信息

  • 总下载量: 6.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固