DI: Smart @inject can look at use statements

Notice: This thread is very old.
greeny
Member | 405
+
0
-

Hi,

it would be nice, if @inject annotations in presenters, etc. will be smarter.

<?php

namespace Foo\Bar;

use Nette\Security;
use Nette\Security\User;
use Nette\Security\Identity as NIdentity;

class TesterClass {

    /**
     * @inject
     * @var TesterClass
     */
    public $testerClass;

    /**
     * @inject
     * @var Security\IAuthenticator
     */
    public $authenticator;

    /**
     * @inject
     * @var User
     */
    public $user;

    /**
     * @inject
     * @var NIdentity
     */
    public $identity;
?>

I tried to implement this, see pull . What do you think about it?

Last edited by greeny (2014-02-23 11:49)

David Grudl
Nette Core | 8218
+
0
-

It is not possible because PHP has no API for checking use statements…

Yes, in Nette is AnnotationsParser::expandClassName(), but it requires to parse whole PHP file, so it is very slow.