定制 eppak/value 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

eppak/value

Composer 安装命令:

composer require eppak/value

包简介

Value Object Helper

README 文档

README

This is a smart dto object, is useful to transport and manipulate data. Usually a value object have getter and setter for a bunch of properties that represent data.

Installation

# composer install eppak/value

Constructor

Can be created in various modes, it accept usually an array of fields with values; the second optional parameter represent if property can be written or is readonly.

  • As new.
  • From an array.
  • From JSON

If the object need to be readonly you can istantiate a roValue object istead ov Value.

Example of Initialization

<?php
    use eppak\value;
    
    //...
    
    $data = [ 'testRead' => 'read',
              'testWrite' => 'write',
              'testReadWrite' => 'readwrite',
              'undisciplined' => 'readwrite' ];
    
    $value = new Value( $data );
    $value = new Value( $data, [ 'testRead' => static::R,
                                 'testWrite' => static::W,
                                 'testReadWrite' => static::RW ] );    

    $value = Value::fromArray( $data );
    $value = Value::fromJson( '{"test": "read"}' );

Example of reading/writing

<?php
    $testRead =  $value->getTestRead();
    $testReadWrite =  $value->getTestReadWrite();
    
    $value->setTestReadWrite('some value');
    $value->setTestRead('some value'); // Thrown an error, is read only    

Testing property existence

Properties existence can be probed as simple level or multi level, useful when value object is istanced from JSON.

<?php
    $json = Json::fromJson('{ "test": { "test1" : { "test2": { "test3" : 1} } }}');
    $testRead_present = $json->has('test');
    $testChin_present = $json->hasChain('test', 'test1>test2>test3');

Cheat sheet

Method Type Description
fromArray static Create an object from array
fromJson static Create an object from a json string
has virtual Check if a property is present
hasChain virtual Check if a chain of properties is present
getChainValue virtual Get the value of a chain of properties
duplicate virtual Create a new object identical to the current
getX virtual Get the X property
setX virtual Set the X property

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固