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

Allow custom getRepository()-like methods #1276

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

theredled
Copy link

@theredled theredled commented Jan 20, 2019

getRepository() currently only support direct calls to ManagerRegistry::getRepository or ObjectManager::getRepository.
This PR supports other methods - typically shortcuts in Controllers - as soon as they use ObjectRepository or a child class as a PHP code return type.

Note : seems hard to support PHPDoc.

Example :

Class MyClass {
  public function getRepo($class): ObjectRepository {}
}

$c = new MyClass();
$c->getRepo(MyEntity::class)-> // Gives access to MyEntity repository methods

@theredled theredled changed the title Allow custom getRepository() methods Allow custom getRepository()-like methods Jan 20, 2019
@theredled
Copy link
Author

theredled commented Jan 20, 2019

I'm only wondering about that part in ObjectRepositoryTypeProvider :

public PhpType getType(PsiElement e) {
// ...
        if(!(e instanceof MethodReference)
                /*|| !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "getRepository") */
        ) {
            return null;
        }
// ...
}

Maybe removing that commented line as I did is too permissive and can cause performance issues? If so, we could narrow the matching methods to "get*" for example...

@Haehnchen
Copy link
Owner

@theredled yes this mentioned method check is for performance and also to not overflow the phpstorm signatures for every method. By removing this simply we are saying we are responsible for all methods.

We need some filtering here. But for now i just see to support it via a configuration.

Another way would be by using the "php7 returns" and index every file to get "getRepo" automaticcally. But as the index is build inside "getType" we dont have access to it at this point. So this must then be cached. So would be a bigger task.

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

Successfully merging this pull request may close these issues.

None yet

2 participants