PHP code example of nerd-framework / nerd-container

1. Go to this page and download the library: Download nerd-framework/nerd-container 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/ */

    

nerd-framework / nerd-container example snippets


$container = new \Nerd\Framework\Container\Container();

$container->bind('foo', Foo::class);

$container->bind('factory', function () {
  return new Factory();
});

$container->singleton('single', SingletonService::class);

$foo = $container->get('foo');

$result = $container->invoke(function (FooFactoryInterface $factory) {
  // $foo will be injected using parameter name
  // $other will be injected using Bar type hint
  return $factory->makeFoo();
});

$result = $container->invoke(function ($foo, $a, $b) {
  //
}, ["a" => "Hello", "b" => "World"]);