PHP code example of beige / psr-11

1. Go to this page and download the library: Download beige/psr-11 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/ */

    

beige / psr-11 example snippets


use Beige\Psr11\Container;

$container = new Container();

$container = new Container([
    'foo' => 'bar'
]);

$container['foo'] = 'bar';
isset($container['foo']);  // true
unset($container['foo']);

$definitionCollection = new DefinitionCollection([
    'foo' => function($container) {
        return 'bar';
    }
]);

$container = new Container([], $definitionCollection);
$container['foo'];  // bar

use Beige\Psr11\Container;
...

$definitionCollection['foo'] = function(Container $c) {
    return 'bar';
};

$definitionCollection['foo'] = function($num1, $num2) {
    return $num1 + $num2;
};

$container = new Container([], $definitionCollection);
$container->make('foo', [1, 2]);  // 3