Code Monkey home page Code Monkey logo

totem's Introduction

Totem

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
        (====)
       _(_,__)
      (___\___)

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

totem's People

Contributors

guillaumepotier avatar juliengrelet avatar marko-ilic avatar morliaguet avatar taluu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

totem's Issues

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.

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.

Deep snapshot

Currently, if there is an object in the properties of an object, only the sha1 will be compared (meaning that only a new object instead of the old one, not the modified one, will be compared to the old one).

The problem lies within the fact that the object is not copied, but is a reference since php5 :

<?php

class Foo {
     public $bar = 'baz';
}

$foo = new Foo;

$bar = $foo;

$foo->bar = 'fubar';

var_dump($foo->bar, $bar->bar); // will dump fubar fubar

But I also can't clone the object if it is an object, because the sha1 will differ from one clone to another, considering it to be a whole new object altogether.

I think I should check if i should, in the data generated by the snapshots, store the value into a value object setting also the type, transforming it into something I may understand... (like an object snapshot, or whatever).

Verify types between old / new snapshots before the switch

If we try to compare a ArraySnapshot or ObjectSnapshot with a null key in the new key, it bugs with a bad argument exception on AbstractSnapshot::isComparable.

I should restore the previous behaviour which checked the new and old keys in the Set class.

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.

Add a ChangeInterface

To allow to customize even further the other classes that could need some of the AbstractChange capabilities... Without extending it.

Switch to PSR-4

This is more sexy than the PSR-0. And also more maintainable, but that is another point. :)

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.

[Collection] Use PropertyPath

As Symfony's ProperyAccess was integrated with the CollectionSnapshot (cf #22), and as in a collection the whole objets should look alike (collection of objects, of arrays, ...), we should not try to modify the primary parameter.

If the snapshot is used with a collection of arrays, then we should either have a PropertyPath directly fed to the pkey argument, or a valid property path either way [key]. If it is a collection of objects, then either a PropertyPath object, either a key path.

This should be way more flexible than it actually is right now, instead of doing a wild guess depending on the types of each elements fed into the collection, which could be wrong.

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".

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")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.