private function PhpDumper::addDefaultParametersMethod

Adds default parameters method.

Return value

string

1 call to PhpDumper::addDefaultParametersMethod()
PhpDumper::dump in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Dumps the service container as a PHP class.

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php, line 735

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

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;
}