DI: Smart @inject can look at use statements

5 years ago

greeny
Member | 406
+
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)

5 years ago

David Grudl
Nette Core | 6864
+
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.