pangolinkeys/php-binders

一个简化数组组合的存储库。

v1.01 2017-11-26 16:55 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:06 UTC


README

一个简化数组组合的 PHP 存储库。

使用方法

Bindable 作为特性添加到目标类上。

use Bindable;

实现 getKeys() 方法,让绑定方法知道数组是如何键控的。

public function getKeys()
{        
    return array_keys($this->data);
} 

创建一个以目标属性名称后缀的 get 方法,该方法接受从 getKeys() 方法传递的单个键,并返回数组中所需位置的引用。

public function &getAge($person)
{
    return $this->data[ $person ]['Age'];
}

最后,调用 bind 并传递第二个对象以及绑定应发生的键。

$people->bind($preference, 'Age');

这些方法应在两个类中适当实现。

示例

这个功能的工作示例可以在 /example 目录中找到。