Changeset calculator between two states of a data

Overview

Totem

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

       \\\\////
        |.)(.|
        | || |   Changeset calculator between two state of a data
        \(__)/   Requires PHP 5.4 ; Compatible PHP 5.5, PHP 5.6, PHP 7 and HHVM
        |-..-|
        |o\/o|
   .----\    /----.
  / / / |~~~~| \ \ \
 / / / /|::::|\ \ \ \
'-'-'-'-|::::|-'-'-'-'
       (((^^)))
        >>><<<   Snapshots currently natively supported :
        ||||||   - Array
        (o)(o)   - Object
        | /\ |   - Collection
        (====)
       _(_,__)
      (___\___)

Documentation

For any pieces of document, please look for the docs/ directory. You may also check up the compiled version

Installation

You have multiple ways to install Totem. If you are unsure what to do, go with the archive release.

Archive Release

  1. Download the most recent release from the release page
  2. Unpack the archive
  3. Move the files somewhere in your project

Development version

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

Via Composer

  1. Install composer in your project: curl -s http://getcomposer.org/installer | php

  2. Create a composer.json file (or update it) in your project root:

      {
        "require": {
          "wisembly/totem": "^1.4"
        }
      }
  3. Install via composer : php composer.phar install

Basic Usage

<?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)
 */

Running Tests

  1. Install phpunit if not already installed
  2. Run phpunit on the project
Comments
  • Refactor main mecanism (a.k.a v2)

    Refactor main mecanism (a.k.a v2)

    Ref #35, #16 and #5

    • [x] Create the snapshot interfaces
    • [x] implement the recursive
    • [x] Refactor how the object snapshots are built
    • [x] Refactor how the array snapshots are built
    • [x] Refactor how the collection snapshot is built
    • [x] Reflect changes on the Set
    • [ ] Implement "comparator"
    • [ ] Tests
    opened by Taluu 5
  • Remove all traces of reflection in ObjectSnapshot

    Remove all traces of reflection in ObjectSnapshot

    Merry christmas @krichprollsch and @lunika, if this works as it should... :heart:

    Basically, removing all traces or dependencies towards Reflection for an ObjectSnapshot. Need to create more tests though with actual objects (see https://gist.github.com/Taluu/2ed4d1d71d5c0db291c4#gistcomment-1657274)

    • [x] Remove Reflection stuff
    • [x] Add some tests for private / protected properties

    It's a little bit hackish though, even though it is still far more optimized like this.

    opened by Taluu 2
  • Collection snapshot

    Collection snapshot

    Should fix #19 and probably fit with #21. But it is not really recursive, as there's no guarantee that an array with numerical indexed elements are collections, and if they are, if they have the same type of primary key.

    • [x] Add a ward against trying to normalize a data that is already a snapshot
    • [x] CollectionSnapshot
    • [x] Unit Tests
    • [x] Use Symfony's PropertyAccess component
    • [x] Allow to pass some options into the CollectionSnapshot (like a directive to tell the snapshot which sub-snapshot to use for each values of the collection)
    opened by Taluu 2
  • Erreur 500 quand l'URL est mal formée au lieu de 404

    Erreur 500 quand l'URL est mal formée au lieu de 404

    Comme décrit ici, lorsqu'on remplace les id par des lettres, on a une 500 au lieu d'une 404. A moins que ça soit le standard django? Quoi qu'il arrive, bug ou non, c'est pas prioritaire.

    opened by artragis 2
  • Allow to use a different Set class when computing the diff between two snapshots

    Allow to use a different Set class when computing the diff between two snapshots

    Now, we may set a different SetClass to use when calculating the diff between two snapshots

    • [x] Add a SetInterface
    • [x] Alter AbstractSnapshot to declare a setClass property
    • [x] Alter Set to add some protections while the set `is not computed yet
    • [x] Fix the tests
    • [x] Counter the BC Break on the Set class

    Some BC Breaks were introduced though (like the suppression of the constructor of the Set class and the need to call explicitly the compute method on the set)

    Fixes #5

    opened by Taluu 2
  • Get rid of the

    Get rid of the "raw data"

    The raw data which is set in the AbstractSnapshot can be wrong.

    Example : on objects, it may return the new state (references, etc) instead of the state it was when it was snapshotted.

    I added this property in order to be able to act on the real data if I ever needed it, like on the diff. I should try to find another way to do that, without really relying on the "raw state".

    enhancement BC Break 
    opened by Taluu 2
  • Shippable Integration

    Shippable Integration

    Because Shippable is a CI service that is cooler (and faster) than Travis-CI.

    But it suffers some problems at the moment (coveralls integration is not complete, and the tests results are somewhat disappointing even though it is said that everything is fine). And also because I do not have enough rights on the repo right now to use Shippable.

    So the point is, this should not be merged before everything is settled.

    opened by Taluu 1
  • Fixes #17 : Add a ChangeInterface

    Fixes #17 : Add a ChangeInterface

    Fixes #17 : Now, a ChangeInterface is available to not be delimited by an AbtractChange but something more open (like, in my case, having to extend Set and allow to fetch the "old" data and the "new" one)

    opened by Taluu 1
  • SetBuilder in Snapshots

    SetBuilder in Snapshots

    Allow to use a different Set (an extension, or something like that) in the built-in snapshots rather than only the built-in Set.

    Currently, if you want to use something else, you have to reimplement the diff method of AbstractSnapshot... Even if all it does is just changing the class used.

    enhancement won't fix 
    opened by Taluu 1
  • [Object Snapshot] ReflectionProperty::getValue() expects exactly 1 parameter, 0 given

    [Object Snapshot] ReflectionProperty::getValue() expects exactly 1 parameter, 0 given

    Occur on instantiate: $snapshot = new ObjectSnapshot($object);

    According to me in ObjectSnapshot ligne 48, $object is missing. $this->data[$reflProperty->getName()] = $reflProperty->getValue($object);

    bug done 
    opened by sogos 1
  • Added / Changed / Removed properties

    Added / Changed / Removed properties

    Instead of only see what has changed, i should soften up the Set to also accept different array sizes when computing the changeset, so it shows what has added and removed.

    Just opening an issue so that I can check it up later. Any comments on how I should proceed are welcome.

    enhancement done 
    opened by Taluu 1
  • Introduce a `Snapshotter`

    Introduce a `Snapshotter`

    Which wold be used to snapshot data with a notion of priority. This would remove the call to any normalize in built-in snapshots and thus remove this method for the AbstractSnapshot.

    As this may be a BC Break, I'm tagging this for 2.0.

    enhancement DX BC Break 
    opened by Taluu 0
  • Bump php version

    Bump php version

    Because 5.4 is now EOL for a while. Should bump to 5.6 (.. or 7 ?). As we are trying to stick close to [http://semver.org](Semantic Versionning), this should be considered on next major bump ("version 2.0")

    BC Break 
    opened by Taluu 1
  • Use a SetObject injection rather than SetClass

    Use a SetObject injection rather than SetClass

    I'm not a huge fan to inject a setClass into the AbstractSnapshot. I think it should be a SetInterface object, as an DIC would like to have.

    Just writing this issue to think about that later.

    enhancement DX BC Break 
    opened by Taluu 0
Releases(v1.5.0)
  • v1.5.0(May 6, 2021)

    A simple release, as this lib has been marked as compatible with PHP 8.0, thanks to the efforts of @marko-ilic in #40.

    This is a minor bump because the compatibility with PHP5 has been removed, with using actual maintained PHP versions instead (so 7.3+). This should be okay as just this has been changed.

    Source code(tar.gz)
    Source code(zip)
  • v1.4.3(Jan 8, 2016)

    New patch release, which optimizes things

    • #37 #34 Remove reflection in ObjectSnapshot (using an exported array instead)
    • #36 Refactor the Set switch (more readable and micro optimized)
    • #32 Some composer and travis changes

    And that's pretty much it

    Source code(tar.gz)
    Source code(zip)
  • v1.4.2(Aug 3, 2014)

    This is a tiny BC Break in 1.4, as if a key primary key is used for an array in a CollectionSnapshot, it won't work anymore. [key] or a PropertyPath should be used instead.

    • #28 : Use PropertyPath instead of a wild guess for CollectionSnapshot (81695b419d5f376ca3da041425dc17f33bbc344d)
    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Jul 23, 2014)

    • #25 : The changeset for a Collection is now numeric indexed based
    • Add a link attribute to the CollectionSnapshot
    • Prevent a bug when computing the Set
    • Fixes #24 : Propagate the setClass onto sub children
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Jul 20, 2014)

    This release introduces the CollectionSnapshot, which can make a snapshot of collection type elements. It also extends the tested code coverage to 100%, and does not abruptly normalize everything in the AbstractSnapshot's normalizer.

    Source code(tar.gz)
    Source code(zip)
  • v1.3.2(Jun 10, 2014)

  • v1.3.1(Jun 10, 2014)

  • v1.3.0(Jun 2, 2014)

    In this version, the possibility to use a whole different Set class than the default provided is now available.

    For this, a SetInterface was introduced, and as on the meaning of the Set object there was no sense whatsoever to extend the AbstractChange object, this filiation was removed.

    The possible BC Break (located on the Set constructor) was avoided, even if passing values other than null, null (which are the defaults) is deprecated and strongly discouraged.

    Source code(tar.gz)
    Source code(zip)
  • v1.2.5(May 31, 2014)

    This release is now using PSR-4 rather than PSR-0 for its autoloading feature, and changes some internal stuff, such as...

    • enhancing the coverage via coveralls.io
    • making sure that PHP 5.6 and HHVM are now supported
    • breaking the Set class
    Source code(tar.gz)
    Source code(zip)
  • v1.2.4(Jan 13, 2014)

  • v1.2.3(Nov 25, 2013)

    This release fixes a bug on the null value handling.

    If the new value was null, even if it was unchanged, modified or added, it was always considered as a Removal instead of an expected Modification, Addition or unchanged value.

    This is due to the php's isset operator which considers that null does not set a value.

    Source code(tar.gz)
    Source code(zip)
  • v1.2.2(Nov 20, 2013)

  • v1.2.1(Nov 18, 2013)

  • v1.2.0(Nov 16, 2013)

    New feature : more detailed changes on each changes. Now, instead of a Totem\ Change object (or Totem\ChangeInterface to be more precise), you'll get a Totem\AbstractChange), which can be one of the following :

    • Totem\Change\Addition if the data was added
    • Totem\Change\Modification if the data was modified
    • Totem\Change\Removal if the data was removed

    Some enhancements were also brought up on the Snapshot parts, and the constraint on the ArraySnapshot (that each keys in two snapshots must be the same if you want to compare two arrays) is now gone.

    Source code(tar.gz)
    Source code(zip)
  • v1.1(Nov 10, 2013)

  • v1.0.1(Nov 8, 2013)

    • Fixes #3 : Fixes a bug on ObjectSnapshot (ReflectionProperty was misused)
    • Enhance code coverage
    • Removed useless time verification in AbstractSnapshot
    • Simplified object comparision in Set (check only the object's hash)
    Source code(tar.gz)
    Source code(zip)
Library for (de-)serializing data of any complexity (supports JSON, and XML)

jms/serializer Introduction This library allows you to (de-)serialize data of any complexity. Currently, it supports XML and JSON. It also provides yo

Johannes 2.2k Jan 1, 2023
:lipstick: Scalable and durable all-purpose data import library for publishing APIs and SDKs.

Porter Scalable and durable data imports for publishing and consuming APIs Porter is the all-purpose PHP data importer. She fetches data from anywhere

null 594 Jan 1, 2023
A repository with implementations of different data structures and algorithms using PHP

PHP Data Structures and Algorithms Data structure and Algorithm is always important for any programming language. PHP, being one of the most popular l

Mizanur Rahman 610 Jan 2, 2023
Missing data types for PHP. Highly extendable.

Neverending data validation can be exhausting. Either you have to validate your data over and over again in every function you use it, or you have to rely it has already been validated somewhere else and risk potential problems.

SmartEmailing 82 Nov 11, 2022
This prj we have two NODEMCU ( ESP8266) and two RFID_RC522 and some rfid tags we used ARDUINO IDE on NODEMCU and running server with XAMPP

This prj we have two NODEMCU ( ESP8266) and two RFID_RC522 and some rfid tags we used ARDUINO IDE on NODEMCU and running server with XAMPP

Mohammadamir Soltanzadeh 2 Mar 29, 2022
A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc). Based on the difflib implementation in Python

PHP Diff Class Introduction A comprehensive library for generating differences between two hashable objects (strings or arrays). Generated differences

Chris Boulton 708 Dec 25, 2022
A tool that can be used to verify BC breaks between two versions of a PHP library.

Roave Backward Compatibility Check A tool that can be used to verify BC breaks between two versions of a PHP library. Pre-requisites/assumptions Your

Roave, LLC 530 Dec 27, 2022
Basic calculator made in PHP, CSS3 and JavaScript.

Basic Calculator in PHP Basic calculator in PHP made for treining. ??‍?? Used Technology PHP HTML CSS JavaScript ?? License This project is under MIT

Maria Peixoto 3 Aug 24, 2021
Unit converter and calculator for php

Unit converter and calculator This library uses the awesome lisachenko/z-engine to allow mathematical operations on objects, allowing to do stuff like

Dominik Chrástecký 8 Apr 8, 2022
A Laravel package providing a list of the countries, states, cities, currencies and timezones

A Laravel package to provide a list of the countries, cities, timezones, currencies and phone numbers formatting/validation helpers. The package can b

Najm Njeim 492 Dec 24, 2022
A simple Laravel Package to sort Countries, States and Cities

Laravel Location ▲ Introduction ?? This Package offers a simple way to get Countries, Cities and States that you may need for your Application, most e

Michael Okoh 197 Jan 1, 2023
Magento 2 Grid Colors module for colorizing admin grids. Supports saving of states with the help of grid's bookmarks.

Magento 2 Grid Colors Overview The module adds extra coloring features to admin grids at the Sales section. With help of this module, it is possible t

Dmitry Shkoliar 58 Dec 8, 2022
The Laravel eCommerce USPS Shipping module allows the store owners to enable United States Postal Servies for the shipment of orders.

Introduction Bagisto Usps Shipping add-on provides Usps Shipping methods for shipping the product. By using this, you can provide Usps (United States

Bagisto 2 May 31, 2022
States allows you to create PHP classes following the State Pattern in PHP.

States allows you to create PHP classes following the State Pattern in PHP. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and this improve maintainability and workflows writing.

Teknoo Software 10 Nov 20, 2022
HTML/PHP/CSS website that tracks two API data

Detailed instructions on how to build and run Step 1: download XAMPP for a live web server XAMPP download 1 XAMP download 2 Step 2: Download all files

Winsor Tse 0 Jun 2, 2022
Sign URLs with expiration date to transfer data between projects.

SafeLink Framework-agnostic, lightweight URL signer. You can use SafeLink to transfer data between projects. Sign the url in project 1: use Alfatron\S

Ozan Hazer 4 Feb 2, 2022
Melek Berita Backend is a service for crawling data from various websites and processing the data to be used for news data needs.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Chacha Nurholis 2 Oct 9, 2022
PHP library for Two Factor Authentication (TFA / 2FA)

PHP library for Two Factor Authentication PHP library for two-factor (or multi-factor) authentication using TOTP and QR-codes. Inspired by, based on b

Rob Janssen 896 Dec 30, 2022