PHP code example of mohamed-amine / ioc-container

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

    

mohamed-amine / ioc-container example snippets


  IOC\IOC::createContainer();

  IOC\IOC::container()->build('namespace\MyClass');

  // instead of doing this
  new MyClass(new ClassA(), new ClassB());
  // you can just do this and it will create ClassA & ClassB and pass them automatically
  IOC\IOC::container()->build('namespace\MyClass');
  

  ...
  public function __constructor(ClassA $classa, ClassB $classb) {...}
  ...
  

  IOC\IOC::container()->build('namespace\MyClass', $argument1, $argument2);

  IOC\IOC::bind('MyClass',function() {
    return new namespace\MyClass();
  });

  IOC\IOC::container()->MyClass;
  // or 
  IOC\IOC::container()->get('MyClass');

  IOC\IOC::container()->register('MyClass', namespace\MyClass::class);

  IOC\IOC::container()->build('MyClass');

  IOC\IOC::container()->registerType('SomeInterface', Namespace\SomeClass::class);

  IOC\IOC::container()->MyInstance;
  // Or
  IOC\IOC::container()->get('MyInstance');