Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Config Laravel Package

illuminate/config

Illuminate Config is Laravel’s configuration repository. It loads and merges config files, lets you read and set values at runtime, supports environment-based defaults, and provides a consistent API for accessing app settings across services and packages.

View on GitHub
Deep Wiki
Context7

Getting Started

  • This package is a standalone subtree split of Laravel’s Config component—used internally by Laravel but usable in non-Laravel PHP apps.
  • First stop: Read the Laravel config documentation as the API remains identical; this package is that logic extracted.
  • Basic usage: Instantiate Illuminate\Config\Repository with an array of config values and optionally a loader (e.g., FileLoader for .php files), then retrieve values via get('key').
  • Example minimal setup:
    use Illuminate\Config\Repository;
    use Illuminate\Filesystem\Filesystem;
    
    $files = new Filesystem();
    $loader = new Illuminate\Config\FileLoader($files, base_path('config'));
    $config = new Repository($loader, ['app' => ['name' => 'MyApp']]);
    $name = $config->get('app.name');
    

Implementation Patterns

  • Hybrid static-like access: While not static by default, many projects wrap Repository in a static facade or singleton for convenience (similar to Laravel’s Config facade).
  • Environment-specific overrides: Use env() calls inside config files to support .env values (requires manually calling $_SERVER/$_ENV—this package does not auto-load .env; that’s handled in Laravel’s bootstrap).
  • Lazy loading via FileLoader: Ideal for apps that want config cached or hot-reloaded during development; config files are resolved only when accessed.
  • Fallback and merge support: Use Repository::offsetGet() or get() with dot notation ('database.connections.mysql.host') to traverse nested arrays; supports fallback defaults via get('key', 'default_value').
  • Testing patterns: Inject Repository (or interface Illuminate\Contracts\Config\Repository) and mock get() calls with withConsecutive() to assert expected config paths.

Gotchas and Tips

  • No .env parsing: This package does not interpret env('KEY') calls in config files. To use env values, you must wrap calls like $_ENV['KEY'] ?? 'default' manually in your config files. Laravel does this via its DetectEnvironment bootstrapper.
  • No caching by default: Unlike Laravel’s Config::set() with config:cache, this component has no built-in cache layer—implement caching via a custom CachedLoader or wrap Repository with your own caching middleware.
  • Dependency chain matters: Requires illuminate/collections and contracts. Ensure compatible versions (e.g., v13.x requires PHP 8.3+ per composer.json).
  • No auto-discovery: Unlike full Laravel, this component doesn’t scan config/ automatically—must explicitly configure FileLoader with the correct path(s).
  • Extension point: Implement LoaderInterface (e.g., ArrayLoader, JsonLoader) to load configs from JSON, databases, or YAML (with extra packages).
  • Debugging tip: Use Repository::inspect('some.key') to see how a value is resolved (though this is an internal method—use with caution across versions).
  • Testing configs: For unit tests, prefer ArrayLoader over FileLoader to avoid filesystem side effects:
    $loader = new ArrayLoader(['app.timezone' => 'UTC']);
    $config = new Repository($loader);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport