Giter VIP home page Giter VIP logo

treewalker's People

Contributors

clicks avatar ecappa avatar lukascivil 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

treewalker's Issues

Array comparision

An empty array in a structure equals a structure without this array.

Next tag date?

Lukas,

When is the next tag coming? This would help lower the stability level in Packagist

nested array in result

HI, thanks for this fantastic code...

i have a litlle problem.
Im receiving this answer with this
$treewalker->getdiff($json1, $json2);

array:3 [▼
"new" => array:63 [▼
"shipping/id" => "123456"

how can i do to receive the array like array ?

array:3 [▼
"new" => array:63 [▼
"shipping" => array [
"id" => "21665181130"

thanks !!

How to get only new values from diff and keep the original structure ?

Hello,

I would like to use this cool php library to store only overrided value of JSON config files inside a database.

I just need to have the modified value with original structure, I don't need to keep the pretty useless oldvalue.

How can I easily do that (without recursively delete all old value and move the new one) ?

Thanks for your work.

array con indices numericos

en la linea 188 dice

if ($key != "_id") {

deberia decir

if ($key !== "_id") {

porque si viene un array con indices numericos
por ej

nombres = ['juan', 'ramon', 'gonzalo']

al hacer el diff devuelve

nombres/ = juan
nombres/1/ = ramon
nombres/2/ = gonzalo

Array comparison : missing index '0'

Hi,
When I compare 2 array (no key, just array for the root element), structPathArray miss the first 'key'.
I had to add to change your test :
$path = $currentpath !== '' ? $currentpath . "/" . $key : sprintf($key);

Do you prefer a pull request ?

walker() function corrupts tree

Hello,

I have the following problem. I want to walk through a tree and give all nodes with the key equal "key" a new increasing number (starting at 100). But after walker() function the tree is corrupted:

$tree = '{"key":"root_1","title":"root","children":[{"title": "Node 1", "key": "1"},{"key":"2","title":"Folder 2","children":[{"key":"3","title":"Node 2.1"},{"key":"4","title":"Node 2.2"}]}]}';
$tree = json_decode($tree, true);
print_r($tree);
        
$counter = 100;
$treewalker = new TreeWalker([]);
$treewalker->walker($tree, function(&$tree, $key, &$value) use (&$counter) {
  if ($key == "key") {
    $value = $counter++;
  }
});
print_r($tree);

The code above has the following output:

Array
(
    [key] => root_1
    [title] => root
    [children] => Array
        (
            [0] => Array
                (
                    [title] => Node 1
                    [key] => 1
                )

            [1] => Array
                (
                    [key] => 2
                    [title] => Folder 2
                    [children] => Array
                        (
                            [0] => Array
                                (
                                    [key] => 3
                                    [title] => Node 2.1
                                )

                            [1] => Array
                                (
                                    [key] => 4
                                    [title] => Node 2.2
                                )

                        )

                )

        )

)
Array
(
    [key] => 100
    [title] => root
    [children] => Array
        (
            [0] => 101
            [1] => Array
                (
                    [key] => 102
                    [title] => Folder 2
                    [children] => Array
                        (
                            [0] => 103
                            [1] => Array
                                (
                                    [key] => 104
                                    [title] => Node 2.2
                                )

                        )

                )

        )

)

Could you please look into this issue?
I use PHP 5.6.24 and the latest Treewalker.php (17.02.2018)

Best regards,
Mario

Check only keys, not values

Hey thanks for this nice lib.

Is there any way of just checking the keys / labels and ignoring the values?

Treewalker with integer values

I'm seeing an issue with Treewalker flagging integer values as edited, even though they are unchanged.

For example I get the following data snippet from an aws config file:

{
    "LoadBalancerAttributes": {
        "crossZoneLoadBalancing": {
            "enabled": false
        },
        "accessLog": {
            "enabled": false
        },
        "connectionDraining": {
            "enabled": false,
            "timeout": 300
        },
        "connectionSettings": {
            "idleTimeout": 60
        },
        "additionalAttributes": []
    },
    "LoadBalancerPolicies": [],
    "Tags": [
        {
            "key": "Name",
            "value": "zabbix-server-dev"
        }
    ]
}

One hour later, I get query aws again and get an identical result but Treewalker reports the following:

{
  "new":[
    
  ],
  "removed":[
    
  ],
  "edited":{
    "LoadBalancerAttributes/connectionDraining/timeout":{
      "oldvalue":300,
      "newvalue":300
    },
    "LoadBalancerAttributes/connectionSettings/idleTimeout":{
      "oldvalue":60,
      "newvalue":60
    }
  }
}

The values are unchanged, so why does Treewalker report them as edited?

nested array

Hi, i face an issue. I had two array and need a nested array instead of parent/child, it will be more usefully in my case parent => [child => [] ].

My full example, first the arrays to compare, the original result and the desire result.

	$array1 = array(
		0 => array(
			"key" => "val",
			"etc" => "val",
		),
	);
	$array2 = array(
		0 => array(
			"key" => "val1",
			"etc" => "val2",
		),
	);

	$array1 = array(
		"edited" =>
			array(
				"0/key" => array( "oldvalue" => "val", "newvalue" => "val1" ),
				"0/etc" => array( "oldvalue" => "val", "newvalue" => "val2" )
			)
	);

	$array1 = array(
		"edited" =>
			array(
				"0" => array(
					"key" => array( "oldvalue" => "val", "newvalue" => "val1" ),
					"etc" => array( "oldvalue" => "val", "newvalue" => "val1" )
				),
			)
	);

Thanks in advance for your help

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.