Adds default parameters method.
string
private function addDefaultParametersMethod() {
if (!$this->container
->getParameterBag()
->all()) {
return '';
}
$parameters = $this
->exportParameters($this->container
->getParameterBag()
->all());
$code = '';
if ($this->container
->isFrozen()) {
$code .= <<<EOF
/**
* {@inheritdoc}
*/
public function getParameter(\$name)
{
\$name = strtolower(\$name);
if (!array_key_exists(\$name, \$this->parameters)) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', \$name));
}
return \$this->parameters[\$name];
}
/**
* {@inheritdoc}
*/
public function hasParameter(\$name)
{
return array_key_exists(strtolower(\$name), \$this->parameters);
}
/**
* {@inheritdoc}
*/
public function setParameter(\$name, \$value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}
/**
* {@inheritDoc}
*/
public function getParameterBag()
{
if (null === \$this->parameterBag) {
\$this->parameterBag = new FrozenParameterBag(\$this->parameters);
}
return \$this->parameterBag;
}
EOF;
}
$code .= <<<EOF
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return {<span class="php-variable">$parameters</span>};
}
EOF;
return $code;
}