Installation
composer require ardent/parameter-bundle
Add the bundle to your config/bundles.php:
Ardent\ParameterBundle\ArdentParameterBundle::class => ['all' => true],
Database Migration
Run the bundle’s migration to create the parameters table:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
(Note: The bundle provides a default migration at vendor/ardent/parameter-bundle/migrations/VersionYYYYMMDDHHMMSS.php.)
First Use Case Define a parameter in a service or controller:
use Ardent\ParameterBundle\Parameter\ParameterManager;
class MyService {
public function __construct(private ParameterManager $parameterManager) {}
public function getSiteName() {
return $this->parameterManager->get('site.name', 'Default Site');
}
}
Access it via the CLI:
php bin/console ardent:parameter:set site.name "My Awesome Site"
Parameter Management
ParameterManager:
$this->parameterManager->set('app.max_retries', 5);
$timeout = $this->parameterManager->get('http.timeout', 30); // Returns 30 if 'http.timeout' DNE
Environment-Specific Parameters
Leverage the environment column (default: prod) to scope parameters:
$this->parameterManager->get('feature.flags.new_ui', false, 'staging');
Validation & Type Safety
Use the ParameterManager::getWithValidation() method:
$this->parameterManager->getWithValidation(
'api.key',
'string',
['min' => 10, 'max' => 255]
);
Caching Layer
Enable Redis/Memcached caching via config/packages/ardent_parameter.yaml:
ardent_parameter:
cache: true
cache_pool: cache.app
config/packages/ardent_parameter.yaml:
ardent_parameter:
default_environment: '%env(APP_ENV)%'
ParameterUpdatedEvent:
// src/EventListener/ParameterUpdateListener.php
public function onParameterUpdated(ParameterUpdatedEvent $event) {
if ($event->getParameterName() === 'cache.ttl') {
$this->cacheManager->clear();
}
}
Register in services.yaml:
services:
App\EventListener\ParameterUpdateListener:
tags:
- { name: 'kernel.event_listener', event: 'ardent.parameter.updated' }
Case Sensitivity
Parameter names are case-sensitive ('API_KEY' ≠ 'api_key'). Use constants or a naming convention (e.g., snake_case).
Default Environment
If default_environment is unset, parameters default to null in the environment column, making them global (applicable to all environments). Explicitly set it:
ardent_parameter:
default_environment: '%env(APP_ENV)%'
Migration Conflicts
If you’ve manually created a parameters table, drop it first before running the bundle’s migration to avoid column conflicts.
Caching Stale Data Clear the cache after bulk updates:
php bin/console cache:clear
Or programmatically:
$this->parameterManager->clearCache();
has() to avoid silent fallbacks:
if ($this->parameterManager->has('critical.config')) {
// Handle existence
}
# config/packages/dev/doctrine.yaml
doctrine:
dbal:
logging: true
profiling: true
Custom Parameter Types
Extend Ardent\ParameterBundle\Entity\Parameter for serialized data (e.g., JSON):
// src/Entity/CustomParameter.php
use Ardent\ParameterBundle\Entity\Parameter;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class CustomParameter extends Parameter {
#[ORM\Column(type: 'json', nullable: true)]
private ?array $data = null;
// Getters/setters...
}
Update the bundle’s ParameterRepository to handle the new type.
Parameter Groups
Add a group column to the parameters table and filter queries:
$this->parameterManager->getAllByGroup('payment');
(Requires custom repository logic.)
Audit Logging Use Doctrine lifecycle callbacks to log changes:
#[ORM\PreUpdate]
public function onPreUpdate() {
$this->setUpdatedAt(new \DateTime());
// Log to a separate table...
}
How can I help you explore Laravel packages today?