2017 © Pedro Peláez
 

library keyper

Do things based on the presence of a key

image

vnn/keyper

Do things based on the presence of a key

  • Thursday, September 24, 2015
  • by austinsmorris
  • Repository
  • 10 Watchers
  • 5 Stars
  • 15,881 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 11 Versions
  • 12 % Grown

The README.md

Keyper

Build Status, (*1)

Do things when an array has a key, (*2)

Usage

$data = [
    'key1' => 'hello',
    'nested' => [
        'one' => 1,
        'two' => 2,
        'three' => [
            'four' => 5
        ]
    ]
];

$keyper = Keyper::create($data);

//do something with a single value
$keyper->when('key1', function($value) {
    //$value == 'hello'
    print $value;
});

//drill down a nested array
$keyper->when('nested.three.four', function($value) {
    //$value == 5
    print $value;
});

//do something with multiple keys
$keyper->when(['nested.one', 'nested.two'], function($one, $two) {
    //$one == 1
    //$two == 2
    print $one + $two;
});

//compose several functions
$keyper->when(['nested.one', 'nested.two'], function($sum) {
    //$sum == 3
    print $sum;
}, function($one, $two) {
    //$one == 1
    //$two == 2
    return $one + $two; //this result gets passed to the function using $sum
});

//if you need all the specified keys to be present, use whenAll
$keyper->whenAll(['nested.one', 'nested.two'], function($one, $two) {
    //$one == 1
    //$two == 2
    print $one + $two;
});

Running tests

composer install

vendor/bin/phpunit

The Versions

24/09 2015

dev-master

9999999-dev

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Austin Morris

function array

24/09 2015

1.3.1

1.3.1.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Austin Morris

function array

05/02 2015

1.3.0

1.3.0.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Austin Morris

function array

19/08 2014

v1.2.3

1.2.3.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Austin Morris

function array

07/07 2014

v1.2.2

1.2.2.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Austin Morris

function array

07/07 2014

v1.2.1

1.2.1.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Austin Morris

function array

07/07 2014

v1.2.0

1.2.0.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Austin Morris

function array

03/05 2014

v1.1.1

1.1.1.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

function array

03/05 2014

v1.1.0

1.1.0.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

02/05 2014

v1.0.1

1.0.1.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

02/05 2014

v1.0.0

1.0.0.0

Do things based on the presence of a key

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires