PHP code example of kaihempel / simpledi

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

    

kaihempel / simpledi example snippets


  $di = new \SimpleDI\SimpleDI();

  $di->add('author', function($name) {
    return new Author($name);
  });

  $author = $di->getAuthor($name);

  $di->add('book', function($name) use ($di) {
    return new Book($di->getAuthor($name));
  });

  $storedBook = $di->getStored()
                   ->getBook($name);