Installation
composer require adrenalinkin/config-helper
Add to config/app.php under providers:
Adrenalinkin\ConfigHelper\ConfigHelperServiceProvider::class,
First Use Case
Create a YAML config file at config/packages/your-package/config.yaml:
# config/packages/your-package/config.yaml
app:
name: "Your Package"
version: "1.0.0"
settings:
debug: true
Access it in a service:
use Adrenalinkin\ConfigHelper\ConfigHelper;
class YourService
{
public function __construct(private ConfigHelper $configHelper)
{
}
public function getConfig()
{
return $this->configHelper->get('your-package');
}
}
Where to Look First
Adrenalinkin\ConfigHelper\ConfigHelperServiceProvider (registers the ConfigHelper binding).config/packages/{bundle-name}/config.yaml convention.ConfigHelper class methods (e.g., get(), set(), has()).Bundle-Specific Configs
Use the package to isolate configs per bundle (e.g., auth-package, payment-package):
# config/packages/auth-package/config.yaml
guards:
web: { driver: session, provider: users }
api: { driver: jwt, provider: users }
Dynamic Config Loading Load configs conditionally (e.g., environment-specific):
$config = $this->configHelper->get('your-package', 'config');
if ($config['debug'] && app()->environment('local')) {
// Enable debug features
}
Merging Configs
Override defaults in config/app.php:
'your-package' => [
'settings' => [
'debug' => env('YOUR_PACKAGE_DEBUG', false),
],
],
$this->app->singleton('auth.guards', function ($app) {
return $app->make(ConfigHelper::class)->get('auth-package.guards');
});
Validator:
use Illuminate\Support\Facades\Validator;
$validator = Validator::make(
$this->configHelper->get('your-package'),
['settings.debug' => 'boolean']
);
app()->environment() to switch configs:
# config/packages/your-package/config.yaml
database:
connection: {{ env('DB_CONNECTION') ?: 'mysql' }}
File Naming Conventions
config/packages/{bundle-name}/ prefix causes ConfigHelper to throw ConfigNotFoundException.config-helper middleware.Caching Quirks
php artisan config:clear).config:cache sparingly or implement a ConfigHelper::refresh() method.YAML Parsing Errors
Symfony\Component\Yaml\Yaml::parse().Namespace Collisions
auth.guards in multiple packages).auth-package.guards).\Log::debug('Your Package Config:', $this->configHelper->get('your-package'));
ConfigHelper to log loaded paths:
$configHelper->setLoader(function ($bundle) {
\Log::debug("Loading config for bundle: $bundle");
return file_get_contents("config/packages/$bundle/config.yaml");
});
Custom Loaders
Extend ConfigHelper to support JSON/ENV files:
$configHelper->extendLoader('json', function ($bundle) {
return json_decode(file_get_contents("config/packages/$bundle/config.json"), true);
});
Event Listeners Trigger events on config load/change:
ConfigHelper::loaded(function ($bundle, $config) {
event(new ConfigLoaded($bundle, $config));
});
Testing
Mock ConfigHelper in tests:
$this->app->instance(ConfigHelper::class, new class {
public function get($bundle) { return ['test' => true]; }
});
How can I help you explore Laravel packages today?