2017 © Pedro Peláez
 

library dotnot

Access your data with dot notation. Array or objects: no matter what!

image

simones/dotnot

Access your data with dot notation. Array or objects: no matter what!

  • Sunday, September 18, 2016
  • by SimoneS
  • Repository
  • 1 Watchers
  • 2 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

Access you data via dot-notation, no matter if it's an array, a stdClass or a custom object!, (*2)

Install

$ composer require simones/dotnot

Usage

Construct a DotNot instance with your data and access it with the get method: that's all! Your data can be composed of any combination of arrays, stdClass instances and custom classes' instances: they all behave the same. You can also use the dotnot helper function, which accepts a mandatory $root argument and an optional $path to resolve., (*3)

Here are some examples (for more, head to the spec):, (*4)

// stdClass + array
dotnot((object) [
    'author' => [
        'name' => 'Simone Salerno'
    ]
])->get('author.name')

// Custom class, with getter method
class Author {
    public function getAuthorName() {
        return 'Simone Salerno';
    }
}

// this looks for a method named "get" . ucfirst($getter)
dotnot(new Author)->get('authorName')

// when it can't resolve the path, it throws an exception
// so you should catch it or test for existence
dotnot(new Author)->get('foo') // throws DotNotException
//or
$dotnot = dotnot(new Author);

if ($dotnot->has('foo')) {
    // do some work...
}

// it also works with numeric indexes
dotnot([
    'people' => [
        0 => (object) [
            'author' => new Author
        ]
    ]
])->get('people.0.author.authorName')

The Versions

18/09 2016

dev-master

9999999-dev

Access your data with dot notation. Array or objects: no matter what!

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

by Simone Salerno

15/09 2016

1.0.0

1.0.0.0

Access your data with dot notation. Array or objects: no matter what!

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

by Simone Salerno