Gets a parameter.
public getParameter ( string $name ) : mixed | ||
$name | string | The parameter name |
return | mixed | The parameter value |
$container = new ContainerBuilder(); $container->setParameter('database_host', 'localhost'); $host = $container->getParameter('database_host');
class MyClass { private $logger; private $debug; public function __construct(LoggerInterface $logger, $debug) { $this->logger = $logger; $this->debug = $debug; } public function someMethod() { if ($this->debug) { $this->logger->info('Some method called'); } // ... } }This example shows how the `getParameter` method can be used to inject a parameter into a class constructor. In this example, we have a class called `MyClass` which uses a `LoggerInterface` object and a `$debug` flag in its constructor. We can define the `$debug` flag value using the `setParameter` method and retrieve it in the constructor of `MyClass` using the `getParameter` method. Package/library: Symfony/Component/DependencyInjection.
public getParameter ( string $name ) : mixed | ||
$name | string | The parameter name |
return | mixed | The parameter value |