PHP code example of widefocus / parameters

1. Go to this page and download the library: Download widefocus/parameters library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

widefocus / parameters example snippets



use WideFocus\Parameters\ParameterBagFactory;

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



use WideFocus\Parameters\ParameterBagFactory;

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

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


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