nunomaduro/phpinsights

Add support for custom presets

開放

#370 建立於 2020年3月5日

 (3 則留言) (5 個反應) (0 位負責人)PHP (308 個分叉)batch import
enhancementgood first issue

倉庫指標

星標
 (5,092 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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,
     ...

貢獻者指南