Skip to content
This repository was archived by the owner on Feb 21, 2019. It is now read-only.

Conversation

OndraM
Copy link
Contributor

@OndraM OndraM commented Mar 12, 2016

Hi,
I'm using AnnotationsParser::parsePhp() method to retrieve FQN of classes in php string, then instantiating those classes using something like $reflectionClass = new \ReflectionClass($className)).

However, parsePhp() won't return name of the classes if they don't have any annotation or at least any use statement. This is quite limiting, as I want to read name of the class no mater if it has any annotations/use statements or not - the exact content of annotations could be checked later (with eg. AnnotationsParser::getAll($reflectionClass)).

Currently there is no way determining whether the file don't contain any class at all, or just class without annotations.

I prepared PoC that changed the behavior. I'm not sure if there is any reason for the current behavior or if this change would break something? If so, this behavior could be at least triggered optionally. What do you think?

Parsing this file with parsePhp() will result in null being returned:

<?php

namespace Foo;

class Bar extends Baz\Ban\AbstractBar
{
    public function do()
    {
        ...
    }
}

But this will return ['Foo\Bar' => ['use' => ['AbstractBar' => 'Baz\Ban\AbstractBar']]]:

<?php

namespace Foo;

use Baz\Ban\AbstractBar;

class Bar extends AbstractBar
{
    public function do()
    {
        ...
    }
}

@dg
Copy link
Member

dg commented Mar 12, 2016

I think that this change should not break anything but do you know that you rely on internal method?

@OndraM
Copy link
Contributor Author

OndraM commented Mar 12, 2016

I know, however, the method is really useful and I didn't find (though I tried!) any alternative library which does the job I need that simply :).

@dg
Copy link
Member

dg commented Mar 12, 2016

So please change commit message to something like: AnnotationsParser::parsePhp() ....

@OndraM
Copy link
Contributor Author

OndraM commented Mar 12, 2016

No problem! Is this all right?

@dg
Copy link
Member

dg commented Mar 12, 2016

👍

dg added a commit that referenced this pull request Mar 12, 2016
Return even classes without annotations when using parsePhp
@dg dg merged commit 3000674 into nette:master Mar 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants