PHP code example of corex / container

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

    

corex / container example snippets


$myClass = (new Container())->make(MyClass::class);

$containerBuilder = new ContainerBuilder();

$containerBuilder->bind('myClass', MyClass::class)
    ->setArgument('firstname', 'Roger');

$container = new Container($containerBuilder);

$myClass = $container->make('myClass', [
    'lastname' => 'Moore'
]);

$containerBuilder = new ContainerBuilder();

$containerBuilder->bindClass(MyClass::class);

$container = new Container($containerBuilder);
$myClass = $container->get(MyClass::class);

interface MyClassInterface
{
}

class MyClass implements MyClassInterface
{
}

$containerBuilder = new ContainerBuilder();

$containerBuilder->bindClassOnInterface(MyClass::class);

$container = new Container($containerBuilder);
$myClass = $container->get(MyClassInterface::class);