2017 © Pedro Peláez
 

library options-resolver

An extension of Symfony's OptionsResolver component

image

ebidtech/options-resolver

An extension of Symfony's OptionsResolver component

  • Thursday, October 27, 2016
  • by ebidtech
  • Repository
  • 6 Watchers
  • 1 Stars
  • 1,148 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 3 % Grown

The README.md

OptionsResolver

This projects extends Symfony's OptionsResolver component, adding some useful features. For a list of all added features please see the Usage section of this readme., (*1)

Installation

The recommended way to install is through composer., (*2)

Just create a composer.json file for your project:, (*3)

``` json { "require": { "ebidtech/options-resolver": "1.*" } }, (*4)


And run these two commands to install it: ```bash $ curl -sS https://getcomposer.org/installer | php $ composer install

Now you can add the autoloader, and you will have access to the library:, (*5)

<?php

require 'vendor/autoload.php';

Usage

This component is used exactly in the same way of the original component. For a good reference about the original component please see its documentation entry., (*6)

The component is used as follows:, (*7)

// Original component instantiation, DON'T USE THIS.
// $options = new \Symfony\Component\OptionsResolver\OptionsResolver();

// Extended component instantiation, USE THIS.
$options = new EBT\OptionsResolver\Model\OptionsResolver\OptionsResolver();

Option type casting

It is often useful to use Symfony's OptionResolver when dealing with API arguments, deserialization results, etc. However, sometimes values are given as string representations of their original values, for example, "123" instead of 123. In this case setting the allowed type to "int" won't validate, because in reality the value is a string., (*8)

To address this problem two methods have been created setCast($option, $cast) and isCast($option)., (*9)

//  Instantiates the options resolver and defines the option.
$options = new EBT\OptionsResolver\Model\OptionsResolver\OptionsResolver();
$options->setDefined('my_option');

$options->isCast('my_option'); // false, cast not set

// Marks "my_option" to be cast to bool. The cast will be applied before resolving the options.
$options->setCast('my_option', 'bool');

$options->isCast('my_option'); // true, cast already set

Allowed cast types

Currently the following cast types are allowed: * int * float * bool, (*10)

If an unsupported type cast is set an exception will be thrown. When a cast is set but the given value is not castable to that specific type, the original value is kept, and any additional validations are applied as normal., (*11)

NOTE: Currently type casting is handled with PHP's filter_var() method. For additional examples of how it converts specific cases please check the official documentation or this repository's tests., (*12)

The Versions

27/10 2016

dev-master

9999999-dev https://github.com/ebidtech/options-resolver

An extension of Symfony's OptionsResolver component

  Sources   Download

MIT

The Requires

 

The Development Requires

27/10 2016
31/03 2016
02/03 2016

v1.1.0

1.1.0.0 https://github.com/ebidtech/options-resolver

An extension of Symfony's OptionsResolver component

  Sources   Download

MIT

The Requires

 

The Development Requires

05/01 2016

v1.0.4

1.0.4.0 https://github.com/ebidtech/options-resolver

An extension of Symfony's OptionsResolver component

  Sources   Download

MIT

The Requires

 

The Development Requires

19/10 2015

v1.0.3

1.0.3.0 https://github.com/ebidtech/options-resolver

An extension of Symfony's OptionsResolver component

  Sources   Download

MIT

The Requires

 

The Development Requires

21/07 2015

v1.0.2

1.0.2.0 https://github.com/ebidtech/options-resolver

An extension of Symfony's OptionsResolver component

  Sources   Download

MIT

The Requires

 

The Development Requires

20/07 2015

v1.0.1

1.0.1.0 https://github.com/ebidtech/options-resolver

An extension of Symfony's OptionsResolver component

  Sources   Download

MIT

The Requires

 

The Development Requires