heydon/uarray

允许在PHP中操作PICK动态数组,以便与RockSoftware的U2产品一起使用

v1.0.1 2013-08-27 23:09 UTC

This package is auto-updated.

Last update: 2024-09-17 14:48:54 UTC


README

允许在PHP中操作PICK动态数组

PICK动态数组是PICK操作系统在数据库中存储数组的方式。数据本身是一个单独的文本字符串,其中用分隔符插入字符串以将字符串拆分为不同的字段。

  • 属性标记 AM (\xfe) ^
  • 值标记 VM (\xfd) ]
  • 子值标记 SVM (\xdc) \

这些标记允许系统将这些字符串拆分成字段,这些字段可以由系统用于指示字段和重复值。

安装

目前仅支持通过 composer 进行安装。编辑您的composer.json文件以添加以下内容。

{
    "require": {
        // ...
        "heydon/uarray": "1.0.x"
    }
}

##示例变量

1]2]3]4]5^Value 1]Value 2]Value 3]Value 4]Value 5

示例代码

$array = new uArray("1\xfd2\xfd3\xfd4\xfd5\xfeValue 1\xfdValue 2\xfdValue 3\xfdValue 4\xfdValue 5");

$a = $array[1] // VAR<1> = 1]2]3]4]5
$a = $array[1][2] // VAR<1,2> = 2

设置值

在PICK BASIC中,您将执行以下操作以插入值

A<1,2> = 'example'

在PHP中,以下将执行。

$a = new uArray();
$a[1][2] = 'example'

此结果将与PICK等效。

]example

取消设置值

PICK/u2实际上没有真正的删除值,这将删除值并且没有“滑动分隔符”。因此,在PICK/u2 BASIC中,您将执行类似以下操作

A = 1:VM:2:VM:3
A<1,2> = ''
PRINT A ;* would result in 1]]3

在PHP中,这可以有两种方式执行。

$a = new uArray("1\xfd2\xfd3");
unset($a[2]); // or
$a[2] = '';

插入值

要将值插入到数组中,在PICK/u2中您将执行以下操作。

A = 100:VM:200:VM:300:VM:400:VM:500
INS 350 BEFORE A<1,4>

在PHP中,以下将执行。

$array = new uArray("100\xfd200\xfd300\xfd400\xfd500");

$array->ins(350, 4);

删除值

在PICK中删除值时,将执行以下操作。

A = 100:VM:200:VM:300:VM:400:VM:500
DEL A<1,3>

在PHP中执行等效操作

$array = new uArray("100\xfd200\xfd300\xfd400\xfd500");

$array->del(3);

关联数组

PICK/u2和PHP中的动态数组在本质上不同。以下是如何在PICK/u2中表示基本发票的示例

01: 10]20]30
02: Item 1]Item 2]Item 3
03: 100]200]300

在此示例中,第1行是项目编号,第2行是项目名称,第3行是成本。但在PHP中,此数组的表示方式如下。

$order = array(
  10 => array(
    'title' => 'Item 1',
    'price' => 1.00,
  ),
  20 => array(
    'title' => 'Item 2',
    'price' => 2.00,
  ),
  30 => array(
    'title' => 'Item 3',
    'price' => 3.00,
  ),
);

在PHP中保持属性对齐既不容易也不自然,因此创建了 ::fetchAssoc() 以允许更容易地操作PICK/u2关联数组。

$v = new uArray('10\xfd20\xfd30\xfeItem 1\xfdItem 2\xfdItem 3\xfe100\xfd200\xfd300');
$assoc = $v->fetchAssoc(array(2,3), 1); // tell fetchAssoc() to user attribute 2 and 3 as the values and attribute 1 as the key

echo "Item: $assoc[20][2]\n"; // to access the values

$assoc[] = array(2 => 'Item 4', 3 => 400); // Which will add an new associated value and keep all the values inline.

任何实现uAssocArraySource的对象都可以实现fetchAssoc()方法。

检查更改。

由于uArray主要是为了与RedBack一起使用而构建的,因此需要捕获更改以便可以将它们发送到后端服务器。创建了Taint标志,并在需要时可以重置以允许检测特定期间的更改。

$value = new uArray('example');
$value->resetTaint(); // Resets the taint flag.
$value->isTainted(); // checks to see if the valiable has changed.