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 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.
// can be switched out easily on one place in your code.
  
$app->bind('FooInterface', Foo::class);
  
// or, bind an interface or other label to a closure to
// directly control dependency injection.
  
$app->bind('FooInterface', function(){
    return 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 = make(FooInterface::class, Foo());

alias('myfoo', FooInterface::class);

$instance = $app->instance('Foo', new Foo);

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


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


$array = $app->getBindings();