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

Expose resolved configuration / Scoper state to patchers #1076

Open
ragulka opened this issue Sep 25, 2024 · 0 comments
Open

Expose resolved configuration / Scoper state to patchers #1076

ragulka opened this issue Sep 25, 2024 · 0 comments

Comments

@ragulka
Copy link

ragulka commented Sep 25, 2024

Feature Request

When using custom patchers, there's currently no access to the fully resolved configuration, nor any of the utilities that PHP Scoper uses to determine if a function or class is exposed, internal, etc.

I recently implemented a basic DocblockPatcher (see #462 (comment)), in which I wanted to only prefix class names which are not internal.

Sure, I was able to create my own instance of Reflector, but it would have been nicer if I could just access the EnrichedReflector created by ScoperFactory.

Recently, I also ran into an issue with global function usages (same as #960), when expose-global-functions=false. I wanted to create a patcher that would access the list of functions that PHP Scoper determines should be aliased, and instead of aliasing them, prefix their usages in the patcher.

Unfortunately, it looks like there's no way to access this list, even though PHP Scoper does keep track of it (but only if expose-global-functions=true) inside an instance of SymbolsRegistry.

I'm not sure if PHP Scoper applies patchers after it has scoped all files, or one-by-one, ie scope a file, then patch it, scope another, then patch that - but I'm guessing it's the first?

If so, then perhaps it would be possible to expose some (or all?) of the state to patchers? I think this would make it possible to create more robust patchers with much less effort.

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

No branches or pull requests

1 participant