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

Cannot instantiate abstract class BaseController if Child controller has nothing to inject #228

Open
hehachris opened this issue Dec 16, 2015 · 2 comments

Comments

@hehachris
Copy link

class MyController extends BaseController
{
    // Nothing to inject
}

abstract class BaseController
{
    /**
     * @var Foo
     * @DI\Inject("my.foo")
     */
    protected $foo;
}

If there's nothing to inject in MyController, the following error occurs:

Error: Cannot instantiate abstract class MyBundle\BaseController

Current workaround:

  • Inject something useless in MyController
@hehachris hehachris changed the title Cannot instantiate abstract class BaseController... Cannot instantiate abstract class BaseController if Child controller has nothing to inject Dec 16, 2015
@stuzzo
Copy link

stuzzo commented Dec 16, 2015

Issues related #186 and #39.

@jhonatanTeixeira
Copy link

jhonatanTeixeira commented Jun 8, 2016

Hy. i found the problem and fixed it on my local bundle, the problem happens because the annotation driver returns null when the class has no annotations and the metadata factory needs at least a reflection class to build its metadata hierarchy.

to do quick local test go to your vendors and edit the class JMS\DiExtraBundle\Metadata\Driver\AnnotationDriver

and comment out these lines:

//        if (null == $metadata->id && !$hasInjection) {
//            return null;
//        }

these are on lines 225-227

I wonder if i can send a PR removing these lines, i wonder if these lines makes any difference at all to the bundle. I've also checked out the bundle and created a test case for this issue, and entire test suit is passing with this change.

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

3 participants