2017 © Pedro PelĂĄez
 

library optionally

A container for keyed booleans.

image

aviator/optionally

A container for keyed booleans.

  • Saturday, December 2, 2017
  • by danielsdeboer
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Build Status Latest Stable Version License, (*1)

Overview

Optionally is a keyed store of booleans. It can be used for anything but usually to store options., (*2)

Installation

Via Composer:, (*3)

composer require aviator/optionally

Testing

Via Composer:, (*4)

composer test

Usage

Instantiate Optionally with or without an array. You can add the array later with add() or replaceWith() (see below)., (*5)

The array should have string keys and boolean values. It's important to note that any pairs with non-string keys and non-boolean values will be silently discarded—they will not be coerced., (*6)

$options = Optionally::make([
    'option1' => true, 
    'option2' => false, 
    0 => false, 
    'test' => 'value'
]);

// [0 => false] and ['test' => 'value'] will be discarded.

Get the underlying array with all():, (*7)

$options->all();

// ['option1' => true, 'option2' => false]

Get the keys of the underlying array with keys():, (*8)

$options->keys();

// ['option1', 'option2']

Get the value of a key if it exists (or null if it doesn't) with get():, (*9)

$options->get('option1');

// true

$options->get('someOptionThatDoesntExist');

// null

Find whether or not a key exists with has():, (*10)

$options->has('option2');

// true

$options->has('someOptionThatDoesntExist');

// false

Trash the existing options and replace them with replaceWith():, (*11)

$options->replaceWith(['option3' => true, 'option4' => false]);

$options->all();

// ['option3' => true, 'option4' => false]

Add a new array to the existing options array, overwriting existing keys with add():, (*12)

$options->add(['option1' => false, 'option3' => true]);

$options->all();

// ['option1' => false, 'option2' => false, 'option3' => true]

Set a single key value pair with set():, (*13)

$options->set('option3', false);

$options->all();

// ['option1' => true, 'option2' => false, 'option3' => false]

Trash a single key value pair with remove():, (*14)

$options->remove('option1');

$options->all();

// ['option2' => true]

An instance of Optionally is iterable:, (*15)

foreach ($options as $key => $value) {
    /* ... */
}

It's also countable:, (*16)

count($foreach);

// 2

Other

License

This package is licensed with the MIT License (MIT)., (*17)

The Versions

02/12 2017

dev-master

9999999-dev https://github.com/danielsdeboer/optionally

A container for keyed booleans.

  Sources   Download

MIT

The Requires

 

The Development Requires

php php7 options

02/12 2017

0.1.1

0.1.1.0 https://github.com/danielsdeboer/optionally

A container for keyed booleans.

  Sources   Download

MIT

The Requires

 

The Development Requires

php php7 options

02/12 2017

0.1.0

0.1.0.0 https://github.com/danielsdeboer/optionally

A container for keyed booleans.

  Sources   Download

MIT

The Requires

 

The Development Requires

php php7 options