PHP code example of ozziest / di

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

    

ozziest / di example snippets

 

class CustomModel {
    
    public function __construct(IDB $db)
    {
        
    }
    
}

class MyController {
    
    public function __construct(IModel $model, IRepository $repository, CustomModel $model)
    {
        
    }
    
}

Ozziest\DI::bind('IModel', 'MyModel');
Ozziest\DI::bind('IRepository', 'MyRepository');
Ozziest\DI::bind('IDB', 'MyDB');

$instance = Ozziest\DI::resolve('MyController');

// equals this
$instance = new MyController(
    new MyModel(), 
    new MyRepository(), 
    new CustomModel(new MyDB())
);