2017 © Pedro Peláez
 

library parameters

A parameter bag implementation.

image

widefocus/parameters

A parameter bag implementation.

  • Thursday, April 27, 2017
  • by sjokki
  • Repository
  • 1 Watchers
  • 0 Stars
  • 127 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

WideFocus Parameters

Build Status Latest Stable Version License, (*1)

This package contains an implementation of a parameter bag., (*2)

Installation

Use composer to install the package., (*3)

$ composer require widefocus/parameters

Usage

Creating a bag

The package includes a factory to create a parameter bag., (*4)

<?php
use WideFocus\Parameters\ParameterBagFactory;

$factory = new ParameterBagFactory();
$bag = $factory->createBag(['foo' => 'Foo']);
if ($bag->has('foo')) {
    echo $bag->get('foo');
}

Adding and removing values.

The bag is immutable but has method to get a copy with an added or a removed value., (*5)

<?php

use WideFocus\Parameters\ParameterBagFactory;

$factory = new ParameterBagFactory();
$bag = $factory->createBag()
    ->with('foo', 'Foo')
    ->with('bar', 'Bar');

$withoutFoo = $bag->without('foo');

Settings values on a subject

A parameter setter can be used to set values on a subject. The default setter looks for setter methods on the subject., (*6)

<?php
use WideFocus\Parameters\ParameterBagFactory;
use WideFocus\Parameters\ParameterSetter;

class Subject
{
    private $foo;

    public function setFoo(string $foo)
    {
        $this->foo = $foo; 
    }

    public function getFoo(): string
    {
        return $this->foo; 
    }
}

$subject = new Subject();

$factory = new ParameterBagFactory();
$bag = $factory->createBag(['foo' => 'Foo']);

$setter  = new ParameterSetter();
$setter->setParameters($subject, $bag);
echo $subject->getFoo(); // Foo

The Versions

27/04 2017

dev-master

9999999-dev

A parameter bag implementation.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Ashoka de Wit

27/04 2017

1.0.0

1.0.0.0

A parameter bag implementation.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Ashoka de Wit