Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDeclaringClass() not safe to use #63

Closed
Danack opened this issue May 23, 2014 · 3 comments
Closed

getDeclaringClass() not safe to use #63

Danack opened this issue May 23, 2014 · 3 comments

Comments

@Danack
Copy link
Collaborator

Danack commented May 23, 2014

When you call Injector->execute on a function, and it requires a non-typehinted param which has not been defined, the error message is generated with the code:

$declaringClass = $param->getDeclaringClass()->getName();
            throw new InjectionException(
                sprintf($this->errorMessages[self::E_UNDEFINED_PARAM], $declaringClass,$param->name),
                self::E_UNDEFINED_PARAM
            );

This can be replicated with the code:

$provider = new \Auryn\Provider();
$provider->execute('functionMissingParamDefine');

exit(0);

$param->getDeclaringClass() does not always work as you would expect. If execute is called from within another class it returns that classes name. e.g. if you put the above code in a test case inside ProviderTest, it returns ProviderTest.

I encountered this by as it returns null when the execute is called from outside a class.

I will fix this when I've re-merged my code with Levi's ninja reorganisation.

@Danack
Copy link
Collaborator Author

Danack commented Jun 1, 2014

This is fixed in Danack/Auryn@8ada817 which is post PR-64.

Just to note once again, the test needs to be run outside of a class - which is why there is now a test in the bootstrap. If anyone has a better way of organising this, I am all ears.

@Danack
Copy link
Collaborator Author

Danack commented Jun 1, 2014

Hmm - it still gives the wrong information when a closure is missing a param define and it is called within a class.

$provider->prepare('\StdClass', function($obj, \Auryn\AurynInjector $injector) {
            $obj->testval = 42;
        });
        $obj = $provider->make('StdClass');

gives No definition available while attempting to provision typeless non-concrete parameter ProviderTest(obj)

@Danack
Copy link
Collaborator Author

Danack commented May 16, 2015

This was fixed during the big merge.

@Danack Danack closed this as completed May 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant