Random thoughts

aura dot di 2 dot x to 3 dot x upgrade guide

3.x has a very minimal BC break. But if you are not sure what are they, then you may feel the pain. I am trying to document most of them, incase I missed please edit and send a pull request.

I will try to eventually pushed to the main Aura.Di repo.

BC Breaks

Instantiation

The way di container is instantiated has been changed from

<?php
use Aura\Di\Container;
use Aura\Di\Factory;
use Aura\Di\ContainerBuilder;

$di = new Container(new Factory);

// or 

$container_builder = new ContainerBuilder();
$di = $container_builder->newInstance(
    array(),
    array(),
    $auto_resolve = false
);

to

<?php
use Aura\Di\ContainerBuilder;

$container_builder = new ContainerBuilder();

// use the builder to create and configure a container
// using an array of ContainerConfig classes
$di = $container_builder->newConfiguredInstance([
    'Aura\Cli\_Config\Common',
    'Aura\Router\_Config\Common',
    'Aura\Web\_Config\Common',
]);

setter vs setters

$di->setter is now $di->setters. Please note there is an additional s in the end. https://github.com/auraphp/Aura.Di/issues/115.

Automatic locking

Automatic locking of container once an object is created by container. So make sure everything is lazy call, else you will run something like Cannot modify container when locked.

Config vs ContainerConfig

Version 2 Aura\Di\Config is now Aura\Di\ContainerConfig

Features

lazyGetCall

Example taken from Radar

$di->params['Radar\Adr\Handler\RoutingHandler']['matcher'] = $di->lazyGetCall('radar/adr:router', 'getMatcher');

Here the matcher assigned is taken from the RouterContainer getMatcher method.

Instance Factories

Create multiple instances of the class. You can read the docs

Menu