Closed piegus closed 1 year ago
Ah yes, we currently prefix all those things to make sure it doesnt conflict with your vendor dependencies. I am currently not sure how I could solve this issue. Will need to dive into it.
Thanks for reporting!
Having the same issue :( Dies this exist in every version of the phar?
I think it's in issue that has always been there @leonardfischer. It's probably enough to whitelist the options resolver from being prefixed, but sadly haven't found the time to test it out yet.
Or change the return type of ::getConfigurableOptions() to return array instead otionsresolver
That's not how that interface works though ;)
I found a dirty workaround for this problem by dynamically figuring out the prefix and then using eval to define a base class for my custom tasks:
// Get the HumbugBox prefix.
$prefix = null;
foreach (get_declared_classes() as $class) {
if (strpos($class, '\Symfony\Component\\') === false) {
continue;
}
$matches = null;
if (!preg_match('#^(_HumbugBox[a-z0-9]+)#', $class, $matches)) {
continue;
}
$prefix = $matches[1];
break;
}
$class = <<<CLASS
namespace MyPackage\GrumPHP\Task;
use $prefix\Symfony\Component\OptionsResolver\OptionsResolver;
use GrumPHP\Task\TaskInterface;
abstract class TaskBase implements TaskInterface {
public static function getConfigurableOptions(): OptionsResolver
{
\$resolver = new OptionsResolver();
static::configureOptionsResolver(\$resolver);
return \$resolver;
}
abstract protected static function configureOptionsResolver(\$resolver): void;
}
CLASS;
eval($class);
Far from ideal, but it works. But then the next problem popped up, Amp couldn't find my task class (because it's not available in the phar's autoloader). It seems that defining custom tasks is simply impossible when using the shim version.
You can get a custom task working with grumphp-shim by patching the phar file with the task.
It's far from ideal, but works. Here's an example patching script. You need to enable writing to phar files. You can then add it to the composer post install commands to automatically patch the phar.
https://gist.github.com/jackbentley/3da7d39ee842b851b36efcb30cbad027
This will be fixed in grumphp v2. More info, see https://github.com/phpro/grumphp/pull/1090
Feel free to play around with it.
WHen I created custom task and implement TskInterface. I saw that in shim version its chainging names to Humbug. Is tehre a way to create custom tasks and still use grumphp-shim??