php-scoper
php-scoper copied to clipboard
[Scoper] Pass directly the files to PHP-Scoper instead of finder instances
Feature Request
Right now there's a finders
configuration key that tells how to find the files to be processed and included in the output. The problem is that there's no way to tell PHP Scoper "include these files in the output, but don't process them".
I think this could be implemented with a new output_finders
key. It would work as follows:
- Anything that is matched by either
output_finders
orfinders
is included in the output. -
But, only what is matched by
finders
is processed.
Or put another way:
- Anything that is matched by
output_finders
but not byfinders
is copied verbatim to the output. - Anything that is matched by
finders
is processed and then generated in the output (as it happens now).
That sounds complicated but it makes sense if we look at a simple example:
'output_finders' => [ Finder::create()->files()->in('src') ],
'finders' => [ Finder::create()->files()->in('src')->name('*.php') ]
So this means "I want everything from src
in the output, but only PHP files should be processed".
This is something I actually need for my job so I can implement it and submit a pull request. In fact I've already been experimenting with the code and seems definitely doable.
Wouldn't https://github.com/humbug/php-scoper#whitelisted-files fit the bill?
If I understood correctly that setting allows whitelisting a concrete set of files only. A mechanism based in finders would be much more flexible and powerful.
I'm wondering if it's worth it though. I realised quite late, but in the scoper file you already have access to the scoped Finder hence you can use it there right away and pass the result to the config which doesn't increase things in complexity for the user and simplifies things on PHP-Scoper side
How would that work? Could you please provide an example for the use case I present in the issue description? (output all the files in a given directory but prefix only *.php
)
Sure, here's one (although not using the Finder but you could totally do): https://github.com/humbug/php-scoper/blob/master/scoper.inc.php#L17
Ok, got it. The following works and is equivalent to my example:
$files_to_output_untouched = (static function (): array {
$finder = Finder::create()->files()->in('src')->notName('*.php');
$files = [];
foreach ($finder as $file) {
$files[] = $file->getPathName();
}
return $files;
})();
return [
'files-whitelist' => $files_to_output_untouched,
'finders' => [ Finder::create()->files()->in('src') ],
...
Maybe something like this could be added to the documentation, but that's a different story 🙂
I think it would be clearer if the same would be done for 'finders'
in which case it could be added to the config template and would be clearer for everyone