2017 © Pedro Peláez
 

library array-option

Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options)

image

aedart/array-option

Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options)

  • Sunday, June 21, 2015
  • by aedart
  • Repository
  • 0 Watchers
  • 0 Stars
  • 20 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Array-Option

Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options), (*1)

Official website (https://bitbucket.org/aedart/array-option), (*2)

Contents

[TOC], (*3)

When to use this

If your component, class or method accepts options, in the form of an array (key-value pair) and you need to perform some kind of basic validation of those options, e.g. are required, data-type check and eventually also have a predefined default value., (*4)

Warning I advise you NOT to use this component, unless you really cannot specify method arguments in any other way, than in the form of an associative array., (*5)

How to install

#!console

composer require aedart/array-option 1.* 

This package uses composer. If you do not know what that is or how it works, I recommend that you read a little about, before attempting to use this package., (*6)

Quick start

The blow stated example show how to build a component, which accepts 3 options, each having a default value and a specific data-type., (*7)

#!php
<?php
use Aedart\ArrayOption\Traits\ArrayOptionsListTrait;
use Aedart\ArrayOption\AllowedOptionsList;
use Aedart\ArrayOption\Interfaces\IOptionType;

class MyComponent {

    use ArrayOptionsListTrait;

    public function __construct(){

        // Specify the allowed options
        // See Aedart\ArrayOption\Interfaces\IAllowedOption
        $allowedOptions = new AllowedOptionsList([
            [
                'name' => 'myOption',
                'type' => IOptionType::TYPE_STRING,
                'required' => true,
                'defaultValue'  => 'doIt',
                'description' => 'A single option with do-it'
            ],
            [
                'name' => 'myOtherOption',
                'type' => IOptionType::TYPE_INTEGER,
                'required' => false,
                'defaultValue'  => 27,
                'description' => 'Another custom option'
            ],
            [
                'name' => 'LastOption',
                'type' => IOptionType::TYPE_ARRAY,
                'required' => false,
                'defaultValue'  => [1, 2, 3],
                'description' => 'Special...'
            ],
        ]);

        // Set the allowed-options-list
        $this->getArrayOptionsList()->setAllowedOptionsList($allowedOptions);
    }

    public function doSomeThing(array $options){
        // Set the given options in the "options-list"
        $optionsList = $this->getArrayOptionsList();
        $optionsList->setArrayOptions($options); // Validates input, throws exceptions if something is wrong

        // Get the value OR default value for a given option
        $myOption = $optionsList->getValue('myOption');

        return $myOption;
    }

}

For additional information, please review this package’s interfaces as well as the unit tests., (*8)

License

BSD-3-Clause, Read the LICENSE file included in this package, (*9)

The Versions

21/06 2015

dev-master

9999999-dev https://bitbucket.org/aedart/array-option

Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

array options method parameters

21/06 2015

1.1.0

1.1.0.0 https://bitbucket.org/aedart/array-option

Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

array options method parameters

25/04 2015

1.0.2

1.0.2.0 https://bitbucket.org/aedart/array-option

Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

array options method parameters

03/04 2015

1.0.1

1.0.1.0 https://bitbucket.org/aedart/array-option

Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

array options method parameters

22/03 2015

1.0.0

1.0.0.0 https://bitbucket.org/aedart/array-option

Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

array options method parameters

22/03 2015

0.9.0

0.9.0.0 https://bitbucket.org/aedart/array-option

TODO

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

array options method parameters

22/03 2015

0.8.0

0.8.0.0 https://bitbucket.org/aedart/array-option

TODO

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

array options method parameters