PHP code example of jshannon63 / cobalt

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

    

jshannon63 / cobalt example snippets


use Jshannon63\Cobalt\Container;

// create a default (prototype) container
$app = new Container();

// or, create a singleton-only services container
$app = new Container('shared');

// a simple binding using only the class name
$app->bind(Foo::class);

// or, bind an interface with a desired concrete implementation —
// you can swap the concrete out in one place in your code.
$app->bind(FooInterface::class, Foo::class);

// or, bind an interface or other label to a closure to directly
// control dependency injection.
$app->bind(FooInterface::class, fn () => new Foo('123-456-7890'));

// or, use array access to bind a new instance directly.
$app['Foo'] = new Foo();

$foo = $app->resolve(FooInterface::class);

// or
$foo = $app[FooInterface::class];

// or
$foo = $app->get(FooInterface::class);

$foo = $app->make(FooInterface::class, Foo::class);

$app->alias('myfoo', FooInterface::class);

$app->bind('Foo', new Foo);

$bool = $app->has('Foo');

$array = $app->getBinding($abstract);

$array = $app->getBindings();