承接 liuggio/filler-dto 相关项目开发

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

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

liuggio/filler-dto

最新稳定版本:0.1.0

Composer 安装命令:

composer require liuggio/filler-dto

包简介

Retrieve and set properties from and to a DTO

README 文档

README

It helps you to bridge DTOs and Model Entities.

Fill or retrieve properties from and to DTO objects!

filler-dto on packagist

Latest Stable Version Latest Unstable Version Total Downloads

Fast

It doesn't use the \Reflection.

Before the Cure

class Cart
{
    private $a;
    private $b;
    private $c;

    private function __construct($a, $b, $c)
    {
        $this->a = $a;
        $this->b = $b;
        $this->c = $c;
    }

    public static function startShipping(StartShippingData $data)
    {
        return new self($data->a, $data->b, null);
    }

    public static function addProduct(AddProductData $data)
    {
        return new self(null, $data->b, $data->cs);
    }
}

After the Cure

class Cart
{
    use PropertyTrait;

    private $a;
    private $b;
    private $c;

    private function __construct($dto)
    {
        $this->fillProperties($dto);
    }

    public static function startShipping(StartShippingData $data)
    {
        return new self($data);
    }

    public static function addProduct(AddProductData $data)
    {
        return new self($data);
    }
}

class StartShippingData
{
    public $a;
    public $b;
}

class AddProductData
{
    public $b;
    public $c;
}

From Request

Do you want to map an object from the Request?

use Liuggio\Filler\HTTPPropertyTrait;

class StartShippingDTO
{
    use HTTPPropertyTrait;

    private $developer;

    public function __construct(Request $request)
    {
        $this->fillPropertiesFromRequest($request);
    }
...
}

Class Controller
{
    public function startShippingAction(Request $request)
    {
        $startShipping = new StartShippingDTO($request);

        if ($this->isValid($startShipping)) ...
    }
}

Copy 2 objects

You can also use it for copy properties between 2 objects

use HTTPPropertyTrait;
$to = new DTOFromRequest();
$this->fillPropertiesFromRequest($request, $to);
// the $to object has all the var from the Request

Differences?

We needed it for an edge case, but then we have decided to release it because if you are used to develop with the Command pattern, this lib could help you to develop faster app.

More info at: verraes:decoupling-symfony2-forms-from-entities

Install

composer require liuggio/filler-dto dev-master

API

trait PropertyTrait
   fillProperties($dto)
   getAllProperties($filter = null)

trait HTTPPropertyTrait
    fillPropertiesFromRequest(Request $request, $name = '')
    copyPropertiesFromRequest(Request $request, $to)

Example

Please have a look to the tests and tests/Fixtures folders :)

Compatibility

  • = 5.4

  • hhvm

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-07-11