phpauraphp

How to create an Aura DI container?


I installed a composer, downloaded the Aura, created an index.pxp and wrote in it:

require('vendor/autoload.php');

use Aura\Di\ContainerBuilder;
$builder = new ContainerBuilder();
$di = $builder->newInstance();

$object = $di->newInstance('Vendor\Package\ClassName');

But phpStorm says:Undefined namespase DI

And i have error: Fatal error: Class 'Aura\Di\ContainerBuilder' not found in... on line 4

I do as follows: http://auraphp.com/packages/3.x/Di/getting-started.html#1-1-1


Solution

  • In order for the composer auto-loader to pick up \Aura\Di, the dependency needs to be managed by composer.

    You can easily do this by executing

    composer require aura/di
    

    which will add the dependency to your composer.json file and register with the auto-loader.


    If you have manually downloaded and installed aura/di, you can revert that.