chalcedonyt/laravel-valueobject 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

chalcedonyt/laravel-valueobject

最新稳定版本:1.01

Composer 安装命令:

composer require chalcedonyt/laravel-valueobject

包简介

Helpers to implement the Value Object pattern in Laravel 5

README 文档

README

A simple implementation of the Value Object pattern (http://c2.com/cgi/wiki?ValueObject) with some helpers for Laravel 5.

Install

Via Composer

$ composer require chalcedonyt/laravel-valueobject:1.*

Once composer is finished, add the service provider to the providers array in app/config/app.php:

Chalcedonyt\ValueObject\Providers\ValueObjectServiceProvider::class

Usage

This package adds a helper generator for Value Objects to quickly create them.

php artisan make:valueobject NewValueObject

Enter the class or variable name for parameter 0 (Examples: \App\User or $user) [Blank to stop entering parameters] [(no_param)]:
 > $var1

 Enter the class or variable name for parameter 1 (Examples: \App\User or $user) [Blank to stop entering parameters] [(no_param)]:
 > $var2
<?php
namespace App\ValueObjects;

class NewValueObject extends Chalcedonyt\ValueObject\ValueObject
{
    /**
    * @var
    */
    protected $var1;

    /**
    * @var
    */
    protected $var2;

    /**
    *
    *  @param $var1
    *  @param $var2
    */
    public function __construct( $var1, $var2)
    {
        $this -> var1 = $var1;
        $this -> var2 = $var2;
    }
}

It also introduces a static method create that will return an instance of the ValueObject from an array.

$args = ['var1' => 1, 'var2' => 2];
$obj = NewValueObject::create($args);
$obj -> __toString(); //"{"var1":1,"var2":2}"

Change log

  • 1.1 You can now create a ValueObject inside a directory by specifying it in the classname, e.g. php artisan make:valueobject MyDir\\MyObject

Please see [CHANGELOG] for more information what has changed recently.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-08