PHP code example of ericsnguyen / simple-di

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

    

ericsnguyen / simple-di example snippets


use SimpleDi\Annotations\Export;
use SimpleDi\Annotations\Import;

/**
* @Export()
 */
class TrainingPlanController extends AbstractController
{
    /**
     * @Import()
     * @var MessageFactory
     */
    protected MessageFactory $mf;
    /**
     * @Import()
     * @var CourseService
     */
    protected CourseService $courseService;
}

// you can put your `array` that act as your old DI container to it as param
$container = new class implements \SimpleDi\Container\IContainer(){
    // in my library we have SdContainer class that implements IContainer
    // but you can implement one if you want.
};

$register = [
    YourInterface::class=> YourImplementClass:class
];

SimpleDi::build([
       // I have a variable $GLOBALS act as an instances holder for my container
      'container'=>new SdContainer($GLOBALS),
      // an $register array.
      'registry'=> 

 // at my routes table reader.
$controller = App::resolver($controllerName);
bash
PROJECT=application FILE=proxy/registry.php ./vendor/ericsnguyen/simple-di/bin/generate