cweagans/composer-configurable-plugin
Composer plugin that makes package configuration flexible by reading and merging settings from composer.json (extra) and other sources. Useful for teams needing configurable behavior across environments without hardcoding values in the plugin itself.
Start by installing the package via Composer: composer require cweagans/composer-configurable-plugin. Once installed, register the plugin in your composer.json by adding it to the extra.plugins section under the type key composer-configurable-plugin. The plugin looks for configuration in a composer.configurable.php file at the project root (or defined via the configurable-config extra key). Your first use case will likely involve defining a configuration schema that other Composer plugins or custom scripts can consume—e.g., enabling plugin-specific settings like cache paths, API endpoints, or feature flags without hard-coding them.
Use composer.configurable.php to define a configuration schema as an associative array with keys for required, optional, and defaults. Return this schema from the file, and it will be merged with environment variables, config overrides (config section in composer.json), and runtime arguments. Plugins or scripts can then read the resolved configuration via Composer\Config::getConfigSource()->getAllConfig() (look for the extra.configurable namespace). Common patterns include defining environment-specific settings (e.g., LOCAL_CACHE_DIR → config.local.php) or exposing plugin behavior toggles (e.g., enable_cdn, strict_validation) without modifying source code. Leverage the Composer\EventDispatcher\Event objects to inject configuration values into custom script logic.
Configuration values are not auto-cast—ensure explicit validation and type coercion in your consumer code (e.g., cast true/false strings to booleans using filter_var($value, FILTER_VALIDATE_BOOLEAN)). The package doesn’t validate schema at install time—misconfigured values may only surface as runtime errors. If your plugin depends on this config system, document the expected keys and types clearly. Use the configurable-config extra key to override the default config file path for monorepos. Debug config resolution by running composer show -p and inspecting the extra section, or add a pre-update script to var_dump(Composer\Factory::getComposer()->getConfig()->getAllConfig()) to trace effective values. Note: This package itself doesn’t provide any CLI; it’s purely a configuration infrastructure layer—consumers must implement the actual plugin behavior.
How can I help you explore Laravel packages today?