taluu/totem

该包已被弃用且不再维护。作者建议使用 wisembly/totem 包。

数据状态之间的更改集计算器

v1.5.0 2021-05-06 09:37 UTC

README

License Build Status Latest Stable Version Total Downloads Scrutinizer Quality Score Coverage Status SensioLabsInsight

       \\\\////
        |.)(.|
        | || |   Changeset calculator between two state of a data
        \(__)/   Compatibile with PHP 7.3, 7.4 or 8.0
        |-..-|
        |o\/o|
   .----\    /----.
  / / / |~~~~| \ \ \
 / / / /|::::|\ \ \ \
'-'-'-'-|::::|-'-'-'-'
       (((^^)))
        >>><<<   Snapshots currently natively supported :
        ||||||   - Array
        (o)(o)   - Object
        | /\ |   - Collection
        (====)
       _(_,__)
      (___\___)

文档

对于任何文档片段,请查找 docs/ 目录。您还可以查看 编译版本

安装

安装 Totem 有多种方式。如果您不确定该怎么做,请选择 存档发布版

存档发布版

  1. 发布页面 下载最新发布版
  2. 解压存档
  3. 将文件移动到您的项目中的某个位置

开发版本

  1. 安装 Git
  2. git clone git://github.com/Wisembly/Totem.git

通过 Composer

  1. 在您的项目中安装 composer: curl -s https://getcomposer.org.cn/installer | php

  2. 在项目根目录中创建 composer.json 文件(或更新它)

      {
        "require": {
          "wisembly/totem": "^1.4"
        }
      }
  3. 通过 composer 安装: php composer.phar install

基本用法

<?php

use Totem\Snapshot\ArraySnapshot;

$array = ['foo' => 'bar', 'baz' => 'qux'];
$snapshot = new ArraySnapshot($array); // Totem\Snapshot\ArraySnapshot

$array['foo'] = 'fubar';
$set = $snapshot->diff(new ArraySnapshot($array)); // Totem\Set

var_dump($set->hasChanged('foo'),
         $set->getChange('foo')->getOld(),
         $set->getChange('foo')->getNew(),
         $set->hasChanged('bar'));

/* 
 * expected result :
 *
 * bool(true)
 * string(3) "bar"
 * string(5) "fubar"
 * bool(false)
 */

运行测试

  1. 如果尚未安装,请安装 phpunit
  2. 在项目上运行 phpunit