Closed afilina closed 5 years ago
Thank you for the great PR. Whitelist can be useful.
I tried to test __DIR__
and __FILE__
(see https://github.com/dg/bypass-finals/commit/06d98c87299ce5fa6b0fc709cabdfa7ca2d04576) and it seems that these constants works as expected. Could you describe when they did not work?
@dg That's only a guess. It was deep within Laravel's call stack. Perhaps the added layer of Docker caused the problem. We stopped digging at some point and just created the exclusion. In any case, even if the bug was somewhere else, this still covers a number of legitimate scenarios.
I am thinking about method name… It is not entirely clear that this is about paths, ie allowed paths. What about setAllowedPaths()
? Or simply setPaths()
? setDirectories()
?
Sure, whichever you prefer.
Actually phpspec stops generating PHP classes based on specs:
warning: file_get_contents(/usr/local/var/www/myproject/src/Repository/UserOrderRepository.php): failed to open stream: No such file or directory in /usr/local/var/www/newonline/vendor/dg/bypass-finals/src/
BypassFinals.php line 211
Was able to get it working with @afilina fork and custom phpspec bootstrap:
<?php
require __DIR__.'/../vendor/autoload.php';
DG\BypassFinals::setWhitelist(findFinalClassesToBypass());
DG\BypassFinals::enable();
function findFinalClassesToBypass(): array
{
$finalClasses = (new Symfony\Component\Finder\Finder())
->in([__DIR__.'/../vendor/symfony/security-core'])
->name('*.php')
->contains('final class');
return array_values(array_map(
function (SplFileInfo $fileInfo) {
return $fileInfo->getRealPath();
},
iterator_to_array($finalClasses)
));
}
@afilina Thanks! 👍
@dg PR will be merged & released? This feature is very important for me too
Fork with this feature: https://github.com/avto-dev/bypass-finals
@afilina - great thx! :+1:
Isn't the name kinda misleading since you cannot just set a path, but need to set every filepath individually? Also it doesn't take into consideration the difference between operating systems (\ vs /).
Reason behind this feature: Some frameworks stop working because of DIR and such, since the files are now served from tmp. This prompted me to add a more fine-grained control.
I added a test and documentation. The old behavior remains unaffected.