Skip to content

Expose resolved configuration / Scoper state to patchers #1076

@ragulka

Description

@ragulka

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions