2017 © Pedro Peláez
 

library object-path

Fork of peridot-php/object-path. A string syntax to fetch values from array and object hierarchies

image

vicary/object-path

Fork of peridot-php/object-path. A string syntax to fetch values from array and object hierarchies

  • Tuesday, July 26, 2016
  • by vicary
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

ObjectPath Build Status

Allows traversal of objects and arrays with a simple string syntax. Extracted from Peridot's matcher library: Leo., (*1)

Usage

use Peridot\ObjectPath\ObjectPath;

// Works with nested arrays, objects, or a mixture of both.
$data = [
  'name' => 'Brian',
  'hobbies' => [
    'reading',
    'programming',
    'lion taming'
  ],
  'address' => new stdClass()
  [
    'street' => '1234 Lane',
    'zip' => '12345'
  ]
];

$data['address']->street = '1234 Lane';
$data['address']->zip = 12345;

// Wraps the value with ObjectPath
$path = new ObjectPath($data);

// Get the value directly
$reading = $path->{'hobbies[0]'};
$zip = $path->{'address[zip]'};

// Sets the value
$path->{'address->street'} = '12345 Street';

// Removes the property
unset($path->{'hobbies[2]'});



// backward compatible with peridot-php/object-path
$reading = $path->get('hobbies[0]');
$zip = $path->get('address[zip]');

// the result of get() is an ObjectPathValue instance
$value = $reading->getPropertyValue();

Tests

$ composer install
$ vendor/bin/peridot specs/

The Versions

26/07 2016

dev-master

9999999-dev

Fork of peridot-php/object-path. A string syntax to fetch values from array and object hierarchies

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Vicary Archangel

array object traversal

26/07 2016

1.1.0

1.1.0.0

A string syntax to fetch values from array and object hierarchies

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

array object traversal

24/07 2015

1.0.0

1.0.0.0

A string syntax to fetch values from array and object hierarchies

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

array object traversal