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

Load Collectors by FQCN #320

Merged
merged 10 commits into from
Sep 2, 2020
Merged

Conversation

DanielBadura
Copy link
Contributor

This patch enables the registry to load collectors by FQCN if not already present in the cache the missing object gets initiated and added to the cache.

Should fix #164

@smoench
Copy link
Contributor

smoench commented Jul 10, 2020

I had this implementation also in mind then I created the issue. It will works when you directly require deptrac via composer (which is not recommended) but we need to check if it is working with the phar file.

@DanielBadura
Copy link
Contributor Author

I will look into it :)

@DanielBadura
Copy link
Contributor Author

I just tested it with a generated phar. I used for this an example depfile (ControllerServiceRepository1.depfile.yml) and it worked with it i got the same result. I just changed the type from className to the FQCN SensioLabs\Deptrac\Collector\ClassNameCollector.

Should i check more?

@smoench
Copy link
Contributor

smoench commented Jul 10, 2020

Can you create your own / custom collector and use the FQCN in the depfile? I think it doesn't work. Probably we need to check if there is a autoload file and load it. Probably we also need to enable the https://github.com/humbug/php-scoper in Box config.

@DanielBadura
Copy link
Contributor Author

Yeah, this is not working. I will look into it later

@DanielBadura
Copy link
Contributor Author

I updated the PR to load the autoload file if exists. Maybe you can already have a look on this.
I already added the scoper local but getting some errors. Im going to try to fix it the next days :)

@DanielBadura
Copy link
Contributor Author

@smoench i activated the php-scoper with the default configuration and tried to execute deptrac. I get an error which i could not resolve, maybe you can help with that.

$ ./deptrac.phar
 0/3 [>---------------------------]   0%PHP Fatal error:  Uncaught TypeError: Return value of _HumbugBoxeae4e57508d1\SensioLabs\Deptrac\AstRunner\AstParser\AstFileReferenceFileCache::get() must be an instance of _HumbugBoxeae4e57508d1\SensioLabs\Deptrac\AstRunner\AstMap\AstFileReference or null, instance of __PHP_Incomplete_Class returned in phar:///srv/share/deptrac.phar/src/AstRunner/AstParser/AstFileReferenceFileCache.php:47
Stack trace:
#0 phar:///srv/share/deptrac.phar/src/AstRunner/AstParser/NikicPhpParser/NikicPhpParser.php(55): _HumbugBoxeae4e57508d1\SensioLabs\Deptrac\AstRunner\AstParser\AstFileReferenceFileCache->get()
#1 phar:///srv/share/deptrac.phar/src/AstRunner/AstRunner.php(30): _HumbugBoxeae4e57508d1\SensioLabs\Deptrac\AstRunner\AstParser\NikicPhpParser\NikicPhpParser->parse()
#2 phar:///srv/share/deptrac.phar/src/Analyser.php(27): _HumbugBoxeae4e57508d1\SensioLabs\Deptrac\AstRunner\AstRunner->createAstMapByFiles()
#3 phar:///srv/share/deptrac.phar/src/Console/Command/AnalyzeCommand.php(54): _HumbugBoxeae4e57508d1\SensioLabs\Deptrac\Analyser->analys in phar:///srv/share/deptrac.phar/src/AstRunner/AstParser/AstFileReferenceFileCache.php on line 47

I did some research but found nothing that helped me.

@smoench
Copy link
Contributor

smoench commented Jul 20, 2020

I think this is a problem with the cache file. With --no-cache it should work. In your cache file there might be still the unscoped classnames written but the allowed_classes for unserialize have the scoped ones -> https://github.com/sensiolabs-de/deptrac/blob/master/src/AstRunner/AstParser/AstFileReferenceFileCache.php#L111

Can you try to add a config for php-scoper with excluding SensioLabs\Deptrac\* from scoping -> https://github.com/humbug/php-scoper#namespaces-whitelisting

@DanielBadura
Copy link
Contributor Author

You were right, with --no-cache i got rid of the error and with the whitelist it is now working 🚀

So this would be finished from my side and would also fix #19 or not?

@smoench smoench added this to the 0.9 milestone Jul 20, 2020
@smoench
Copy link
Contributor

smoench commented Jul 21, 2020

Thank you @DanielBadura! I will try it out on Friday and give you feedback

@DanielBadura
Copy link
Contributor Author

@smoench did you had time to try it out?

@smoench
Copy link
Contributor

smoench commented Aug 3, 2020

Sorry, I was on vacation. I will try it out asap.

@DanielBadura
Copy link
Contributor Author

No problem! Hope you had a nice vacation! :)

Copy link
Contributor

@smoench smoench left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it out https://github.com/smoench/deptrac-custom-collector. Works fine so far.

Can you write a documentation chapter in the README.md?

@DanielBadura
Copy link
Contributor Author

Nice! Yeah i will do it the next days :)

@DanielBadura
Copy link
Contributor Author

Readme is updated 👍

README.md Outdated Show resolved Hide resolved
@smoench smoench merged commit f003f81 into qossmic:master Sep 2, 2020
@smoench
Copy link
Contributor

smoench commented Sep 2, 2020

Thank you @DanielBadura !

@smoench smoench mentioned this pull request Sep 2, 2020
@DanielBadura DanielBadura deleted the registry-load-by-fqcn branch July 22, 2022 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load/instantiate collectors by FQCN
2 participants