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

Config options resolver #1090

Merged
merged 1 commit into from
May 22, 2023
Merged

Config options resolver #1090

merged 1 commit into from
May 22, 2023

Conversation

veewee
Copy link
Contributor

@veewee veewee commented May 20, 2023

Q A
Branch v2
Bug fix? yes
New feature? yes
BC breaks? yes
Deprecations? no
Documented? no
Fixed tickets

Fixes phpro/grumphp-shim#10

This PR makes sure that the GrumPHP TaskInterface only has a dependency to the GrumPHP\\ namespace.
Symfony OptionsResolver will not be a part of the task interface anymore.

New task interface:

namespace GrumPHP\Task;

use GrumPHP\Runner\TaskResultInterface;
use GrumPHP\Task\Config\ConfigOptionsResolver;
use GrumPHP\Task\Config\TaskConfigInterface;
use GrumPHP\Task\Context\ContextInterface;

interface TaskInterface
{
    public static function getConfigurableOptions(): ConfigOptionsResolver;

    public function canRunInContext(ContextInterface $context): bool;

    public function run(ContextInterface $context): TaskResultInterface;

    public function getConfig(): TaskConfigInterface;

    public function withConfig(TaskConfigInterface $config): TaskInterface;
}

This makes it possible for extensions to provide tasks that are compatible with the grumphp-shim release.
In order to make the task compatible, you'll need to wrap the symfony options-resolver with GrumPHP's own options-resolver:

    public static function getConfigurableOptions(): ConfigOptionsResolver
    {
        $resolver = new OptionsResolver();

        // ..... your config

        return ConfigOptionsResolver::fromClosure(
            static fn (array $options): array => $resolver->resolve($options)
        );
    }

❗ In extensions, you do not want to use \GrumPHP\Task\Config\ConfigOptionsResolver::fromOptionsResolver() - since Symfony's options resolver will be scoped (prefixed) in grumphp-shim's phar distrubition.

@veewee veewee added this to the 2.0.0 milestone May 20, 2023
@veewee veewee changed the base branch from master to v2.x May 20, 2023 09:03
@veewee veewee force-pushed the config-options-resolver branch 3 times, most recently from 3128fda to 1b4a44b Compare May 20, 2023 09:51
@veewee veewee force-pushed the config-options-resolver branch from 1b4a44b to b79dc6a Compare May 20, 2023 09:54
@veewee veewee merged commit 4a1235d into phpro:v2.x May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Task implementing AbstractExternalTask is not working
1 participant