2017 © Pedro Peláez
 

library tree-access

Symfony-Property-Access-like tree manipulation helper

image

ama-team/tree-access

Symfony-Property-Access-like tree manipulation helper

  • Thursday, January 11, 2018
  • by etki
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

AmaTeam\TreeAccess

Packagist CircleCI/master Coveralls/master Scrutinizer/master, (*1)

This tiny project allows to read, enumerate and write properties / elements in a nested tree consisting of arrays and objects., (*2)

It is very close to symfony/property-access, but have two differences:, (*3)

  • This library treats array elements and object properties the same way, providing a unified tree access. This may be both desirable and not, depending on real application, so property-access may be more useful for you.
  • This library allows to enumerate properties of a specific node.

Installation

composer require ama-team/tree-access

Usage

<?php

$object = new stdClass();
$object->values = ['apples' => 'green'];
$root = [$object];

$accessor = AmaTeam\TreeAccess\TreeAccess::createAccessor();

// 'green'
$color = $accessor->read($root, '0.values.apples');
// List of AmaTeam\TreeAccess\API\NodeInterface
$values = $accessor->enumerate($root, '0.values');
// NodeInterface that got updated
$accessor->write($root, '0.values.melon', 'yellow');
// false
$accessor->exists($root, '0.values.watermelon');

Setters / getters support is already bundled in, and accessing missing nodes will throw an exception (except when setting leaf of existing node)., (*4)

ActiveNode

Accessor already provides additional method that allows alternative manipulation interface:, (*5)

<?php

$object = new stdClass();
$object->values = ['apples' => 'green'];
$root = [$object];

$accessor = AmaTeam\TreeAccess\TreeAccess::createAccessor();

$activeNode = $accessor->wrap($object);
foreach ($activeNode->enumerate() as $child) {
    $child->getChild('values')->setChild('lemon', 'yellow');
    $child->setChild('processed', true);
}

Performance

As of 0.1.x, possible performance optimizations are sacrificed for ease of use. This library doesn't promote performance (at least for now) at all., (*6)

Contributing

Feel free to send PR to dev branch, (*7)

Dev branch state

CircleCI/dev Coveralls/dev Scrutinizer/dev, (*8)

Licensing

MIT License / AMA Team, 2018, (*9)

The Versions

11/01 2018

dev-master

9999999-dev

Symfony-Property-Access-like tree manipulation helper

  Sources   Download

MIT

The Requires

  • php >= 5.6

 

The Development Requires

by AMA Team

11/01 2018
11/01 2018

dev-release/0.1

dev-release/0.1

Symfony-Property-Access-like tree manipulation helper

  Sources   Download

MIT

The Requires

  • php >= 5.6

 

The Development Requires

by AMA Team

11/01 2018
11/01 2018

dev-feature/inspective-interface

dev-feature/inspective-interface

Symfony-Property-Access-like tree manipulation helper

  Sources   Download

MIT

The Requires

  • php >= 5.6

 

The Development Requires

by AMA Team

11/01 2018