c33s-toolkit/core-config-bundle
Installation Add the package via Composer:
composer require c33s-toolkit/core-config-bundle
Enable the bundle in config/bundles.php:
return [
// ...
C33S\Toolkit\CoreConfigBundle\C33SToolkitCoreConfigBundle::class => ['all' => true],
];
Basic Configuration
Define your project-wide constants in config/packages/c33s_toolkit_core_config.yaml:
c33s_toolkit_core_config:
app:
name: "MyApp"
version: "1.0.0"
debug: "%kernel.debug%"
features:
experimental_ui: false
First Use Case Access config values in a controller or service:
use C33S\Toolkit\CoreConfigBundle\Config\ConfigManager;
class MyController extends AbstractController
{
public function index(ConfigManager $configManager)
{
$appName = $configManager->get('app.name');
$debugMode = $configManager->get('app.debug');
return $this->render('index.html.twig', [
'app_name' => $appName,
'debug' => $debugMode,
]);
}
}
# config/packages/c33s_toolkit_core_config.yaml
services:
api:
base_url: "https://api.example.com/v1"
timeout: 30
Access via:
$apiUrl = $configManager->get('services.api.base_url');
dev, prod).config/packages/dev/c33s_toolkit_core_config.yaml:
c33s_toolkit_core_config:
app:
debug: true
features:
experimental_ui: true
Use config/packages/prod/c33s_toolkit_core_config.yaml for production overrides.features:
new_dashboard: true
legacy_support: false
Check in middleware or controllers:
if ($configManager->get('features.new_dashboard')) {
// Enable new dashboard logic
}
%parameter% system.c33s_toolkit_core_config:
app:
database: "%env(DATABASE_URL)%"
Access via:
$dbUrl = $configManager->get('app.database');
config/packages/c33s_toolkit_core_config.yaml:
c33s_toolkit_core_config:
app:
name: "DefaultApp" # Fallback if not overridden
timeout: 60 # Default timeout
Caching Issues
php bin/console cache:clear
Namespace Collisions
app.name vs. application.name).project.app.name).Type Safety
$timeout = (int) $configManager->get('app.timeout');
Dependency Injection
ConfigManager is properly autowired in services/controllers.ServiceNotFoundException if the bundle isn’t enabled.dump($configManager->getAll());
php bin/console debug:config c33s_toolkit_core_config
Custom Config Loaders
ConfigManager to load from external sources (e.g., database):
$configManager->extendLoader(function ($key) {
return DB::table('config')->where('key', $key)->value('value');
});
Event Listeners
kernel.request):
// src/EventListener/ConfigListener.php
public function onKernelRequest(GetResponseEvent $event)
{
$configManager->reload();
}
Validation Rules
Validator:
# config/validator/constraints.yaml
C33S\Toolkit\CoreConfigBundle\Validator\Constraints\ValidConfig:
groups: [config_validation]
getAll() results if used frequently.get('key') over getAll() for specific values.How can I help you explore Laravel packages today?