The Wayback Machine - https://web.archive.org/web/20201007232342/https://github.com/nunomaduro/phpinsights/issues/370
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

Add support for custom presets #370

Open
olivernybroe opened this issue Mar 5, 2020 · 1 comment
Open

Add support for custom presets #370

olivernybroe opened this issue Mar 5, 2020 · 1 comment

Comments

@olivernybroe
Copy link
Collaborator

@olivernybroe olivernybroe commented Mar 5, 2020

Q A
Bug report? no
Feature request? yes

Right now we can create custom configuration based on presets, however I think it would be worth allowing custom presets also.
This would mean opening up the Preset interface so for example a framework could maintain their own Preset file and users can then use the preset, just by pointing their preset configuration to the class.

Implementation

  • In Configuration::resolveConfig, the OptionsResolver now has to allow preset to also be a valid class.
  • In ConfigResolver::resolve, add a new private method resolvePreset, which has the current logic for resolving a preset, but also adds support for the preset variable could be a class fqn.
  • Add docs
  • Add a test in ConfigResolverTest for setting preset from a class
  • Remove internal from phpdoc in Preset interface
  • Consider if we should also remove internal from Composer class
  • Remove shouldBeApplied and getName from Preset interface and add it to a new internal interface, which our presets implements. (this method is used for guessing the preset from composer, but does not make sense with custom preset as their are not registered in our application.)

Usage

Using this should be rather straight forward, creating a custom Preset should be like this

class LaravelLumenPreset implements Preset
{
    public static function get(Composer $composer): array
    {
        $config = [
            // My custom configs
        ];

        return ConfigResolver::mergeConfig(LaravelPreset::get($composer), $config);
    }
}

And our config file would then look like

return [
    'preset' => FQN\LaravelLumenPreset::class,
     ...
@Jibbarth
Copy link
Collaborator

@Jibbarth Jibbarth commented Mar 7, 2020

👍 I'm totally okay with this feature request !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.