PHP code example of nayjest / di-hub

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

    

nayjest / di-hub example snippets


use Nayjest\DI\Hub;
# Empty hub
$hub = new Hub;

# Hub with definitions

$hub = new Hub([
  new Value('item1', $item1),
  new Value('item2', $item2),
  new Relation('item1', 'item2', $handler),
]);


# Add data directly to definition
$hub->addDefinition(new Value('item1', $data));

# Add data via callable
$hub->addDefinition(new Value('item2', function(){
   return $data;
}));