jzaleski/php-open_struct 问题修复 & 功能扩展

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

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

jzaleski/php-open_struct

Composer 安装命令:

composer require jzaleski/php-open_struct

包简介

A very flexible data-structure (inspired by Ruby's `ostruct` library)

README 文档

README

Build Status

A very flexible data-structure (inspired by Ruby's ostruct library)

Requirements

This library requires PHP 5.4+

Installation

You can easily install Open_Struct with the following command:

composer [global] require 'jzaleski/php-open_struct=*'

Usage

Creating a new [empty] instance:

$struct = new Open_Struct;

Creating a new instance from an array of attributes:

$struct = new Open_Struct(['foo' => 1, 'bar' => ['biz' => 2]]);

Dereferencing a top-level value:

$value = $struct->foo;

Getting a top-level value by index/key:

$value = $struct['foo'];

Dereferencing a nested value:

$nested_value = $struct->bar->biz;

Getting a nested value by index/key:

$nested_value = $struct['bar']['biz'];

Setting a top-level value:

$struct->foo = 2;

Setting a top-level value by index/key:

$struct['foo'] = 2;

Setting a nested value:

$struct->bar->biz = 3;

Setting a nested value by index/key:

$struct['bar']['biz'] = 3;

Unsetting a top-level value:

unset($struct->foo);

Unsetting a top-level value by index/key:

unset($struct['foo']);

Checking for the existence of a key:

isset($struct->foo);

Checking for the existence of a key by index/key:

isset($struct['foo']);

Setting a callback value (this is useful for scenarios where you want to derive or lazy-load a property):

$dao = new Data_Access_Object;

$struct = new Open_Struct(['something' => function() use ($dao) { return $dao->get_something(); }]);

$struct->something;

The dirty method will return false until initialization (the constructor) is complete:

$struct = new Open_Struct(['foo' => 1]);

$struct->dirty(); // returns: `false`

The dirty method will return true, after initialization (the constructor), when a value is set:

$struct = new Open_Struct;

$struct->foo = 1;

$struct->dirty(); // returns: `true`

The dirty method will return false, after initialization (the constructor), when a value is set back to its original state:

$struct = new Open_Struct(['foo' => 1]);

$struct->foo = 2;

$struct->dirty(); // returns: `true`

$struct->foo = 1;

$struct->dirty(); // returns: `false`

Getting the array of attributes:

$struct = new Open_Struct(['foo' => 1]);

$struct->foo = 2;

$struct->bar = 3;

$struct->attributes(); // returns: `['foo' => 2, 'bar' => 3]`

Getting the array of changed attributes:

$struct = new Open_Struct(['foo' => 1]);

$struct->bar = 2;

$struct->changed_attributes(); // returns: `['bar' => 2]`

The changed_attributes method will return an empty array. after initializaiton (the constructor), when a value is set back to its original state:

$struct = new Open_Struct(['foo' => 1]);

$struct->foo = 2;

$struct->changed_attributes(); // returns: `['foo' => 2]`

$struct->foo = 1;

$struct->changed_attributes(); // returns: `[]`

Contributing

  1. Fork it ( http://github.com/jzaleski/php-open_struct/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固