Parameters
Parameters are the container's storage for configuration values. Think of them as the scalar knobs of your application — hostnames, secrets, timeouts, feature flags. There is no technical limitation on what a parameter may hold (you can store an object), but conceptually you should keep them to values, not services.
TIP
This page covers the runtime PHP API. If you are looking for how to declare parameters inside a .ctn container file, read Container Files › Parameters.
Initial parameters
The container constructor accepts an array of initial parameters:
use ClanCats\Container\Container;
$container = new Container(['env' => 'production']);These initial values are merged with any parameters already defined (for example the ones baked into a compiled container). This makes the constructor a convenient place to inject environment specific overrides — see Basic Container usage for the equivalent factory call.
The same array can be handed to the factory when you build a container:
$factory = new \ClanCats\Container\ContainerFactory(__DIR__ . '/cache');
$container = $factory->create('AppContainer', function($builder) {}, ['env' => 'production']);Reading a parameter
$container->getParameter('env');You may supply a fallback that is returned when the parameter has not been defined. Note that a parameter explicitly set to null still counts as defined, so the fallback will not kick in for it.
$container->getParameter('cron.idle.timeout', 3600);Get the parameter with the the given name, or return the default value if the parameter is not set.
Method definition:
public function getParameter(string $name, $default = null)Arguments
| Data type | Variable name | Comment |
|---|---|---|
| string | $name | The parameter name. |
| mixed | $default | The returned default value if the parameter is not set. |
Returns
mixed
Setting a parameter
Parameters can be written at any point during runtime.
$container->setParameter('session.cookie.name', 'mysessiontoken');The value is not limited to strings — arrays and other structures are fine too.
$container->setParameter('available.languages', ['de', 'en', 'it', 'fr']);Set the given parameter with value
Method definition:
public function setParameter(string $name, $value)Arguments
| Data type | Variable name | Comment |
|---|---|---|
| string | $name | The parameter name. |
| mixed | $value | The parameter value. |
Returns
void
Checking if a parameter exists
Sometimes you just need to know whether a parameter is present. Remember: a parameter whose value is null still exists.
if ($container->hasParameter('smtp.host')) {
// ...
}Does the container contain the parameter with the given name?
Method definition:
public function hasParameter(string $name) : boolArguments
| Data type | Variable name | Comment |
|---|---|---|
| string | $name | The parameter name. |
Returns
bool
Reading all parameters
For debugging and introspection you can dump the full parameter map.
foreach ($container->allParameters() as $name => $value) {
// ...
}Returns all container parameters
Method definition:
public function allParameters() : arrayArguments
This method takes no arguments.
Returns
array<string, mixed>
