rdlowrey / auryn

IoC Dependency Injector
MIT License
722 stars 65 forks source link

Delegated factory not being passed class name parameter. #10

Closed Danack closed 11 years ago

Danack commented 11 years ago

The documentation for delegates says:

NOTE: Auryn\Provider will pass the class name to be instantiated to the specified callable as its lone argument. This doesn't seem to be working.

Test is as follows.

class DelegationInvokeTestFactory {

    function __invoke($class){
        $numberOfArgs = func_num_args();

        if ($numberOfArgs == 0) {
            throw new \Exception("Error in delegation, __invoke is being called with no parameters, so factory can't see class requested.");    
        }

        if ($class === null) {
            throw new \Exception("Error in delegation, __invoke called with null parameter instead of class name.");
        }

        return new DelegationInvokeTest();
    }
}

function testInvokeDelegationParameters() {
    $injector = new Auryn\Provider(new Auryn\ReflectionPool);
    $injector->delegate('DelegationInvokeTest', 'DelegationInvokeTestFactory');
    $testObject = $injector->make('DelegationInvokeTest');
}

Expected behaviour

No exception

Actual behaviour

'Error in delegation, __invoke called with null parameter instead of class name.'

rdlowrey commented 11 years ago

This is actually a failure on my part to update the documentation. This "feature" has actually been removed on purpose. The documentation has now been updated. There were also other errors regarding delegate provisioning which have also been corrected.

The new documentation can be viewed at:

https://github.com/rdlowrey/Auryn/wiki/Advanced-Usage#delegates